1 \hypertarget{md_README.build_cm}{}\section{Introduction to C\+Make}\label{md_README.build_cm}
2 C\+Make is a multi-\/platform build tool that can generate build files for many different target platforms. See more info at \href{http://www.cmake.org}{\tt http\+://www.\+cmake.\+org}
4 C\+Make also allows/recommends you to do \char`\"{}out of source\char`\"{}-\/builds, that is, the build files are separated from your sources, so there is no need to create elaborate clean scripts to get a clean source tree, instead you simply remove your build directory.
6 Libwebsockets has been tested to build successfully on the following platforms with S\+SL support (both Open\+S\+S\+L/wolf\+S\+SL)\+:
10 \item Windows (Visual Studio)
11 \item Windows (Min\+GW)
12 \item Linux (x86 and A\+RM)
15 \end{DoxyItemize}\hypertarget{md_README.build_build1}{}\section{Building the library and test apps}\label{md_README.build_build1}
16 The project settings used by C\+Make to generate the platform specific build files is called \href{CMakeLists.txt}{\tt C\+Make\+Lists.\+txt}. C\+Make then uses one of its \char`\"{}\+Generators\char`\"{} to output a Visual Studio project or Make file for instance. To see a list of the available generators for your platform, simply run the \char`\"{}cmake\char`\"{} command.
18 Note that by default Open\+S\+SL will be linked, if you don\textquotesingle{}t want S\+SL support see below on how to toggle compile options.\hypertarget{md_README.build_bu}{}\section{Building on Unix\+:}\label{md_README.build_bu}
21 \item Install C\+Make 2.\+8 or greater\+: \href{http://cmake.org/cmake/resources/software.html}{\tt http\+://cmake.\+org/cmake/resources/software.\+html} (Most Unix distributions comes with a packaged version also)
22 \item Install Open\+S\+SL.
23 \item Generate the build files (default is Make files)\+:
31 \item Finally you can build using the generated Makefile\+:
33 1 $ make && sudo make install
35 {\bfseries N\+O\+TE}\+: The {\ttfamily build/}{\ttfamily directory can have any name and be located anywhere on your filesystem, and that the argument}..` given to cmake is simply the source directory of {\bfseries libwebsockets} containing the \href{CMakeLists.txt}{\tt C\+Make\+Lists.\+txt} project file. All examples in this file assumes you use \char`\"{}..\char`\"{}
38 {\bfseries N\+O\+T\+E2}\+: A common option you may want to give is to set the install path, same as --prefix= with autotools. It defaults to /usr/local. You can do this by, eg
40 1 $ cmake -DCMAKE\_INSTALL\_PREFIX:PATH=/usr .
44 {\bfseries N\+O\+T\+E3}\+: On machines that want libraries in lib64, you can also add the following to the cmake line
50 {\bfseries N\+O\+T\+E4}\+: If you are building against a non-\/distro Open\+S\+SL (eg, in order to get access to A\+L\+PN support only in newer Open\+S\+SL versions) the nice way to express that in one cmake command is eg,
52 1 $ cmake .. -DOPENSSL\_ROOT\_DIR=/usr/local/ssl \(\backslash\)
53 2 -DCMAKE\_INCLUDE\_DIRECTORIES\_PROJECT\_BEFORE=/usr/local/ssl \(\backslash\)
54 3 -DLWS\_WITH\_HTTP2=1
58 When you run the test apps using non-\/distro S\+SL, you have to force them to use your libs, not the distro ones
60 1 $ LD\_LIBRARY\_PATH=/usr/local/ssl/lib libwebsockets-test-server --ssl
64 To get it to build on latest openssl (2016-\/04-\/10) it needed this approach
66 1 cmake .. -DLWS\_WITH\_HTTP2=1 -DLWS\_OPENSSL\_INCLUDE\_DIRS=/usr/local/include/openssl
67 -DLWS\_OPENSSL\_LIBRARIES="/usr/local/lib64/libssl.so;/usr/local/lib64/libcrypto.so"
71 {\bfseries N\+O\+T\+E5}\+: To build with debug info and \+\_\+\+D\+E\+B\+UG for lower priority debug messages compiled in, use
73 1 $ cmake .. -DCMAKE\_BUILD\_TYPE=DEBUG
75 \hypertarget{md_README.build_cmq}{}\section{Quirk of cmake}\label{md_README.build_cmq}
76 When changing cmake options, for some reason the only way to get it to see the changes sometimes is delete the contents of your build directory and do the cmake from scratch.\hypertarget{md_README.build_cmw}{}\section{Building on Windows (\+Visual Studio)}\label{md_README.build_cmw}
79 \item Install C\+Make 2.\+6 or greater\+: \href{http://cmake.org/cmake/resources/software.html}{\tt http\+://cmake.\+org/cmake/resources/software.\+html}
80 \item Install Open\+S\+SL binaries. \href{http://www.openssl.org/related/binaries.html}{\tt http\+://www.\+openssl.\+org/related/binaries.\+html}
82 ({\bfseries N\+O\+TE}\+: Preferably in the default location to make it easier for C\+Make to find them)
84 {\bfseries N\+O\+T\+E2}\+: Be sure that O\+P\+E\+N\+S\+S\+L\+\_\+\+C\+O\+NF environment variable is defined and points at $<$\+Open\+S\+S\+L install=\char`\"{}\char`\"{} location$>$=\char`\"{}\char`\"{}$>$.cfg
85 \item Generate the Visual studio project by opening the Visual Studio cmd prompt\+:
93 4 cmake -G "Visual Studio 10" ..
97 ({\bfseries N\+O\+TE}\+: There is also a cmake-\/gui available on Windows if you prefer that)
99 {\bfseries N\+O\+T\+E2}\+: See this link to find out the version number corresponding to your Visual Studio edition\+: \href{http://superuser.com/a/194065}{\tt http\+://superuser.\+com/a/194065}
102 \begin{DoxyEnumerate}
103 \item Now you should have a generated Visual Studio Solution in your {\ttfamily $<$path to src$>$/build} directory, which can be used to build.
104 \item Some additional deps may be needed
110 \item If you\textquotesingle{}re using libuv, you must make sure to compile libuv with the same multithread-\/dll / Mtd attributes as libwebsockets itself
111 \end{DoxyEnumerate}\hypertarget{md_README.build_cmwmgw}{}\section{Building on Windows (\+Min\+G\+W)}\label{md_README.build_cmwmgw}
113 \begin{DoxyEnumerate}
114 \item Install Min\+GW\+: \href{http://sourceforge.net/projects/mingw/files}{\tt http\+://sourceforge.\+net/projects/mingw/files}
116 ({\bfseries N\+O\+TE}\+: Preferably in the default location C\+:)
117 \item Fix up Min\+GW headers
119 a) Add the following lines to C\+:.h\+:
121 1 #if(\_WIN32\_WINNT >= 0x0600)
123 3 typedef struct pollfd \{
129 9 \} WSAPOLLFD, *PWSAPOLLFD, FAR *LPWSAPOLLFD;
131 11 WINSOCK\_API\_LINKAGE int WSAAPI WSAPoll(LPWSAPOLLFD fdArray, ULONG fds, INT timeout);
133 13 #endif // (\_WIN32\_WINNT >= 0x0600)
135 b) Create C\+:.h and copy and paste the content from following link into it\+:
137 \href{http://wine-unstable.sourcearchive.com/documentation/1.1.32/mstcpip_8h-source.html}{\tt http\+://wine-\/unstable.\+sourcearchive.\+com/documentation/1.\+1.\+32/mstcpip\+\_\+8h-\/source.\+html}
138 \item Install C\+Make 2.\+6 or greater\+: \href{http://cmake.org/cmake/resources/software.html}{\tt http\+://cmake.\+org/cmake/resources/software.\+html}
139 \item Install Open\+S\+SL binaries. \href{http://www.openssl.org/related/binaries.html}{\tt http\+://www.\+openssl.\+org/related/binaries.\+html}
141 ({\bfseries N\+O\+TE}\+: Preferably in the default location to make it easier for C\+Make to find them)
143 {\bfseries N\+O\+T\+E2}\+: Be sure that O\+P\+E\+N\+S\+S\+L\+\_\+\+C\+O\+NF environment variable is defined and points at $<$\+Open\+S\+S\+L install=\char`\"{}\char`\"{} location$>$=\char`\"{}\char`\"{}$>$.cfg
144 \item Generate the build files (default is Make files) using M\+S\+YS shell\+:
146 1 $ cd /drive/path/to/src
149 4 $ cmake -G "MSYS Makefiles" -DCMAKE\_INSTALL\_PREFIX=C:/MinGW ..
151 ({\bfseries N\+O\+TE}\+: The {\ttfamily build/}{\ttfamily directory can have any name and be located anywhere on your filesystem, and that the argument}..` given to cmake is simply the source directory of {\bfseries libwebsockets} containing the \href{CMakeLists.txt}{\tt C\+Make\+Lists.\+txt} project file. All examples in this file assumes you use \char`\"{}..\char`\"{})
153 {\bfseries N\+O\+T\+E2}\+: To generate build files allowing to create libwebsockets binaries with debug information set the C\+M\+A\+K\+E\+\_\+\+B\+U\+I\+L\+D\+\_\+\+T\+Y\+PE flag to D\+E\+B\+UG\+:
155 1 $ cmake -G "MSYS Makefiles" -DCMAKE\_INSTALL\_PREFIX=C:/MinGW -DCMAKE\_BUILD\_TYPE=DEBUG ..
158 \item Finally you can build using the generated Makefile and get the results deployed into your Min\+GW installation\+:
166 \hypertarget{md_README.build_mbed3}{}\section{Building on mbed3}\label{md_README.build_mbed3}
167 M\+B\+E\+D3 is a non-\/posix embedded OS targeted on Cortex M class chips.
169 \href{https://www.mbed.com/}{\tt https\+://www.\+mbed.\+com/}
171 It\textquotesingle{}s quite unlike any other Posixy platform since the OS is linked statically in with lws to form one binary.
173 At the minute server-\/only is supported and due to bugs in mbed3 network support, the port is of alpha quality. However it can serve the test html, favicon.\+ico and logo png and may be able to make ws connections. The binary for that including the OS, test app, lws and all the assets is only 117\+KB.
175 0) Today mbed3 only properly works on F\+R\+DM K64F \$35 Freescale Dev Board with 1\+MB Flash, 256\+KB S\+R\+AM and Ethernet.
177 \href{http://www.freescale.com/products/arm-processors/kinetis-cortex-m/k-series/k6x-ethernet-mcus/freescale-freedom-development-platform-for-kinetis-k64-k63-and-k24-mcus:FRDM-K64F}{\tt http\+://www.\+freescale.\+com/products/arm-\/processors/kinetis-\/cortex-\/m/k-\/series/k6x-\/ethernet-\/mcus/freescale-\/freedom-\/development-\/platform-\/for-\/kinetis-\/k64-\/k63-\/and-\/k24-\/mcus\+:\+F\+R\+D\+M-\/\+K64F}
179 1) Get a working mbed3 environment with arm-\/none-\/eabi-\/cs toolchain (available in Fedora, Ubuntu and other distros)
181 2) Confirm you can build things using yotta by following the getting started guide here
183 \href{https://docs.mbed.com/docs/getting-started-mbed-os/en/latest/}{\tt https\+://docs.\+mbed.\+com/docs/getting-\/started-\/mbed-\/os/en/latest/}
187 git clone \href{https://github.com/warmcat/lws-test-server}{\tt https\+://github.\+com/warmcat/lws-\/test-\/server}
191 4) mkdir -\/p yotta\+\_\+modules ; cd yotta\+\_\+modules
193 5) git clone \href{https://github.com/warmcat/libwebsockets}{\tt https\+://github.\+com/warmcat/libwebsockets} ; mv libwebsockets websockets ; cd ..
195 6) yotta target frdm-\/k64f-\/gcc
199 8) yotta build\hypertarget{md_README.build_cmco}{}\section{Setting compile options}\label{md_README.build_cmco}
200 To set compile time flags you can either use one of the C\+Make gui applications or do it via command line.\hypertarget{md_README.build_cmcocl}{}\subsection{Command line}\label{md_README.build_cmcocl}
201 To list avaialable options (omit the H if you don\textquotesingle{}t want the help text)\+: \begin{DoxyVerb} cmake -LH ..
205 Then to set an option and build (for example turn off S\+SL support)\+: \begin{DoxyVerb} cmake -DLWS_WITH_SSL=0 ..
207 or cmake -\/\+D\+L\+W\+S\+\_\+\+W\+I\+T\+H\+\_\+\+S\+SL\+:B\+O\+OL=O\+FF ..\hypertarget{md_README.build_cmcoug}{}\subsection{Unix G\+UI}\label{md_README.build_cmcoug}
208 If you have a curses-\/enabled build you simply type\+: (not all packages include this, my debian install does not for example). \begin{DoxyVerb} ccmake
210 \hypertarget{md_README.build_cmcowg}{}\subsection{Windows G\+UI}\label{md_README.build_cmcowg}
211 On windows C\+Make comes with a gui application\+: Start -\/$>$ Programs -\/$>$ C\+Make -\/$>$ C\+Make (cmake-\/gui)\hypertarget{md_README.build_wolf}{}\section{wolf\+S\+S\+L/\+Cya\+S\+S\+L replacement for Open\+S\+SL}\label{md_README.build_wolf}
212 wolf\+S\+S\+L/\+Cya\+S\+SL is a lightweight S\+SL library targeted at embedded systems\+: \href{https://www.wolfssl.com/wolfSSL/Products-wolfssl.html}{\tt https\+://www.\+wolfssl.\+com/wolf\+S\+S\+L/\+Products-\/wolfssl.\+html}
214 It contains a Open\+S\+SL compatibility layer which makes it possible to pretty much link to it instead of Open\+S\+SL, giving a much smaller footprint.
216 {\bfseries N\+O\+TE}\+: wolfssl needs to be compiled using the {\ttfamily -\/-\/enable-\/opensslextra} flag for this to work.\hypertarget{md_README.build_wolf1}{}\section{Compiling libwebsockets with wolf\+S\+SL}\label{md_README.build_wolf1}
219 1 cmake .. -DLWS\_USE\_WOLFSSL=1 \(\backslash\)
220 2 -DLWS\_WOLFSSL\_INCLUDE\_DIRS=/path/to/wolfssl \(\backslash\)
221 3 -DLWS\_WOLFSSL\_LIBRARIES=/path/to/wolfssl/wolfssl.a ..
225 {\bfseries N\+O\+TE}\+: On windows use the .lib file extension for {\ttfamily L\+W\+S\+\_\+\+W\+O\+L\+F\+S\+S\+L\+\_\+\+L\+I\+B\+R\+A\+R\+I\+ES} instead.\hypertarget{md_README.build_cya}{}\section{Compiling libwebsockets with Cya\+S\+SL}\label{md_README.build_cya}
228 1 cmake .. -DLWS\_USE\_CYASSL=1 \(\backslash\)
229 2 -DLWS\_CYASSL\_INCLUDE\_DIRS=/path/to/cyassl \(\backslash\)
230 3 -DLWS\_CYASSL\_LIBRARIES=/path/to/wolfssl/cyassl.a ..
234 {\bfseries N\+O\+TE}\+: On windows use the .lib file extension for {\ttfamily L\+W\+S\+\_\+\+C\+Y\+A\+S\+S\+L\+\_\+\+L\+I\+B\+R\+A\+R\+I\+ES} instead.\hypertarget{md_README.build_extplugins}{}\section{Building plugins outside of lws itself}\label{md_README.build_extplugins}
235 The directory ./plugin-\/standalone/ shows how easy it is to create plugins outside of lws itself. First build lws itself with -\/\+D\+L\+W\+S\+\_\+\+W\+I\+T\+H\+\_\+\+P\+L\+U\+G\+I\+NS, then use the same flow to build the standalone plugin
237 1 cd ./plugin-standalone
241 5 make && sudo make install
245 if you changed the default plugin directory when you built lws, you must also give the same arguments to cmake here (eg, {\ttfamily -\/\+D\+C\+M\+A\+K\+E\+\_\+\+I\+N\+S\+T\+A\+L\+L\+\_\+\+P\+R\+E\+F\+IX\+:P\+A\+TH=/usr/something/else...} )
247 Otherwise if you run lwsws or libwebsockets-\/test-\/server-\/v2.\+0, it will now find the additional plugin \char`\"{}libprotocol\+\_\+example\+\_\+standalone.\+so\char`\"{}
249 1 lwsts[21257]: Plugins:
250 2 lwsts[21257]: libprotocol\_dumb\_increment.so
251 3 lwsts[21257]: libprotocol\_example\_standalone.so
252 4 lwsts[21257]: libprotocol\_lws\_mirror.so
253 5 lwsts[21257]: libprotocol\_lws\_server\_status.so
254 6 lwsts[21257]: libprotocol\_lws\_status.so
256 If you have multiple vhosts, you must enable plugins at the vhost additionally, discovered plugins are not enabled automatically for security reasons. You do this using info-\/$>$pvo or for lwsws, in the J\+S\+ON config.\hypertarget{md_README.build_http2rp}{}\section{Reproducing H\+T\+T\+P2.\+0 tests}\label{md_README.build_http2rp}
257 You must have built and be running lws against a version of openssl that has A\+L\+PN / N\+PN. Most distros still have older versions. You\textquotesingle{}ll know it\textquotesingle{}s right by seeing
259 1 lwsts[4752]: Compiled with OpenSSL support
260 2 lwsts[4752]: Using SSL mode
261 3 lwsts[4752]: HTTP2 / ALPN enabled
265 For non-\/\+S\+SL H\+T\+T\+P2.\+0 upgrade
267 1 $ nghttp -nvasu http://localhost:7681/test.htm
269 For S\+SL / A\+L\+PN H\+T\+T\+P2.\+0 upgrade
271 1 $ nghttp -nvas https://localhost:7681/test.html
273 \hypertarget{md_README.build_cross}{}\section{Cross compiling}\label{md_README.build_cross}
274 To enable cross-\/compiling {\bfseries libwebsockets} using C\+Make you need to create a \char`\"{}\+Toolchain file\char`\"{} that you supply to C\+Make when generating your build files. C\+Make will then use the cross compilers and build paths specified in this file to look for dependencies and such.
276 {\bfseries Libwebsockets} includes an example toolchain file \href{cross-arm-linux-gnueabihf.cmake}{\tt cross-\/arm-\/linux-\/gnueabihf.\+cmake} you can use as a starting point.
278 The commandline to configure for cross with this would look like
280 1 $ cmake .. -DCMAKE\_INSTALL\_PREFIX:PATH=/usr \(\backslash\)
281 2 -DCMAKE\_TOOLCHAIN\_FILE=../cross-arm-linux-gnueabihf.cmake \(\backslash\)
282 3 -DWITHOUT\_EXTENSIONS=1 -DWITH\_SSL=0
284 The example shows how to build with no external cross lib dependencies, you need to provide the cross libraries otherwise.
286 {\bfseries N\+O\+TE}\+: start from an E\+M\+P\+TY build directory if you had a non-\/cross build in there before the settings will be cached and your changes ignored.
288 Additional information on cross compilation with C\+Make\+: \href{http://www.vtk.org/Wiki/CMake_Cross_Compiling}{\tt http\+://www.\+vtk.\+org/\+Wiki/\+C\+Make\+\_\+\+Cross\+\_\+\+Compiling}\hypertarget{md_README.build_mem}{}\section{Memory efficiency}\label{md_README.build_mem}
289 Embedded server-\/only configuration without extensions (ie, no compression on websocket connections), but with full v13 websocket features and http server, built on A\+RM Cortex-\/\+A9\+:
291 Update at 8dac94d (2013-\/02-\/18)
293 1 $ ./configure --without-client --without-extensions --disable-debug --without-daemonize
295 3 Context Creation, 1024 fd limit[2]: 16720 (includes 12 bytes per fd)
296 4 Per-connection [3]: 72 bytes, +1328 during headers
298 6 .text .rodata .data .bss
301 This shows the impact of the major configuration with/without options at 13ba5bbc633ea962d46d using Ubuntu A\+RM on a Panda\+Board ES.
303 These are accounting for static allocations from the library elf, there are additional dynamic allocations via malloc. These are a bit old now but give the right idea for relative \char`\"{}expense\char`\"{} of features.
305 Static allocations, A\+R\+M9
308 \begin{longtabu} spread 0pt [c]{*5{|X[-1]}|}
310 \rowcolor{\tableheadbgcolor}{\bf }&{\bf .text }&{\bf .rodata }&{\bf .data }&{\bf .bss }\\\cline{1-5}
315 \rowcolor{\tableheadbgcolor}{\bf }&{\bf .text }&{\bf .rodata }&{\bf .data }&{\bf .bss }\\\cline{1-5}
317 All (no without) &35024 &9940 &336 &4104 \\\cline{1-5}
318 without client &25684 &7144 &336 &4104 \\\cline{1-5}
319 without client, exts &21652 &6288 &288 &4104 \\\cline{1-5}
320 without client, exts, debug\mbox{[}1\mbox{]} &19756 &3768 &288 &4104 \\\cline{1-5}
321 without server &30304 &8160 &336 &4104 \\\cline{1-5}
322 without server, exts &25382 &7204 &288 &4104 \\\cline{1-5}
323 without server, exts, debug\mbox{[}1\mbox{]} &23712 &4256 &288 &4104 \\\cline{1-5}
325 \mbox{[}1\mbox{]} {\ttfamily -\/-\/disable-\/debug} only removes messages below {\ttfamily lwsl\+\_\+notice}. Since that is the default logging level the impact is not noticeable, error, warn and notice logs are all still there.
327 \mbox{[}2\mbox{]} {\ttfamily 1024} fd per process is the default limit (set by ulimit) in at least Fedora and Ubuntu. You can make significant savings tailoring this to actual expected peak fds, ie, at a limit of {\ttfamily 20}, context creation allocation reduces to {\ttfamily 4432 + 240 = 4672})
329 \mbox{[}3\mbox{]} known header content is freed after connection establishment