blob: 3994c9cc0cb47fa98fc62cce90aa6b71b58e4a6c [file] [log] [blame]
Joakim Soderberg7df99082013-02-07 20:24:19 +08001Introduction
2------------
3Libwebsockets can be built using two different build systems
4autoconf or CMake. autoconf only works on Unix systems, or mingw/cygwin
5on Windows. CMake works differently and can generate platform specific
6project files for most popular IDEs and build systems.
7
8################################### Autoconf ###################################
9
Andy Green6c1f64e2013-01-20 11:28:06 +080010Building the library and test apps
11----------------------------------
12
13You need to regenerate the autotools and libtoolize stuff for your system
14
15$ ./autogen.sh
16
Andy Green16ab3182013-02-10 18:02:31 +080017Then,
Andy Greena2156aa2013-02-02 18:10:29 +080018
19------Fedora x86_64
Andy Green6c1f64e2013-01-20 11:28:06 +080020
21 ./configure --prefix=/usr --libdir=/usr/lib64 --enable-openssl
22
Andy Greena2156aa2013-02-02 18:10:29 +080023------Apple
24
25Christopher Baker reported that this is needed
Andy Green6c1f64e2013-01-20 11:28:06 +080026
27./configure CC="gcc -arch i386 -arch x86_64" CXX="g++ -arch i386 -arch
28x86_64" CPP="gcc -E" CXXCPP="g++ -E" --enable-nofork
29
Andy Greena2156aa2013-02-02 18:10:29 +080030------mingw
31
32I did the following to get working build, ping test is disabled when
33building this way
Andy Green6c1f64e2013-01-20 11:28:06 +080034
351) install mingw64_w32 compiler packages from Fedora
362) additionally install mingw64-zlib package
373) ./configure --prefix=/usr --enable-mingw --host=x86_64-w64-mingw32
384) make
39
Andy Greena2156aa2013-02-02 18:10:29 +080040------MIPS cross-build using OpenWRT
Andy Green6c1f64e2013-01-20 11:28:06 +080041
Andy Greena2156aa2013-02-02 18:10:29 +080042 ./configure --prefix=/usr --without-extensions --host mips-openwrt-linux
43
44I did not try building the extensions since they need cross-zlib, but it
45should also be workable.
46
47------Other uClibc
48
49you may need --enable-builtin-getifaddrs if your toolchain
50doesn't have it - openWRT uclibc has it so you don't need this option.
51
52------ARM cross-build
Andy Green5c81e802013-01-20 20:14:42 +080053
54./configure --prefix=/usr --host=arm-linux-gnueabi --without-client --without-extensions
55
56you can build cross with client and extensions perfectly well, but
57apart from the size shrink this has the nice characteristic that no
58non-toolchain libraries are needed to build it.
59
Andy Green6c1f64e2013-01-20 11:28:06 +080060
61otherwise if /usr/local/... and /usr/local/lib are OK then...
62
63$ ./configure
64$ make clean
65$ make && sudo make install
66$ libwebsockets-test-server
67
68should be enough to get a test server listening on port 7861.
69
70
71Configure script options
72------------------------
73
74There are several other possible configure options
75
Andy Green23c5f2e2013-02-06 15:43:00 +090076--enable-openssl Builds in the SSL support
77
78--with-cyassl Use cyassl instead of OpenSSL... you will need CyaSSL
79 to have been configured with --enable-opensslExtra
80\ when it was built.
81
Andy Green6c1f64e2013-01-20 11:28:06 +080082--enable-libcrypto by default libwebsockets uses its own
83 built-in md5 and sha-1 implementation for
84 simplicity. However the libcrypto ones
85 may be faster, and in a distro context it
86 may be highly desirable to use a common
87 library implementation for ease of security
88 upgrades. Give this configure option
89 to disable the built-in ones and force use
90 of the libcrypto (part of openssl) ones.
91
92--with-client-cert-dir=dir tells the client ssl support where to
93 look for trust certificates to validate
94 the remote certificate against.
95
96--enable-noping Don't try to build the ping test app
97 It needs some unixy environment that
98 may choke in other build contexts, this
99 lets you cleanly stop it being built
100
101--enable-builtin-getifaddrs if your libc lacks getifaddrs, you can build an
102 implementation into the library. By default your libc
103 one is used.
104
105--without-testapps Just build the library not the test apps
106
107--without-client Don't build the client part of the library nor the
108 test apps that need the client part. Useful to
109 minimize library footprint for embedded server-only
110 case
111
112--without-server Don't build the server part of the library nor the
113 test apps that need the server part. Useful to
114 minimize library footprint for embedded client-only
115 case
116
117--without-daemonize Don't build daemonize.c / lws_daemonize
118
119--disable-debug Remove all debug logging below lwsl_notice in severity
120 from the code -- it's not just defeated from logging
121 but removed from compilation
122
Andy Green3182ece2013-01-20 17:08:31 +0800123--without-extensions Remove all code and data around protocol extensions.
124 This reduces the code footprint considerably but
125 you will lose extension features like compression.
126 However that may be irrelevant for embedded use and
127 the code / data size / speed improvements may be
128 critical.
129
Andy Greend636e352013-01-29 12:36:17 +0800130--with-latency Builds the latency-tracking code into the library...
131 this slows your library down a bit but is very useful
132 to find the cause of unexpected latencies occurring
133 inside the library. See README.test-apps for more
134 info
135
Andy Green6c1f64e2013-01-20 11:28:06 +0800136
137Externally configurable important constants
138-------------------------------------------
139
140You can control these from configure by just setting them as commandline
141args throgh CFLAGS, eg
142
143./configure CFLAGS="-DLWS_MAX_ZLIB_CONN_BUFFER=8192"
144
145
146They all have reasonable defaults usable for all use-cases except resource-
147constrained, so you only need to take care about them if you want to tune them
148to the amount of memory available.
149
Andy Green16ab3182013-02-10 18:02:31 +0800150 - LWS_MAX_HEADER_LEN default 1024: allocated area to copy http headers that
151libwebsockets knows about into. You only need to think about increasing this
152if your application might have monster length URLs for example, or some other
153header that lws cares about will be abnormally large (headers it does not
154know about are skipped).
Andy Green6c1f64e2013-01-20 11:28:06 +0800155
Andy Green16ab3182013-02-10 18:02:31 +0800156 - LWS_MAX_PROTOCOLS default 5: largest amount of different protocols the
Andy Green6c1f64e2013-01-20 11:28:06 +0800157server can serve
158
Andy Green16ab3182013-02-10 18:02:31 +0800159 - LWS_MAX_EXTENSIONS_ACTIVE default 3: largest amount of extensions we can
Andy Green6c1f64e2013-01-20 11:28:06 +0800160choose to have active on one connection
161
162 - SPEC_LATEST_SUPPORTED default 13: only change if you want to remove support
163for later protocol versions... unlikely
164
165 - AWAITING_TIMEOUT default 5: after this many seconds without a response, the
166server will hang up on the client
167
Andy Green6c1f64e2013-01-20 11:28:06 +0800168 - SYSTEM_RANDOM_FILEPATH default "/dev/urandom": if your random device differs
169you can set it here
170
171 - LWS_MAX_ZLIB_CONN_BUFFER maximum size a compression buffer is allowed to
172grow to before closing the connection. Some limit is needed or any connecton
173can exhaust all server memory by sending it 4G buffers full of zeros which the
174server is expect to expand atomically. Default is 64KBytes.
175
176 - LWS_SOMAXCONN maximum number of pending connect requests the listening
177socket can cope with. Default is SOMAXCONN. If you need to use synthetic
178tests that just spam hundreds of connect requests at once without dropping
179any, you can try messing with these as well as ulimit (see later)
180(courtesy Edwin van der Oetelaar)
181
182echo "2048 64512" > /proc/sys/net/ipv4/ip_local_port_range
183echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle
184echo "1" > /proc/sys/net/ipv4/tcp_tw_reuse
185echo "10" > /proc/sys/net/ipv4/tcp_fin_timeout
186echo "65536" > /proc/sys/net/core/somaxconn
187echo "65536" > /proc/sys/net/ipv4/tcp_max_syn_backlog
188echo "262144" > /proc/sys/net/netfilter/nf_conntrack_max
189
Andy Green5c81e802013-01-20 20:14:42 +0800190
191Memory efficiency
192-----------------
193
Andy Greenab40eaa2013-01-21 13:20:33 +0800194Embedded server-only configuration without extensions (ie, no compression
195on websocket connections), but with full v13 websocket features and http
196server, built on ARM Cortex-A9:
197
Andy Greencb8febd2013-02-18 12:08:15 +0800198Update at 8dac94d (2013-02-18)
Andy Green72dfd752013-02-11 22:40:39 +0800199
200./configure --without-client --without-extensions --disable-debug --without-daemonize
201
Andy Greencb8febd2013-02-18 12:08:15 +0800202Context Creation, 1024 fd limit[2]: 16720 (includes 12 bytes per fd)
203Per-connection [3]: 72 bytes, +1328 during headers
Andy Green72dfd752013-02-11 22:40:39 +0800204
205.text .rodata .data .bss
Andy Greencb8febd2013-02-18 12:08:15 +080020611512 2784 288 4
Andy Greenab40eaa2013-01-21 13:20:33 +0800207
Andy Green5c81e802013-01-20 20:14:42 +0800208This shows the impact of the major configuration with/without options at
20913ba5bbc633ea962d46d using Ubuntu ARM on a PandaBoard ES.
210
211These are accounting for static allocations from the library elf, there are
Andy Greencb8febd2013-02-18 12:08:15 +0800212additional dynamic allocations via malloc. These are a bit old now but give
213the right idea for relative "expense" of features.
Andy Green5c81e802013-01-20 20:14:42 +0800214
215Static allocations, ARM9
216 .text .rodata .data .bss
217 All (no without) 35024 9940 336 4104
218 without client 25684 7144 336 4104
219 without client, exts 21652 6288 288 4104
220 without client, exts, debug[1] 19756 3768 288 4104
221 without server 30304 8160 336 4104
222 without server, exts 25382 7204 288 4104
223 without server, exts, debug[1] 23712 4256 288 4104
224
Andy Green5c81e802013-01-20 20:14:42 +0800225[1] --disable-debug only removes messages below lwsl_notice. Since that is
226the default logging level the impact is not noticable, error, warn and notice
227logs are all still there.
228
229[2] 1024 fd per process is the default limit (set by ulimit) in at least Fedora
Andy Greencb8febd2013-02-18 12:08:15 +0800230and Ubuntu. You can make significant savings tailoring this to actual expected
231peak fds, ie, at a limit of 20, context creation allocation reduces to 4432 +
232240 = 4672)
Andy Green5c81e802013-01-20 20:14:42 +0800233
Andy Greencb8febd2013-02-18 12:08:15 +0800234[3] known header content is freed after connection establishment
Joakim Soderberg7df99082013-02-07 20:24:19 +0800235
236
237#################################### CMake ####################################
238
239CMake is a multi-platform build tool that can generate build files for many
240different target platforms. See more info at http://www.cmake.org
241
242CMake also allows/recommends you to do "out of source"-builds, that is,
243the build files are separated from your sources, so there is no need to
244create elaborate clean scripts to get a clean source tree, instead you
245simply remove your build directory.
246
247Libwebsockets has been tested to build successfully on the following platforms
248with SSL support (both OpenSSL/CyaSSL):
249
250- Windows
251- Linux (x86 and ARM)
252- OSX
253- NetBSD
254
255Building the library and test apps
256----------------------------------
257
258The project settings used by CMake to generate the platform specific build
259files is called CMakeLists.txt. CMake then uses one of its "Generators" to
260output a Visual Studio project or Make file for instance. To see a list of
261the available generators for your platform, simply run the "cmake" command.
262
263Note that by default OpenSSL will be linked, if you don't want SSL support
264see below on how to toggle compile options.
265
266Building on Unix:
267-----------------
268
2691. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
270 (Most Unix distributions comes with a packaged version also)
271
2722. Install OpenSSL.
273
2743. Generate the build files (default is Make files):
275
276 cd /path/to/src
277 mkdir build
278 cd build
279 cmake ..
280
281 (NOTE: The build/ directory can have any name and be located anywhere
282 on your filesystem, and that the argument ".." given to cmake is simply
283 the source directory of libwebsockets containing the CMakeLists.txt project
284 file. All examples in this file assumes you use "..")
285
Andy Green975423c2013-02-26 11:58:45 +0800286 NOTE2
Andy Green799ecbf2013-02-19 10:26:39 +0800287 A common option you may want to give is to set the install path, same
288 as --prefix= with autotools. It defaults to /usr/local.
289 You can do this by, eg
290
291 cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr
292
Andy Green975423c2013-02-26 11:58:45 +0800293 NOTE3
294 On machines that want libraries in lib64, you can also add the
295 following to the cmake line
296
297 -DLIB_SUFFIX=64
298
Joakim Soderberg7df99082013-02-07 20:24:19 +08002994. Finally you can build using the generated Makefile:
300
301 make
302
303Building on Windows (Visual Studio)
304-----------------------------------
3051. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
306
3072. Install OpenSSL binaries. http://www.openssl.org/related/binaries.html
308 (Preferably in the default location to make it easier for CMake to find them)
309
3103. Generate the Visual studio project by opening the Visual Studio cmd prompt:
311
312 cd <path to src>
313 md build
314 cd build
315 cmake -G "Visual Studio 10" ..
316
317 (NOTE: There is also a cmake-gui available on Windows if you prefer that)
318
3194. Now you should have a generated Visual Studio Solution in your
320 <path to src>/build directory, which can be used to build.
321
322Setting compile options
323-----------------------
324
325To set compile time flags you can either use one of the CMake gui applications
326or do it via command line.
327
328Command line
329------------
330To list avaialable options (ommit the H if you don't want the help text):
331
332 cmake -LH ..
333
334Then to set an option and build (for example turn off SSL support):
335
336 cmake -DWITH_SSL=0 ..
337or
338 cmake -DWITH_SSL:BOOL=OFF ..
339
340Unix GUI
341--------
342If you have a curses enabled build you simply type:
343(not all packages include this, my debian install does not for example).
344
345 ccmake
346
347Windows GUI
348-----------
349On windows CMake comes with a gui application:
350 Start -> Programs -> CMake -> CMake (cmake-gui)
351
352CyaSSL replacement for OpenSSL
353------------------------------
354CyaSSL is a lightweight SSL library targeted at embedded system:
355http://www.yassl.com/yaSSL/Products-cyassl.html
356
357It contains a OpenSSL compatability layer which makes it possible to pretty
358much link to it instead of OpenSSL, giving a much smaller footprint.
359
360NOTE: At the time of writing this the current release of CyaSSL contains a
361crash bug due to some APIs libwebsocket uses. To be able to use this you will
362need to use the current HEAD in their official repository:
363 https://github.com/cyassl/cyassl
364
365NOTE: cyassl needs to be compiled using the --enable-opensslExtra flag for
366this to work.
367
368Compiling libwebsockets with CyaSSL
369-----------------------------------
370
371cmake -DUSE_CYASSL=1
372 -DCYASSL_INCLUDE_DIRS=/path/to/cyassl
373 -DCYASSL_LIB=/path/to/cyassl/cyassl.a ..
374
375NOTE: On windows use the .lib file extension for CYASSL_LIB instead.
376
377Cross compiling
378---------------
379To enable cross compiling libwebsockets using CMake you need to create
380a "Toolchain file" that you supply to CMake when generating your build files.
381CMake will then use the cross compilers and build paths specified in this file
382to look for dependencies and such.
383
384Below is an example of how one of these files might look like:
385
386 #
387 # CMake Toolchain file for crosscompiling on ARM.
388 #
389 # This can be used when running cmake in the following way:
390 # cd build/
391 # cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/this/file/TC_arm-linux-gcc.cmake
392 #
393
394 set(CROSS_PATH /path/to/cross_environment/uClibc)
395
396 # Target operating system name.
397 set(CMAKE_SYSTEM_NAME Linux)
398
399 # Name of C compiler.
400 set(CMAKE_C_COMPILER "${CROSS_PATH}/bin/arm-linux-uclibc-gcc")
401 set(CMAKE_CXX_COMPILER "${CROSS_PATH}/bin/arm-linux-uclibc-g++")
402
403 # Where to look for the target environment. (More paths can be added here)
404 set(CMAKE_FIND_ROOT_PATH "${CROSS_PATH}")
405
406 # Adjust the default behavior of the FIND_XXX() commands:
407 # search programs in the host environment only.
408 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
409
410 # Search headers and libraries in the target environment only.
411 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
412 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
413
414Additional information on cross compilation with CMake:
415 http://www.vtk.org/Wiki/CMake_Cross_Compiling