1c87c5fbaSopenharmony_ciFor Windows builds - see the Windows Section
2c87c5fbaSopenharmony_ci
3c87c5fbaSopenharmony_ciObtaining the Libcoap Source
4c87c5fbaSopenharmony_ci============================
5c87c5fbaSopenharmony_ci
6c87c5fbaSopenharmony_ciTo get the libcoap library source, you need to do either the following
7c87c5fbaSopenharmony_ci
8c87c5fbaSopenharmony_ci* Obtain the latest distribution package file from
9c87c5fbaSopenharmony_ci  https://github.com/obgm/libcoap/archive/develop.zip
10c87c5fbaSopenharmony_ci  [There is a stable version at
11c87c5fbaSopenharmony_ci   https://github.com/obgm/libcoap/archive/main.zip]
12c87c5fbaSopenharmony_ci* Change to the directory that you want to install the libcoap sub-directory
13c87c5fbaSopenharmony_ci  into
14c87c5fbaSopenharmony_ci* Unpack the distribution package file
15c87c5fbaSopenharmony_ci* Change into the top level directory of the unpackaged files
16c87c5fbaSopenharmony_ci
17c87c5fbaSopenharmony_cior alternatively, clone the libcoap git repository from github
18c87c5fbaSopenharmony_ci
19c87c5fbaSopenharmony_ci* Change to the directory that you want to install the libcoap sub-directory
20c87c5fbaSopenharmony_ci  into.
21c87c5fbaSopenharmony_ci* Then clone the latest (develop) version of the code:-
22c87c5fbaSopenharmony_ci   git clone https://github.com/obgm/libcoap.git
23c87c5fbaSopenharmony_ci* Change into the top level directory of the cloned files
24c87c5fbaSopenharmony_ci* Optionally, change the branch from develop to the stable main branch:-
25c87c5fbaSopenharmony_ci   git checkout main
26c87c5fbaSopenharmony_ci
27c87c5fbaSopenharmony_ciBuilding Libcoap Libraries and Examples
28c87c5fbaSopenharmony_ci=======================================
29c87c5fbaSopenharmony_ci
30c87c5fbaSopenharmony_ciFollow the appropriate sections below
31c87c5fbaSopenharmony_ci
32c87c5fbaSopenharmony_ci
33c87c5fbaSopenharmony_ciTinyDTLS Only
34c87c5fbaSopenharmony_ci=============
35c87c5fbaSopenharmony_ci
36c87c5fbaSopenharmony_ciIt is possible that you may need to execute the following two commands once to
37c87c5fbaSopenharmony_ciget the TinyDTLS code into your project, so the TinyDTLS library can be used.
38c87c5fbaSopenharmony_ci
39c87c5fbaSopenharmony_ci git submodule init
40c87c5fbaSopenharmony_ci git submodule update
41c87c5fbaSopenharmony_ci
42c87c5fbaSopenharmony_ciGeneral Building with cmake for linux/windows/macos/android (not for RIOT, LwIP or Contiki-NG - see below)
43c87c5fbaSopenharmony_ci================
44c87c5fbaSopenharmony_ci
45c87c5fbaSopenharmony_ci cmake -E remove_directory build
46c87c5fbaSopenharmony_ci cmake -E make_directory build
47c87c5fbaSopenharmony_ci cd build
48c87c5fbaSopenharmony_ci cmake .. -DENABLE_TESTS=ON
49c87c5fbaSopenharmony_ci cmake --build .
50c87c5fbaSopenharmony_ci [sudo] cmake --build . -- install
51c87c5fbaSopenharmony_ci cd ..
52c87c5fbaSopenharmony_ci
53c87c5fbaSopenharmony_ci Note: to see possible options (TLS lib, doc, tests, examples etc.):
54c87c5fbaSopenharmony_ci cmake -LH build
55c87c5fbaSopenharmony_ci
56c87c5fbaSopenharmony_ci Note: For Windows, this is supported by Visual Studio Code with CMake extension
57c87c5fbaSopenharmony_ci Note: You must use cmake version >=3.10.
58c87c5fbaSopenharmony_ci
59c87c5fbaSopenharmony_ci Note: you can use cmake's find package after installation: find_package(libcoap-3 REQUIRED),
60c87c5fbaSopenharmony_ci and target_link_libraries(myTarget PRIVATE libcoap::coap-2)
61c87c5fbaSopenharmony_ci
62c87c5fbaSopenharmony_ci Note: Shared Library support is not currently available for Windows.
63c87c5fbaSopenharmony_ci
64c87c5fbaSopenharmony_ciGeneral Building with autoconf (not for RIOT, LwIP or Contiki-NG - see below)
65c87c5fbaSopenharmony_ci================
66c87c5fbaSopenharmony_ci
67c87c5fbaSopenharmony_ci ./autogen.sh
68c87c5fbaSopenharmony_ci ./configure
69c87c5fbaSopenharmony_ci make
70c87c5fbaSopenharmony_ci sudo make install
71c87c5fbaSopenharmony_ci
72c87c5fbaSopenharmony_ci./autogen.sh will fail if there is a required package for buildling libcoap
73c87c5fbaSopenharmony_cithat is missing. Install the missing package and try ./autogen.sh again.
74c87c5fbaSopenharmony_ci
75c87c5fbaSopenharmony_ciIt is possible that you may need to provide some options to ./configure
76c87c5fbaSopenharmony_cito customize your installation.
77c87c5fbaSopenharmony_ci
78c87c5fbaSopenharmony_ciIn particular you may need to define which (D)TLS library to use as well as
79c87c5fbaSopenharmony_cidisable some building of documentation.
80c87c5fbaSopenharmony_ci
81c87c5fbaSopenharmony_ciGeneral configure instructions can be found in INSTALL, which is built
82c87c5fbaSopenharmony_ciby ./autogen.sh
83c87c5fbaSopenharmony_ci
84c87c5fbaSopenharmony_ci ./configure --help
85c87c5fbaSopenharmony_cigives the specific options available to libcoap.
86c87c5fbaSopenharmony_ci
87c87c5fbaSopenharmony_ciSome examples are:-
88c87c5fbaSopenharmony_ci
89c87c5fbaSopenharmony_ci# No DTLS
90c87c5fbaSopenharmony_ci ./configure --enable-tests --disable-documentation --enable-examples --disable-dtls --enable-shared
91c87c5fbaSopenharmony_ci
92c87c5fbaSopenharmony_ci# With TinyDTLS
93c87c5fbaSopenharmony_ci ./configure --enable-tests --disable-documentation --enable-examples --with-tinydtls --enable-shared
94c87c5fbaSopenharmony_ci
95c87c5fbaSopenharmony_ciNote: FreeBSD requires gmake instead of make when building TinyDTLS - i.e.
96c87c5fbaSopenharmony_ci gmake
97c87c5fbaSopenharmony_ci sudo gmake install
98c87c5fbaSopenharmony_ci
99c87c5fbaSopenharmony_ci# With OpenSSL
100c87c5fbaSopenharmony_ci ./configure --with-openssl --enable-tests --enable-shared
101c87c5fbaSopenharmony_ci
102c87c5fbaSopenharmony_ci# With GnuTLS
103c87c5fbaSopenharmony_ci ./configure --with-gnutls --enable-tests --enable-shared
104c87c5fbaSopenharmony_ci
105c87c5fbaSopenharmony_ciNote: --disable-documentation disables the building of doxygen and man page
106c87c5fbaSopenharmony_cifiles.  If you want to only disable one of them, use --disable-doxygen or
107c87c5fbaSopenharmony_ci--disable-manpages.  Doxygen requires the program doxygen and man pages require
108c87c5fbaSopenharmony_cithe program a2x to build the appropriate files.
109c87c5fbaSopenharmony_ci
110c87c5fbaSopenharmony_ciIf you need to rebuild the libcoap-*.{map,sym} files to update any exposed
111c87c5fbaSopenharmony_cifunction changes, run
112c87c5fbaSopenharmony_ci
113c87c5fbaSopenharmony_ci make update-map-file
114c87c5fbaSopenharmony_ci
115c87c5fbaSopenharmony_ciprior to running 'make'.
116c87c5fbaSopenharmony_ci
117c87c5fbaSopenharmony_ciRIOT
118c87c5fbaSopenharmony_ci====
119c87c5fbaSopenharmony_ci
120c87c5fbaSopenharmony_ci ./autogen.sh
121c87c5fbaSopenharmony_ci ./configure --disable-tests --disable-documentation --disable-examples --disable-dtls
122c87c5fbaSopenharmony_ci cd examples/riot
123c87c5fbaSopenharmony_ci make
124c87c5fbaSopenharmony_ci
125c87c5fbaSopenharmony_ciSee examples/riot/README for further information.
126c87c5fbaSopenharmony_ci
127c87c5fbaSopenharmony_ciLwIP
128c87c5fbaSopenharmony_ci====
129c87c5fbaSopenharmony_ci
130c87c5fbaSopenharmony_ci ./autogen.sh
131c87c5fbaSopenharmony_ci ./configure --disable-tests --disable-documentation --disable-examples --disable-dtls
132c87c5fbaSopenharmony_ci cd examples/lwip
133c87c5fbaSopenharmony_ci make
134c87c5fbaSopenharmony_ci
135c87c5fbaSopenharmony_ciExecutable is ./server. See examples/lwip/README for further information.
136c87c5fbaSopenharmony_ci
137c87c5fbaSopenharmony_ciContiki-NG
138c87c5fbaSopenharmony_ci==========
139c87c5fbaSopenharmony_ci
140c87c5fbaSopenharmony_ci ./autogen.sh
141c87c5fbaSopenharmony_ci ./configure --disable-tests --disable-documentation --disable-examples --disable-dtls
142c87c5fbaSopenharmony_ci cd examples/contiki
143c87c5fbaSopenharmony_ci make
144c87c5fbaSopenharmony_ci
145c87c5fbaSopenharmony_ciExecutable is ./server.native. See examples/contiki/README for further
146c87c5fbaSopenharmony_ciinformation.
147c87c5fbaSopenharmony_ci
148c87c5fbaSopenharmony_ciWindows
149c87c5fbaSopenharmony_ci=======
150c87c5fbaSopenharmony_ci
151c87c5fbaSopenharmony_ciInstall OpenSSL (minimum version 1.1.0) including the development libraries if
152c87c5fbaSopenharmony_cinot already installed.
153c87c5fbaSopenharmony_ci
154c87c5fbaSopenharmony_ciWithin Visual Studio, "Clone or check out code" using the repository
155c87c5fbaSopenharmony_cihttps://github.com/obgm/libcoap.git
156c87c5fbaSopenharmony_ci
157c87c5fbaSopenharmony_ciYou may need to update the SDK version of the libcoap Windows Project files to
158c87c5fbaSopenharmony_cimatch that of the SDK version of the Visual Studio you are using.  In Solution
159c87c5fbaSopenharmony_ciExplorer with the view set to libcoap.sln, right click "Solution 'libcoap'"
160c87c5fbaSopenharmony_ciand then "Retarget solution".
161c87c5fbaSopenharmony_ci
162c87c5fbaSopenharmony_ciYou may need to edit win32\libcoap.props to update the OpenSSLRootDir and
163c87c5fbaSopenharmony_ciOpenSSLRootDirDbg variables to point to the top level directory where OpenSSL
164c87c5fbaSopenharmony_ciis installed so that the include, lib etc. directories are correctly set up.
165c87c5fbaSopenharmony_ciNote: Make sure that you include a trailing \ in the variable definitions.
166c87c5fbaSopenharmony_ci
167c87c5fbaSopenharmony_ciAlternatively you can build everything in Visual Studio with CMake.
168c87c5fbaSopenharmony_ci
169c87c5fbaSopenharmony_ciMinGW
170c87c5fbaSopenharmony_ci=====
171c87c5fbaSopenharmony_ci
172c87c5fbaSopenharmony_ciAs there are many ways to install MinGW, depending on the different
173c87c5fbaSopenharmony_ciinstalled packages, random failures can occur (usually because of conflicts
174c87c5fbaSopenharmony_ciwith cygwin based packages).  Below is a way known to work with libcoap
175c87c5fbaSopenharmony_cion a Windows host.
176c87c5fbaSopenharmony_ci
177c87c5fbaSopenharmony_ciRemove any old copy of MSYS2 using Windows program remove.
178c87c5fbaSopenharmony_ci
179c87c5fbaSopenharmony_ciDownload https://repo.msys2.org/distrib/x86_64/msys2-x86_64-20230318.exe and
180c87c5fbaSopenharmony_cirun the executable, accepting the defaults.
181c87c5fbaSopenharmony_ci
182c87c5fbaSopenharmony_ciIn a UCRT64 window, add in the following packages
183c87c5fbaSopenharmony_ci
184c87c5fbaSopenharmony_ci pacman -S git
185c87c5fbaSopenharmony_ci pacman -S vim
186c87c5fbaSopenharmony_ci pacman -S mingw-w64-ucrt-x86_64-cmake
187c87c5fbaSopenharmony_ci pacman -S mingw-w64-ucrt-x86_64-gcc
188c87c5fbaSopenharmony_ci pacman -S mingw-w64-ucrt-x86_64-openssl
189c87c5fbaSopenharmony_ci
190c87c5fbaSopenharmony_ciAlternatively, in a MINGW64 window, add in the following packages
191c87c5fbaSopenharmony_ci
192c87c5fbaSopenharmony_ci pacman -S git
193c87c5fbaSopenharmony_ci pacman -S vim
194c87c5fbaSopenharmony_ci pacman -S mingw-w64-x86_64-cmake
195c87c5fbaSopenharmony_ci pacman -S mingw-w64-x86_64-gcc
196c87c5fbaSopenharmony_ci pacman -S mingw-w64-x86_64-openssl
197c87c5fbaSopenharmony_ci
198c87c5fbaSopenharmony_ciThen clone a copy of the github libcoap repository in a UCRT64 or MINGW64 window
199c87c5fbaSopenharmony_ci
200c87c5fbaSopenharmony_ci git clone https://github.com/obgm/libcoap.git
201c87c5fbaSopenharmony_ci cd libcoap
202c87c5fbaSopenharmony_ci
203c87c5fbaSopenharmony_ciThen build the libcoap library and example executables (which will be in the
204c87c5fbaSopenharmony_cibuild directory)
205c87c5fbaSopenharmony_ci
206c87c5fbaSopenharmony_ci cmake -E remove_directory build
207c87c5fbaSopenharmony_ci cmake -E make_directory build
208c87c5fbaSopenharmony_ci cd build
209c87c5fbaSopenharmony_ci cmake .. -DENABLE_DOCS=OFF -DDTLS_BACKEND=openssl
210c87c5fbaSopenharmony_ci cmake --build .
211