1 Notes about building lws
2 ========================
5 @section cm Introduction to CMake
7 CMake is a multi-platform build tool that can generate build files for many
8 different target platforms. See more info at http://www.cmake.org
10 CMake also allows/recommends you to do "out of source"-builds, that is,
11 the build files are separated from your sources, so there is no need to
12 create elaborate clean scripts to get a clean source tree, instead you
13 simply remove your build directory.
15 Libwebsockets has been tested to build successfully on the following platforms
16 with SSL support (for OpenSSL/wolfSSL/BoringSSL):
18 - Windows (Visual Studio)
25 @section build1 Building the library and test apps
27 The project settings used by CMake to generate the platform specific build
28 files is called [CMakeLists.txt](CMakeLists.txt). CMake then uses one of its "Generators" to
29 output a Visual Studio project or Make file for instance. To see a list of
30 the available generators for your platform, simply run the "cmake" command.
32 Note that by default OpenSSL will be linked, if you don't want SSL support
33 see below on how to toggle compile options.
36 @section bu Building on Unix:
38 1. Install CMake 2.8 or greater: http://cmake.org/cmake/resources/software.html
39 (Most Unix distributions comes with a packaged version also)
43 3. Generate the build files (default is Make files):
51 4. Finally you can build using the generated Makefile:
53 $ make && sudo make install
55 **NOTE**: The `build/`` directory can have any name and be located anywhere
56 on your filesystem, and that the argument `..` given to cmake is simply
57 the source directory of **libwebsockets** containing the [CMakeLists.txt](CMakeLists.txt)
58 project file. All examples in this file assumes you use ".."
61 A common option you may want to give is to set the install path, same
62 as --prefix= with autotools. It defaults to /usr/local.
63 You can do this by, eg
65 $ cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .
69 On machines that want libraries in lib64, you can also add the
70 following to the cmake line
76 If you are building against a non-distro OpenSSL (eg, in order to get
77 access to ALPN support only in newer OpenSSL versions) the nice way to
78 express that in one cmake command is eg,
80 $ cmake .. -DOPENSSL_ROOT_DIR=/usr/local/ssl \
81 -DCMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE=/usr/local/ssl \
85 When you run the test apps using non-distro SSL, you have to force them
86 to use your libs, not the distro ones
88 $ LD_LIBRARY_PATH=/usr/local/ssl/lib libwebsockets-test-server --ssl
91 To get it to build on latest openssl (2016-04-10) it needed this approach
93 cmake .. -DLWS_WITH_HTTP2=1 -DLWS_OPENSSL_INCLUDE_DIRS=/usr/local/include/openssl -DLWS_OPENSSL_LIBRARIES="/usr/local/lib64/libssl.so;/usr/local/lib64/libcrypto.so"
96 Mac users have reported
99 $ export OPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2k; cmake ..; make -j4
102 worked for them when using "homebrew" OpenSSL
105 To build with debug info and _DEBUG for lower priority debug messages
108 $ cmake .. -DCMAKE_BUILD_TYPE=DEBUG
112 To build on Solaris the linker needs to be informed to use lib socket
113 and libnsl, and only builds in 64bit mode.
116 $ cmake .. -DCMAKE_C_FLAGS=-m64 -DCMAKE_EXE_LINKER_FLAGS="-lsocket -lnsl"
119 4. Finally you can build using the generated Makefile:
125 @section cmq Quirk of cmake
127 When changing cmake options, for some reason the only way to get it to see the
128 changes sometimes is delete the contents of your build directory and do the
132 @section cmw Building on Windows (Visual Studio)
134 1. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
136 2. Install OpenSSL binaries. http://www.openssl.org/related/binaries.html
138 (**NOTE**: Preferably in the default location to make it easier for CMake to find them)
141 Be sure that OPENSSL_CONF environment variable is defined and points at
142 <OpenSSL install location>\bin\openssl.cfg
144 3. Generate the Visual studio project by opening the Visual Studio cmd prompt:
150 cmake -G "Visual Studio 10" ..
153 (**NOTE**: There is also a cmake-gui available on Windows if you prefer that)
156 See this link to find out the version number corresponding to your Visual Studio edition:
157 http://superuser.com/a/194065
159 4. Now you should have a generated Visual Studio Solution in your
160 `<path to src>/build` directory, which can be used to build.
162 5. Some additional deps may be needed
168 6. If you're using libuv, you must make sure to compile libuv with the same multithread-dll / Mtd attributes as libwebsockets itself
171 @section cmwmgw Building on Windows (MinGW)
173 1. Install MinGW: http://sourceforge.net/projects/mingw/files
175 (**NOTE**: Preferably in the default location C:\MinGW)
177 2. Fix up MinGW headers
179 a) Add the following lines to C:\MinGW\include\winsock2.h:
181 #if(_WIN32_WINNT >= 0x0600)
183 typedef struct pollfd {
189 } WSAPOLLFD, *PWSAPOLLFD, FAR *LPWSAPOLLFD;
191 WINSOCK_API_LINKAGE int WSAAPI WSAPoll(LPWSAPOLLFD fdArray, ULONG fds, INT timeout);
193 #endif // (_WIN32_WINNT >= 0x0600)
195 b) Create C:\MinGW\include\mstcpip.h and copy and paste the content from following link into it:
197 http://wine-unstable.sourcearchive.com/documentation/1.1.32/mstcpip_8h-source.html
199 3. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
201 4. Install OpenSSL binaries. http://www.openssl.org/related/binaries.html
203 (**NOTE**: Preferably in the default location to make it easier for CMake to find them)
206 Be sure that OPENSSL_CONF environment variable is defined and points at
207 <OpenSSL install location>\bin\openssl.cfg
209 5. Generate the build files (default is Make files) using MSYS shell:
211 $ cd /drive/path/to/src
214 $ cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=C:/MinGW ..
216 (**NOTE**: The `build/`` directory can have any name and be located anywhere
217 on your filesystem, and that the argument `..` given to cmake is simply
218 the source directory of **libwebsockets** containing the [CMakeLists.txt](CMakeLists.txt)
219 project file. All examples in this file assumes you use "..")
222 To generate build files allowing to create libwebsockets binaries with debug information
223 set the CMAKE_BUILD_TYPE flag to DEBUG:
225 $ cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=C:/MinGW -DCMAKE_BUILD_TYPE=DEBUG ..
227 6. Finally you can build using the generated Makefile and get the results deployed into your MinGW installation:
234 @section optee Building for OP-TEE
236 OP-TEE is a "Secure World" Trusted Execution Environment.
238 Although lws is only part of the necessary picture to have an https-enabled
239 TA, it does support OP-TEE as a platform and if you provide the other
240 pieces, does work very well.
242 Select it in cmake with `-DLWS_PLAT_OPTEE=1`
245 @section cmco Setting compile options
247 To set compile time flags you can either use one of the CMake gui applications
248 or do it via the command line.
250 @subsection cmcocl Command line
252 To list available options (omit the H if you don't want the help text):
256 Then to set an option and build (for example turn off SSL support):
258 cmake -DLWS_WITH_SSL=0 ..
260 cmake -DLWS_WITH_SSL:BOOL=OFF ..
262 @subsection cmcoug Unix GUI
264 If you have a curses-enabled build you simply type:
265 (not all packages include this, my debian install does not for example).
269 @subsection cmcowg Windows GUI
271 On windows CMake comes with a gui application:
272 Start -> Programs -> CMake -> CMake (cmake-gui)
275 @section wolf wolfSSL/CyaSSL replacement for OpenSSL
277 wolfSSL/CyaSSL is a lightweight SSL library targeted at embedded systems:
278 https://www.wolfssl.com/wolfSSL/Products-wolfssl.html
280 It contains a OpenSSL compatibility layer which makes it possible to pretty
281 much link to it instead of OpenSSL, giving a much smaller footprint.
283 **NOTE**: wolfssl needs to be compiled using the `--enable-opensslextra` flag for
286 @section wolf1 Compiling libwebsockets with wolfSSL
289 cmake .. -DLWS_USE_WOLFSSL=1 \
290 -DLWS_WOLFSSL_INCLUDE_DIRS=/path/to/wolfssl \
291 -DLWS_WOLFSSL_LIBRARIES=/path/to/wolfssl/wolfssl.a ..
294 **NOTE**: On windows use the .lib file extension for `LWS_WOLFSSL_LIBRARIES` instead.
296 @section cya Compiling libwebsockets with CyaSSL
299 cmake .. -DLWS_USE_CYASSL=1 \
300 -DLWS_CYASSL_INCLUDE_DIRS=/path/to/cyassl \
301 -DLWS_CYASSL_LIBRARIES=/path/to/wolfssl/cyassl.a ..
304 **NOTE**: On windows use the .lib file extension for `LWS_CYASSL_LIBRARIES` instead.
307 @section extplugins Building plugins outside of lws itself
309 The directory ./plugin-standalone/ shows how easy it is to create plugins
310 outside of lws itself. First build lws itself with -DLWS_WITH_PLUGINS,
311 then use the same flow to build the standalone plugin
313 cd ./plugin-standalone
317 make && sudo make install
320 if you changed the default plugin directory when you built lws, you must
321 also give the same arguments to cmake here (eg,
322 ` -DCMAKE_INSTALL_PREFIX:PATH=/usr/something/else...` )
324 Otherwise if you run lwsws or libwebsockets-test-server-v2.0, it will now
325 find the additional plugin "libprotocol_example_standalone.so"
327 lwsts[21257]: Plugins:
328 lwsts[21257]: libprotocol_dumb_increment.so
329 lwsts[21257]: libprotocol_example_standalone.so
330 lwsts[21257]: libprotocol_lws_mirror.so
331 lwsts[21257]: libprotocol_lws_server_status.so
332 lwsts[21257]: libprotocol_lws_status.so
334 If you have multiple vhosts, you must enable plugins at the vhost
335 additionally, discovered plugins are not enabled automatically for security
336 reasons. You do this using info->pvo or for lwsws, in the JSON config.
339 @section http2rp Reproducing HTTP2.0 tests
341 You must have built and be running lws against a version of openssl that has
342 ALPN / NPN. Most distros still have older versions. You'll know it's right by
345 lwsts[4752]: Compiled with OpenSSL support
346 lwsts[4752]: Using SSL mode
347 lwsts[4752]: HTTP2 / ALPN enabled
351 For non-SSL HTTP2.0 upgrade
353 $ nghttp -nvasu http://localhost:7681/test.htm
355 For SSL / ALPN HTTP2.0 upgrade
357 $ nghttp -nvas https://localhost:7681/test.html
360 @section cross Cross compiling
362 To enable cross-compiling **libwebsockets** using CMake you need to create
363 a "Toolchain file" that you supply to CMake when generating your build files.
364 CMake will then use the cross compilers and build paths specified in this file
365 to look for dependencies and such.
367 **Libwebsockets** includes an example toolchain file [cross-arm-linux-gnueabihf.cmake](cross-arm-linux-gnueabihf.cmake)
368 you can use as a starting point.
370 The commandline to configure for cross with this would look like
372 $ cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr \
373 -DCMAKE_TOOLCHAIN_FILE=../cross-arm-linux-gnueabihf.cmake \
374 -DLWS_WITHOUT_EXTENSIONS=1 -DLWS_WITH_SSL=0
376 The example shows how to build with no external cross lib dependencies, you
377 need to provide the cross libraries otherwise.
379 **NOTE**: start from an EMPTY build directory if you had a non-cross build in there
380 before the settings will be cached and your changes ignored.
382 Additional information on cross compilation with CMake:
383 http://www.vtk.org/Wiki/CMake_Cross_Compiling
385 @section mem Memory efficiency
387 Embedded server-only configuration without extensions (ie, no compression
388 on websocket connections), but with full v13 websocket features and http
389 server, built on ARM Cortex-A9:
391 Update at 8dac94d (2013-02-18)
393 $ ./configure --without-client --without-extensions --disable-debug --without-daemonize
395 Context Creation, 1024 fd limit[2]: 16720 (includes 12 bytes per fd)
396 Per-connection [3]: 72 bytes, +1328 during headers
398 .text .rodata .data .bss
401 This shows the impact of the major configuration with/without options at
402 13ba5bbc633ea962d46d using Ubuntu ARM on a PandaBoard ES.
404 These are accounting for static allocations from the library elf, there are
405 additional dynamic allocations via malloc. These are a bit old now but give
406 the right idea for relative "expense" of features.
408 Static allocations, ARM9
410 | | .text | .rodata | .data | .bss |
411 |--------------------------------|---------|---------|-------|------|
412 | All (no without) | 35024 | 9940 | 336 | 4104 |
413 | without client | 25684 | 7144 | 336 | 4104 |
414 | without client, exts | 21652 | 6288 | 288 | 4104 |
415 | without client, exts, debug[1] | 19756 | 3768 | 288 | 4104 |
416 | without server | 30304 | 8160 | 336 | 4104 |
417 | without server, exts | 25382 | 7204 | 288 | 4104 |
418 | without server, exts, debug[1] | 23712 | 4256 | 288 | 4104 |
420 [1] `--disable-debug` only removes messages below `lwsl_notice`. Since that is
421 the default logging level the impact is not noticeable, error, warn and notice
422 logs are all still there.
424 [2] `1024` fd per process is the default limit (set by ulimit) in at least Fedora
425 and Ubuntu. You can make significant savings tailoring this to actual expected
426 peak fds, ie, at a limit of `20`, context creation allocation reduces to `4432 +
429 [3] known header content is freed after connection establishment