1Notes about building lws 2======================== 3 4You can download and install lws using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager: 5``` 6git clone https://github.com/microsoft/vcpkg.git 7cd vcpkg 8./bootstrap-vcpkg.sh 9./vcpkg integrate install 10vcpkg install libwebsockets 11``` 12The lws port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg/) on the vcpkg repository. 13 14@section cm Introduction to CMake 15 16CMake is a multi-platform build tool that can generate build files for many 17different target platforms. See more info at http://www.cmake.org 18 19CMake also allows/recommends you to do "out of source"-builds, that is, 20the build files are separated from your sources, so there is no need to 21create elaborate clean scripts to get a clean source tree, instead you 22simply remove your build directory. 23 24Libwebsockets has been tested to build successfully on the following platforms 25with SSL support (for OpenSSL/wolfSSL/BoringSSL): 26 27- Windows (Visual Studio) 28- Windows (MinGW) 29- Linux (x86 and ARM) 30- OSX 31- NetBSD 32 33 34@section build1 Building the library and test apps 35 36The project settings used by CMake to generate the platform specific build 37files is called [CMakeLists.txt](../CMakeLists.txt). CMake then uses one of its "Generators" to 38output a Visual Studio project or Make file for instance. To see a list of 39the available generators for your platform, simply run the "cmake" command. 40 41Note that by default OpenSSL will be linked, if you don't want SSL support 42see below on how to toggle compile options. 43 44 45@section bu Building on Unix: 46 471. Install CMake 2.8 or greater: http://cmake.org/cmake/resources/software.html 48 (Most Unix distributions comes with a packaged version also) 49 502. Install OpenSSL. 51 523. Generate the build files (default is Make files): 53``` 54 $ cd /path/to/src 55 $ mkdir build 56 $ cd build 57 $ cmake .. 58``` 59 604. Finally you can build using the generated Makefile: 61``` 62 $ make && sudo make install 63``` 64**NOTE**: The `build/`` directory can have any name and be located anywhere 65 on your filesystem, and that the argument `..` given to cmake is simply 66 the source directory of **libwebsockets** containing the [CMakeLists.txt](../CMakeLists.txt) 67 project file. All examples in this file assumes you use ".." 68 69**NOTE2**: 70A common option you may want to give is to set the install path, same 71as --prefix= with autotools. It defaults to /usr/local. 72You can do this by, eg 73``` 74 $ cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr . 75``` 76 77**NOTE3**: 78On machines that want libraries in lib64, you can also add the 79following to the cmake line 80``` 81 -DLIB_SUFFIX=64 82``` 83 84**NOTE4**: 85If you are building against a non-distro OpenSSL (eg, in order to get 86access to ALPN support only in newer OpenSSL versions) the nice way to 87express that in one cmake command is eg, 88``` 89 $ cmake .. -DOPENSSL_ROOT_DIR=/usr/local/ssl \ 90 -DCMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE=/usr/local/ssl \ 91 -DLWS_WITH_HTTP2=1 92``` 93 94When you run the test apps using non-distro SSL, you have to force them 95to use your libs, not the distro ones 96``` 97 $ LD_LIBRARY_PATH=/usr/local/ssl/lib libwebsockets-test-server --ssl 98``` 99 100To get it to build on latest openssl (2016-04-10) it needed this approach 101``` 102 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" 103``` 104 105Mac users have reported 106 107``` 108 $ export OPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2k; cmake ..; make -j4 109``` 110 111worked for them when using "homebrew" OpenSSL 112 113**NOTE5**: 114To build with debug info and _DEBUG for lower priority debug messages 115compiled in, use 116``` 117 $ cmake .. -DCMAKE_BUILD_TYPE=DEBUG 118``` 119 120**NOTE6** 121To build on Solaris the linker needs to be informed to use lib socket 122and libnsl, and only builds in 64bit mode. 123 124```bash 125 $ cmake .. -DCMAKE_C_FLAGS=-m64 -DCMAKE_EXE_LINKER_FLAGS="-lsocket -lnsl" 126``` 127 128**NOTE7** 129 130Build and test flow against boringssl. Notice `LWS_WITH_GENHASH` is currently 131unavailable with boringssl due to their removing the necessary apis. 132 133Build current HEAD boringssl 134 135``` 136 $ cd /projects 137 $ git clone https://boringssl.googlesource.com/boringssl 138 $ cd boringssl 139 $ mkdir build 140 $ cd build 141 $ cmake .. -DBUILD_SHARED_LIBS=1 142 $ make -j8 143``` 144 145Build and test lws against it 146 147``` 148 $ cd /projects/libwebsockets/build 149 $ cmake .. -DOPENSSL_LIBRARIES="/projects/boringssl/build/ssl/libssl.so;\ 150 /projects/boringssl/build/crypto/libcrypto.so" \ 151 -DOPENSSL_INCLUDE_DIRS=/projects/boringssl/include \ 152 -DLWS_WITH_BORINGSSL=1 -DCMAKE_BUILD_TYPE=DEBUG 153 $ make -j8 && sudo make install 154 $ LD_PRELOAD="/projects/boringssl/build/ssl/libssl.so \ 155 /projects/boringssl/build/crypto/libcrypto.so" \ 156 /usr/local/bin/libwebsockets-test-server -s 157``` 158 1594. Finally you can build using the generated Makefile: 160 161```bash 162 $ make 163 ``` 164 165@section lcap Linux Capabilities 166 167On Linux, lws now lets you retain selected root capabilities when dropping 168privileges. If libcap-dev or similar package is installed providing 169sys/capabilities.h, and libcap or similar package is installed providing 170libcap.so, CMake will enable the capability features. 171 172The context creation info struct .caps[] and .count_caps members can then 173be set by user code to enable selected root capabilities to survive the 174transition to running under an unprivileged user. 175 176@section cmq Quirk of cmake 177 178When changing cmake options, for some reason the only way to get it to see the 179changes sometimes is delete the contents of your build directory and do the 180cmake from scratch. 181 182deleting build/CMakeCache.txt may be enough. 183 184 185@section cmw Building on Windows (Visual Studio) 186 1871. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html 188 1892. Install OpenSSL binaries. https://wiki.openssl.org/index.php/Binaries 190 191 (**NOTE**: Preferably in the default location to make it easier for CMake to find them) 192 193 **NOTE2**: 194 Be sure that OPENSSL_CONF environment variable is defined and points at 195 <OpenSSL install location>\bin\openssl.cfg 196 1973. Generate the Visual studio project by opening the Visual Studio cmd prompt: 198 199``` 200 cd <path to src> 201 md build 202 cd build 203 cmake -G "Visual Studio 10" .. 204``` 205 206 (**NOTE**: There is also a cmake-gui available on Windows if you prefer that) 207 208 **NOTE2**: 209 See this link to find out the version number corresponding to your Visual Studio edition: 210 http://superuser.com/a/194065 211 2124. Now you should have a generated Visual Studio Solution in your 213 `<path to src>/build` directory, which can be used to build. 214 2155. Some additional deps may be needed 216 217 - iphlpapi.lib 218 - psapi.lib 219 - userenv.lib 220 2216. If you're using libuv, you must make sure to compile libuv with the same multithread-dll / Mtd attributes as libwebsockets itself 222 223 224@section cmwmgw Building on Windows (MinGW) 225 2261. Install MinGW 227 228 For Fedora, it's, eg, `dnf install mingw64-gcc` 229 2302. Install current CMake package 231 232 For Fedora, it's `dnf install cmake` 233 2343. Instal mingw-built OpenSSL pieces 235 236 For Fedora, it's `mingw64-openssl.noarch mingw64-openssl-static.noarch` 237 238 mingw64-cmake as described below will auto-find the libs and includes 239 for build. But to execute the apps, they either need to go into the same 240 `/usr/x86_64-w64-mingw32/sys-root/mingw/bin/` as the dlls are installed to, 241 or the dlls have to be copied into the same dir as your app executable. 242 2434. Generate the build files (default is Make files) using MSYS shell. 244 245 For Fedora, they provide a `mingw64-cmake` wrapper in the package 246 `mingw64-filesystem`, with this you can run that instead of cmake directly 247 and don't have to get involved with setting the cmake generator. 248 249 Otherwise doing it by hand is like this: 250 251``` 252 $ cd /drive/path/to/src 253 $ mkdir build 254 $ cd build 255 $ cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=C:/MinGW .. 256``` 257 258 To generate build files allowing to create libwebsockets binaries with debug information 259 set the CMAKE_BUILD_TYPE flag to DEBUG: 260``` 261 $ cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=C:/MinGW -DCMAKE_BUILD_TYPE=DEBUG .. 262``` 2635. Finally you can build using the generated Makefile and get the results deployed into your MinGW installation: 264 265``` 266 $ make && make install 267``` 268 269@section distro Selecting CMake options useful for distros 270 271Distro packagers should select the CMake option "LWS_WITH_DISTRO_RECOMMENDED", 272which selects common additional options like support for various event libraries, 273plugins and lwsws. 274 275@section ssllib Choosing Your TLS Poison 276 277 - If you are really restricted on memory, code size, or don't care about TLS 278 speed, mbedTLS is a good choice: `cmake .. -DLWS_WITH_MBEDTLS=1` 279 280 - If cpu and memory is not super restricted and you care about TLS speed, 281 OpenSSL or a directly compatible variant like Boring SSL is a good choice. 282 283Just building lws against stock Fedora OpenSSL or stock Fedora mbedTLS, for 284SSL handhake mbedTLS takes ~36ms and OpenSSL takes ~1ms on the same x86_64 285build machine here, with everything else the same. Over the 144 connections of 286h2spec compliance testing for example, this ends up completing in 400ms for 287OpenSSL and 5.5sec for mbedTLS on x86_64. In other words mbedTLS is very slow 288compared to OpenSSL under the (fairly typical) conditions I tested it. 289 290This isn't an inefficiency in the mbedtls interface implementation, it's just 291mbedTLS doing the crypto much slower than OpenSSL, which has accelerated 292versions of common crypto operations it automatically uses for platforms 293supporting it. As of Oct 2017 mbedTLS itself has no such optimizations for any 294platform that I could find. It's just pure C running on the CPU. 295 296Lws supports both almost the same, so instead of taking my word for it you are 297invited to try it both ways and see which the results (including, eg, binary 298size and memory usage as well as speed) suggest you use. 299 300NOTE: one major difference with mbedTLS is it does not load the system trust 301store by default. That has advantages and disadvantages, but the disadvantage 302is you must provide the CA cert to lws built against mbedTLS for it to be able 303to validate it, ie, use -A with the test client. The minimal test clients 304have the CA cert for warmcat.com and libwebsockets.org and use it if they see 305they were built with mbedTLS. 306 307@section optee Building for OP-TEE 308 309OP-TEE is a "Secure World" Trusted Execution Environment. 310 311Although lws is only part of the necessary picture to have an https-enabled 312TA, it does support OP-TEE as a platform and if you provide the other 313pieces, does work very well. 314 315Select it in cmake with `-DLWS_PLAT_OPTEE=1` 316 317 318@section cmco Setting compile options 319 320To set compile time flags you can either use one of the CMake gui applications 321or do it via the command line. 322 323@subsection cmcocl Command line 324 325To list available options (omit the H if you don't want the help text): 326 327 cmake -LH .. 328 329Then to set an option and build (for example turn off SSL support): 330 331 cmake -DLWS_WITH_SSL=0 .. 332or 333 cmake -DLWS_WITH_SSL:BOOL=OFF .. 334 335@subsection cmcoug Unix GUI 336 337If you have a curses-enabled build you simply type: 338(not all packages include this, my debian install does not for example). 339 340 ccmake 341 342@subsection cmcowg Windows GUI 343 344On windows CMake comes with a gui application: 345 Start -> Programs -> CMake -> CMake (cmake-gui) 346 347 348@section wolf wolfSSL/CyaSSL replacement for OpenSSL 349 350wolfSSL/CyaSSL is a lightweight SSL library targeted at embedded systems: 351https://www.wolfssl.com/wolfSSL/Products-wolfssl.html 352 353It contains a OpenSSL compatibility layer which makes it possible to pretty 354much link to it instead of OpenSSL, giving a much smaller footprint. 355 356**NOTE**: wolfssl needs to be compiled using the `--enable-opensslextra` flag for 357this to work. 358 359@section wolf1 Compiling libwebsockets with wolfSSL 360 361``` 362 cmake .. -DLWS_WITH_WOLFSSL=1 \ 363 -DLWS_WOLFSSL_INCLUDE_DIRS=/path/to/wolfssl \ 364 -DLWS_WOLFSSL_LIBRARIES=/path/to/wolfssl/wolfssl.a .. 365``` 366 367**NOTE**: On windows use the .lib file extension for `LWS_WOLFSSL_LIBRARIES` instead. 368 369@section cya Compiling libwebsockets with CyaSSL 370 371``` 372 cmake .. -DLWS_WITH_CYASSL=1 \ 373 -DLWS_CYASSL_INCLUDE_DIRS=/path/to/cyassl \ 374 -DLWS_CYASSL_LIBRARIES=/path/to/wolfssl/cyassl.a .. 375``` 376 377**NOTE**: On windows use the .lib file extension for `LWS_CYASSL_LIBRARIES` instead. 378 379@section gzip Selecting GZIP or MINIZ 380 381By default lws supports gzip when compression is needed. But you can tell it to use 382MINIZ instead by using `-DLWS_WITH_MINIZ=1`. 383 384For native build cmake will try to find an existing libminiz.so or .a and build 385against that and the found includes automatically. 386 387For cross-build or building against local miniz, you need the following kind of 388cmake to tell it where to get miniz 389 390``` 391cmake .. -DLWS_WITH_MINIZ=1 -DLWS_WITH_ZIP_FOPS=1 -DMINIZ_INCLUDE_DIRS="/projects/miniz;/projects/miniz/build" -DMINIZ_LIBRARIES=/projects/miniz/build/libminiz.so.2.1.0 392``` 393 394@section esp32 Building for ESP32 395 396Building for ESP32 requires the ESP-IDF framework. It can be built under Linux, OSX or Windows (MSYS2). 397 3981. Install ESP-IDF, follow the getting started guide here - http://esp-idf.readthedocs.io/en/latest/get-started/ 3992. Set ESP-IDF to last known working version (assuming ESP-IDF is in `~/esp/esp-idf`) : 400``` 401 cd ~/esp/esp-idf 402 git checkout 0c50b65a34cd6b3954f7435193411a88adb49cb0 403 git submodule update --recursive 404``` 4053. Add `libwebsockets` as a submodule in the `components` folder of your ESP-IDF project: 406``` 407 git submodule add https://github.com/warmcat/libwebsockets.git components/libwebsockets 408``` 4094. If on Windows (MSYS2) you will need to install CMake in the MSYS2 environment: 410``` 411 pacman -S mingw-w64-i686-cmake 412``` 413If you're on Linux or OSX ensure CMake version is at least 3.7. 414 415@section extplugins Building plugins outside of lws itself 416 417The directory ./plugin-standalone/ shows how easy it is to create plugins 418outside of lws itself. First build lws itself with -DLWS_WITH_PLUGINS, 419then use the same flow to build the standalone plugin 420``` 421 cd ./plugin-standalone 422 mkdir build 423 cd build 424 cmake .. 425 make && sudo make install 426``` 427 428if you changed the default plugin directory when you built lws, you must 429also give the same arguments to cmake here (eg, 430` -DCMAKE_INSTALL_PREFIX:PATH=/usr/something/else...` ) 431 432Otherwise if you run lwsws or libwebsockets-test-server-v2.0, it will now 433find the additional plugin "libprotocol_example_standalone.so" 434``` 435 lwsts[21257]: Plugins: 436 lwsts[21257]: libprotocol_dumb_increment.so 437 lwsts[21257]: libprotocol_example_standalone.so 438 lwsts[21257]: libprotocol_lws_mirror.so 439 lwsts[21257]: libprotocol_lws_server_status.so 440 lwsts[21257]: libprotocol_lws_status.so 441``` 442If you have multiple vhosts, you must enable plugins at the vhost 443additionally, discovered plugins are not enabled automatically for security 444reasons. You do this using info->pvo or for lwsws, in the JSON config. 445 446 447@section http2rp Reproducing HTTP/2 tests 448 449Enable `-DLWS_WITH_HTTP2=1` in cmake to build with http/2 support enabled. 450 451You must have built and be running lws against a version of openssl that has 452ALPN. At the time of writing, recent distros have started upgrading to OpenSSL 4531.1+ that supports this already. You'll know it's right by seeing 454 455``` 456 lwsts[4752]: Compiled with OpenSSL support 457 lwsts[4752]: Using SSL mode 458 lwsts[4752]: HTTP2 / ALPN enabled 459``` 460at lws startup. 461 462Recent Firefox and Chrome also support HTTP/2 by ALPN, so these should just work 463with the test server running in -s / ssl mode. 464 465For testing with nghttp client: 466 467``` 468 $ nghttp -nvas https://localhost:7681/test.html 469``` 470 471Testing with h2spec (https://github.com/summerwind/h2spec) 472 473``` 474 $ h2spec -h 127.0.0.1 -p 7681 -t -k -v -o 1 475``` 476 477``` 478145 tests, 145 passed, 0 skipped, 0 failed 479 480``` 481 482@section coverage Automated Coverage Testing 483 484./test-apps/attack.sh contains scripted tests that are the basis 485of the automated test coverage assessment available for gcc and clang. 486 487To reproduce 488 489 $ cd build 490 $ cmake .. -DLWS_WITH_GCOV=1 -DCMAKE_BUILD_TYPE=DEBUG 491 $ ../scripts/build-gcov.sh 492 $ ../test-apps/attack.sh 493 $ ../scripts/gcov.sh 494... 495Lines executed:51.24% of 8279 496 497@section windowsprebuilt Using Windows binary builds on Appveyor 498 499The CI builds on Appveyor now produce usable binary outputs. Visit 500 501[lws on Appveyor](https://ci.appveyor.com/project/lws-team/libwebsockets) 502 503and select one of the builds, then click on ARTIFACTS at the top right. The zip file 504want to be unpacked into `C:\Program Files (x86)/libwebsockets`, after that, you should be able to run the test server, by running it from `bin/Release/libwebsockets-test-server.exe` and opening a browser on http://127.0.0.1:7681 505 506@section cross Cross compiling 507 508To enable cross-compiling **libwebsockets** using CMake you need to create 509a "Toolchain file" that you supply to CMake when generating your build files. 510CMake will then use the cross compilers and build paths specified in this file 511to look for dependencies and such. 512 513**Libwebsockets** includes an example toolchain file [cross-arm-linux-gnueabihf.cmake](../contrib/cross-arm-linux-gnueabihf.cmake) 514you can use as a starting point. 515 516The commandline to configure for cross with this would look like 517``` 518 $ cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr/lib/my-cross-root \ 519 -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-arm-linux-gnueabihf.cmake \ 520 -DLWS_WITHOUT_EXTENSIONS=1 -DLWS_WITH_SSL=0 \ 521 -DLWS_WITH_ZIP_FOPS=0 -DLWS_WITH_ZLIB=0 522``` 523The example shows how to build with no external cross lib dependencies, you 524need to provide the cross libraries otherwise. 525 526**NOTE**: start from an EMPTY build directory if you had a non-cross build in there 527 before the settings will be cached and your changes ignored. 528 Delete `build/CMakeCache.txt` at least before trying a new cmake config 529 to ensure you are really building the options you think you are. 530 531Additional information on cross compilation with CMake: 532 http://www.vtk.org/Wiki/CMake_Cross_Compiling 533 534@section cross_example Complex Cross compiling example 535 536Here are step by step instructions for cross-building the external projects needed for lws with lwsws + mbedtls as an example. 537 538In the example, my toolchain lives in `/projects/aist-tb/arm-tc` and is named `arm-linux-gnueabihf`. So you will need to adapt those to where your toolchain lives and its name where you see them here. 539 540Likewise I do all this in /tmp but it has no special meaning, you can adapt that to somewhere else. 541 542All "foreign" cross-built binaries are sent into `/tmp/cross` so they cannot be confused for 'native' x86_64 stuff on your host machine in /usr/[local/].... 543 544## Prepare the cmake toolchain file 545 5461) `cd /tmp` 547 5482) `wget -O mytoolchainfile https://raw.githubusercontent.com/warmcat/libwebsockets/main/contrib/cross-arm-linux-gnueabihf.cmake` 549 5503) Edit `/tmp/mytoolchainfile` adapting `CROSS_PATH`, `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER` to reflect your toolchain install dir and path to your toolchain C and C++ compilers respectively. For my case: 551 552``` 553set(CROSS_PATH /projects/aist-tb/arm-tc/) 554set(CMAKE_C_COMPILER "${CROSS_PATH}/bin/arm-linux-gnueabihf-gcc") 555set(CMAKE_CXX_COMPILER "${CROSS_PATH}/bin/arm-linux-gnueabihf-g++") 556``` 557 558## 1/4: Building libuv cross: 559 5601) `export PATH=/projects/aist-tb/arm-tc/bin:$PATH` Notice there is a **/bin** on the end of the toolchain path 561 5622) `cd /tmp ; mkdir cross` we will put the cross-built libs in /tmp/cross 563 5643) `git clone https://github.com/libuv/libuv.git` get libuv 565 5664) `cd libuv` 567 5685) `./autogen.sh` 569 570``` 571+ libtoolize --copy 572libtoolize: putting auxiliary files in '.'. 573libtoolize: copying file './ltmain.sh' 574libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'. 575libtoolize: copying file 'm4/libtool.m4' 576libtoolize: copying file 'm4/ltoptions.m4' 577libtoolize: copying file 'm4/ltsugar.m4' 578libtoolize: copying file 'm4/ltversion.m4' 579libtoolize: copying file 'm4/lt~obsolete.m4' 580+ aclocal -I m4 581+ autoconf 582+ automake --add-missing --copy 583configure.ac:38: installing './ar-lib' 584configure.ac:25: installing './compile' 585configure.ac:22: installing './config.guess' 586configure.ac:22: installing './config.sub' 587configure.ac:21: installing './install-sh' 588configure.ac:21: installing './missing' 589Makefile.am: installing './depcomp' 590``` 591If it has problems, you will need to install `automake`, `libtool` etc. 592 5936) `./configure --host=arm-linux-gnueabihf --prefix=/tmp/cross` 594 5957) `make && make install` this will install to `/tmp/cross/...` 596 5978) `file /tmp/cross/lib/libuv.so.1.0.0` Check it's really built for ARM 598``` 599/tmp/cross/lib/libuv.so.1.0.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=cdde0bc945e51db6001a9485349c035baaec2b46, with debug_info, not stripped 600``` 601 602## 2/4: Building zlib cross 603 6041) `cd /tmp` 605 6062) `git clone https://github.com/madler/zlib.git` 607 6083) `CC=arm-linux-gnueabihf-gcc ./configure --prefix=/tmp/cross` 609``` 610Checking for shared library support... 611Building shared library libz.so.1.2.11 with arm-linux-gnueabihf-gcc. 612Checking for size_t... Yes. 613Checking for off64_t... Yes. 614Checking for fseeko... Yes. 615Checking for strerror... Yes. 616Checking for unistd.h... Yes. 617Checking for stdarg.h... Yes. 618Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf(). 619Checking for vsnprintf() in stdio.h... Yes. 620Checking for return value of vsnprintf()... Yes. 621Checking for attribute(visibility) support... Yes. 622``` 623 6244) `make && make install` 625``` 626arm-linux-gnueabihf-gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -c -o example.o test/example.c 627... 628rm -f /tmp/cross/include/zlib.h /tmp/cross/include/zconf.h 629cp zlib.h zconf.h /tmp/cross/include 630chmod 644 /tmp/cross/include/zlib.h /tmp/cross/include/zconf.h 631``` 632 6335) `file /tmp/cross/lib/libz.so.1.2.11` This is just to confirm we built an ARM lib as expected 634``` 635/tmp/cross/lib/libz.so.1.2.11: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=6f8ffef84389b1417d2fd1da1bd0c90f748f300d, with debug_info, not stripped 636``` 637 638## 3/4: Building mbedtls cross 639 6401) `cd /tmp` 641 6422) `git clone https://github.com/ARMmbed/mbedtls.git` 643 6443) `cd mbedtls ; mkdir build ; cd build` 645 6463) `cmake .. -DCMAKE_TOOLCHAIN_FILE=/tmp/mytoolchainfile -DCMAKE_INSTALL_PREFIX:PATH=/tmp/cross -DCMAKE_BUILD_TYPE=RELEASE -DUSE_SHARED_MBEDTLS_LIBRARY=1` mbedtls also uses cmake, so you can simply reuse the toolchain file you used for libwebsockets. That is why you shouldn't put project-specific options in the toolchain file, it should just describe the toolchain. 647 6484) `make && make install` 649 6505) `file /tmp/cross/lib/libmbedcrypto.so.2.6.0` 651``` 652/tmp/cross/lib/libmbedcrypto.so.2.6.0: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=bcca195e78bd4fd2fb37f36ab7d72d477d609d87, with debug_info, not stripped 653``` 654 655## 4/4: Building libwebsockets with everything 656 6571) `cd /tmp` 658 6592) `git clone ssh://git@github.com/warmcat/libwebsockets` 660 6613) `cd libwebsockets ; mkdir build ; cd build` 662 6634) (this is all one line on the commandline) 664``` 665cmake .. -DCMAKE_TOOLCHAIN_FILE=/tmp/mytoolchainfile \ 666-DCMAKE_INSTALL_PREFIX:PATH=/tmp/cross \ 667-DLWS_WITH_LWSWS=1 \ 668-DLWS_WITH_MBEDTLS=1 \ 669-DLWS_MBEDTLS_LIBRARIES="/tmp/cross/lib/libmbedcrypto.so;/tmp/cross/lib/libmbedtls.so;/tmp/cross/lib/libmbedx509.so" \ 670-DLWS_MBEDTLS_INCLUDE_DIRS=/tmp/cross/include \ 671-DLWS_LIBUV_LIBRARIES=/tmp/cross/lib/libuv.so \ 672-DLWS_LIBUV_INCLUDE_DIRS=/tmp/cross/include \ 673-DLWS_ZLIB_LIBRARIES=/tmp/cross/lib/libz.so \ 674-DLWS_ZLIB_INCLUDE_DIRS=/tmp/cross/include 675``` 676 6773) `make && make install` 678 6794) `file /tmp/cross/lib/libwebsockets.so.11` 680``` 681/tmp/cross/lib/libwebsockets.so.11: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=81e59c6534f8e9629a9fc9065c6e955ce96ca690, with debug_info, not stripped 682``` 683 6845) `arm-linux-gnueabihf-objdump -p /tmp/cross/lib/libwebsockets.so.11 | grep NEEDED` Confirm that the lws library was linked against everything we expect (libm / libc are provided by your toolchain) 685``` 686 NEEDED libz.so.1 687 NEEDED libmbedcrypto.so.0 688 NEEDED libmbedtls.so.10 689 NEEDED libmbedx509.so.0 690 NEEDED libuv.so.1 691 NEEDED libm.so.6 692 NEEDED libc.so.6 693``` 694 695You will also find the lws test apps in `/tmp/cross/bin`... to run lws on the target you will need to copy the related things from /tmp/cross... all the .so from /tmp/cross/lib and anything from /tmp/cross/bin you want. 696 697@section mem Memory efficiency 698 699Embedded server-only configuration without extensions (ie, no compression 700on websocket connections), but with full v13 websocket features and http 701server, built on ARM Cortex-A9: 702 703Update at 8dac94d (2013-02-18) 704``` 705 $ ./configure --without-client --without-extensions --disable-debug --without-daemonize 706 707 Context Creation, 1024 fd limit[2]: 16720 (includes 12 bytes per fd) 708 Per-connection [3]: 72 bytes, +1328 during headers 709 710 .text .rodata .data .bss 711 11512 2784 288 4 712``` 713This shows the impact of the major configuration with/without options at 71413ba5bbc633ea962d46d using Ubuntu ARM on a PandaBoard ES. 715 716These are accounting for static allocations from the library elf, there are 717additional dynamic allocations via malloc. These are a bit old now but give 718the right idea for relative "expense" of features. 719 720Static allocations, ARM9 721 722| | .text | .rodata | .data | .bss | 723|--------------------------------|---------|---------|-------|------| 724| All (no without) | 35024 | 9940 | 336 | 4104 | 725| without client | 25684 | 7144 | 336 | 4104 | 726| without client, exts | 21652 | 6288 | 288 | 4104 | 727| without client, exts, debug[1] | 19756 | 3768 | 288 | 4104 | 728| without server | 30304 | 8160 | 336 | 4104 | 729| without server, exts | 25382 | 7204 | 288 | 4104 | 730| without server, exts, debug[1] | 23712 | 4256 | 288 | 4104 | 731 732[1] `--disable-debug` only removes messages below `lwsl_notice`. Since that is 733the default logging level the impact is not noticeable, error, warn and notice 734logs are all still there. 735 736[2] `1024` fd per process is the default limit (set by ulimit) in at least Fedora 737and Ubuntu. You can make significant savings tailoring this to actual expected 738peak fds, ie, at a limit of `20`, context creation allocation reduces to `4432 + 739240 = 4672`) 740 741[3] known header content is freed after connection establishment 742