blob: 9c33e175be9fca1a177521810c8c471388144920 [file] [log] [blame]
Andy Green0097a992013-03-09 13:06:37 +08001Introduction to CMake
2---------------------
Joakim Soderberg7df99082013-02-07 20:24:19 +08003
4CMake is a multi-platform build tool that can generate build files for many
5different target platforms. See more info at http://www.cmake.org
6
7CMake also allows/recommends you to do "out of source"-builds, that is,
8the build files are separated from your sources, so there is no need to
9create elaborate clean scripts to get a clean source tree, instead you
10simply remove your build directory.
11
12Libwebsockets has been tested to build successfully on the following platforms
13with SSL support (both OpenSSL/CyaSSL):
14
15- Windows
16- Linux (x86 and ARM)
17- OSX
18- NetBSD
19
20Building the library and test apps
21----------------------------------
22
23The project settings used by CMake to generate the platform specific build
24files is called CMakeLists.txt. CMake then uses one of its "Generators" to
25output a Visual Studio project or Make file for instance. To see a list of
26the available generators for your platform, simply run the "cmake" command.
27
28Note that by default OpenSSL will be linked, if you don't want SSL support
29see below on how to toggle compile options.
30
31Building on Unix:
32-----------------
33
341. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
35 (Most Unix distributions comes with a packaged version also)
36
372. Install OpenSSL.
38
393. Generate the build files (default is Make files):
40
41 cd /path/to/src
42 mkdir build
43 cd build
44 cmake ..
45
46 (NOTE: The build/ directory can have any name and be located anywhere
47 on your filesystem, and that the argument ".." given to cmake is simply
Andy Green0097a992013-03-09 13:06:37 +080048 the source directory of libwebsockets containing the CMakeLists.txt
49 project file. All examples in this file assumes you use "..")
Joakim Soderberg7df99082013-02-07 20:24:19 +080050
Andy Green975423c2013-02-26 11:58:45 +080051 NOTE2
Andy Green799ecbf2013-02-19 10:26:39 +080052 A common option you may want to give is to set the install path, same
53 as --prefix= with autotools. It defaults to /usr/local.
54 You can do this by, eg
55
56 cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr
57
Andy Green975423c2013-02-26 11:58:45 +080058 NOTE3
59 On machines that want libraries in lib64, you can also add the
60 following to the cmake line
61
62 -DLIB_SUFFIX=64
63
Joakim Soderberg7df99082013-02-07 20:24:19 +0800644. Finally you can build using the generated Makefile:
65
66 make
67
Andy Green0651e502014-04-02 21:18:11 +080068
69Quirk of cmake
70--------------
71
72When changing cmake options, for some reason the only way to get it to see the
73changes sometimes is delete the contents of your build directory and do the
74cmake from scratch.
75
76
Joakim Soderberg7df99082013-02-07 20:24:19 +080077Building on Windows (Visual Studio)
78-----------------------------------
791. Install CMake 2.6 or greater: http://cmake.org/cmake/resources/software.html
80
812. Install OpenSSL binaries. http://www.openssl.org/related/binaries.html
82 (Preferably in the default location to make it easier for CMake to find them)
83
843. Generate the Visual studio project by opening the Visual Studio cmd prompt:
85
86 cd <path to src>
87 md build
88 cd build
89 cmake -G "Visual Studio 10" ..
90
91 (NOTE: There is also a cmake-gui available on Windows if you prefer that)
92
934. Now you should have a generated Visual Studio Solution in your
94 <path to src>/build directory, which can be used to build.
95
96Setting compile options
97-----------------------
98
99To set compile time flags you can either use one of the CMake gui applications
100or do it via command line.
101
102Command line
103------------
104To list avaialable options (ommit the H if you don't want the help text):
105
106 cmake -LH ..
107
108Then to set an option and build (for example turn off SSL support):
109
Andy Green1ea84e72014-02-21 18:45:45 +0800110 cmake -DLWS_WITH_SSL=0 ..
Joakim Soderberg7df99082013-02-07 20:24:19 +0800111or
Andy Green1ea84e72014-02-21 18:45:45 +0800112 cmake -DLWS_WITH_SSL:BOOL=OFF ..
Joakim Soderberg7df99082013-02-07 20:24:19 +0800113
114Unix GUI
115--------
116If you have a curses enabled build you simply type:
117(not all packages include this, my debian install does not for example).
118
119 ccmake
120
121Windows GUI
122-----------
123On windows CMake comes with a gui application:
124 Start -> Programs -> CMake -> CMake (cmake-gui)
125
126CyaSSL replacement for OpenSSL
127------------------------------
128CyaSSL is a lightweight SSL library targeted at embedded system:
129http://www.yassl.com/yaSSL/Products-cyassl.html
130
131It contains a OpenSSL compatability layer which makes it possible to pretty
132much link to it instead of OpenSSL, giving a much smaller footprint.
133
John Clark388dc7d2014-03-01 22:24:47 -0500134NOTE: cyassl needs to be compiled using the --enable-opensslextra flag for
Joakim Soderberg7df99082013-02-07 20:24:19 +0800135this to work.
136
137Compiling libwebsockets with CyaSSL
138-----------------------------------
139
John Clark388dc7d2014-03-01 22:24:47 -0500140cmake .. -DLWS_USE_CYASSL=1 \
141 -DLWS_CYASSL_INCLUDE_DIRS=/path/to/cyassl \
142 -DLWS_CYASSL_LIB=/path/to/cyassl/cyassl.a ..
Joakim Soderberg7df99082013-02-07 20:24:19 +0800143
John Clark388dc7d2014-03-01 22:24:47 -0500144NOTE: On windows use the .lib file extension for LWS_CYASSL_LIB instead.
Joakim Soderberg7df99082013-02-07 20:24:19 +0800145
146Cross compiling
147---------------
148To enable cross compiling libwebsockets using CMake you need to create
149a "Toolchain file" that you supply to CMake when generating your build files.
150CMake will then use the cross compilers and build paths specified in this file
151to look for dependencies and such.
152
Andy Green5b479ac2013-03-30 10:30:03 +0800153Libwebsockets includes an example toolchain file cross-arm-linux-gnueabihf.cmake
154you can use as a starting point.
Joakim Soderberg7df99082013-02-07 20:24:19 +0800155
Andy Green5b479ac2013-03-30 10:30:03 +0800156The commandline to configure for cross with this would look like
Joakim Soderberg7df99082013-02-07 20:24:19 +0800157
Andy Green5b479ac2013-03-30 10:30:03 +0800158cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr \
159 -DCMAKE_TOOLCHAIN_FILE=../cross-arm-linux-gnueabihf.cmake \
160 -DWITHOUT_EXTENSIONS=1 -DWITH_SSL=0
Joakim Soderberg7df99082013-02-07 20:24:19 +0800161
Andy Green5b479ac2013-03-30 10:30:03 +0800162The example shows how to build with no external cross lib dependencies, you
163need to proide the cross libraries otherwise.
Joakim Soderberg7df99082013-02-07 20:24:19 +0800164
Andy Green5b479ac2013-03-30 10:30:03 +0800165NOTE: start from an EMPTY build directory if you had a non-cross build in there
166 before the settings will be cached and your changes ignored.
Joakim Soderberg7df99082013-02-07 20:24:19 +0800167
168Additional information on cross compilation with CMake:
169 http://www.vtk.org/Wiki/CMake_Cross_Compiling
Andy Green0097a992013-03-09 13:06:37 +0800170
171
172Memory efficiency
173-----------------
174
175Embedded server-only configuration without extensions (ie, no compression
176on websocket connections), but with full v13 websocket features and http
177server, built on ARM Cortex-A9:
178
179Update at 8dac94d (2013-02-18)
180
181./configure --without-client --without-extensions --disable-debug --without-daemonize
182
183Context Creation, 1024 fd limit[2]: 16720 (includes 12 bytes per fd)
184Per-connection [3]: 72 bytes, +1328 during headers
185
186.text .rodata .data .bss
18711512 2784 288 4
188
189This shows the impact of the major configuration with/without options at
19013ba5bbc633ea962d46d using Ubuntu ARM on a PandaBoard ES.
191
192These are accounting for static allocations from the library elf, there are
193additional dynamic allocations via malloc. These are a bit old now but give
194the right idea for relative "expense" of features.
195
196Static allocations, ARM9
197 .text .rodata .data .bss
198 All (no without) 35024 9940 336 4104
199 without client 25684 7144 336 4104
200 without client, exts 21652 6288 288 4104
201 without client, exts, debug[1] 19756 3768 288 4104
202 without server 30304 8160 336 4104
203 without server, exts 25382 7204 288 4104
204 without server, exts, debug[1] 23712 4256 288 4104
205
206[1] --disable-debug only removes messages below lwsl_notice. Since that is
207the default logging level the impact is not noticable, error, warn and notice
208logs are all still there.
209
210[2] 1024 fd per process is the default limit (set by ulimit) in at least Fedora
211and Ubuntu. You can make significant savings tailoring this to actual expected
212peak fds, ie, at a limit of 20, context creation allocation reduces to 4432 +
213240 = 4672)
214
215[3] known header content is freed after connection establishment
216
217
218