]> granicus.if.org Git - libevent/blob - Documentation/Building.md
doc: add build prerequisites
[libevent] / Documentation / Building.md
1 # Building and installing Libevent
2
3 ### Jump to:
4
5 - [Prerequisites](#Prerequisites)
6 - [Autoconf](#autoconf)
7   - [Flags](#autoconf-flags)
8 - [Building on Windows](#building-on-windows)
9 - [Building on Unix (With CMake)](#building-on-unix-cmake)
10 - [CMake Variables](#cmake-variables)
11
12 ## Prerequisites
13
14 ### Linux deb-like (ubuntu/debian/...)
15
16 Just install tools using your preferred package manager if you build using autotools:
17
18 ```sh
19 sudo apt-get install automake autoconf libtool pkg-config
20 ```
21
22 or build using cmake:
23
24 ```sh
25 sudo apt-get install cmake
26 ```
27
28 Doxygen is a tool for generating documentation. Git is used to fetch the package version.
29 Install them if needed:
30
31 ```
32 sudo apt-get install doxygen git
33 ```
34
35 libevent has encryption layer, you need openssl or mbedTLS for it, you can
36 install one of this using:
37
38 ```sh
39 sudo apt-get install libssl-dev libmbedtls-dev
40 ```
41
42 To support multithreaded environments, libpthread is a must, and it already exists in the system.
43
44 To run the tests, you should install zlib:
45
46 ```sh
47 sudo apt-get install zlib1g-dev
48 ```
49
50 Finally, python interpreter should be installed if you want to run regression tests.
51
52 ### MacOS
53
54 On MacOS you can use `brew` to manage packages.
55
56 The installation process on MacOS is roughly the same as on Linux,
57 the difference is installation of openssl and zlib:
58
59 ```sh
60 brew install openssl zlib
61 ```
62
63 ### Windows
64
65 To install it, there are two choices: installer and zip file.
66
67 If using zip file, you should set the PATH variable in the Environment
68 Variables for your User to include the installation path of cmake.
69
70 Install Visual Studio which is the true compiler that will be used.
71
72 Install OpenSSL to support for encryption, then add the installation path into the PATH variable in the Environment Variables,
73 or set OPENSSL_ROOT_DIR in command prompt:
74
75 ```sh
76 set "OPENSSL_ROOT_DIR=C:\path\to\OpenSSL"
77 ```
78
79 or add `OPENSSL_ROOT_DIR` definition to the cmake command:
80
81 ```sh
82 cmake -DOPENSSL_ROOT_DIR=C:/path/to/OpenSSL ...
83 ```
84
85 ## Autoconf
86
87 ```
88 $ ./configure
89 $ make
90 ```
91
92 **Note: If you had downloaded libevent from the Git repository, then you have to run `./autogen.sh` first!**
93
94 You can run the regression tests by running
95 ```
96 $ make verify
97 ```
98 *Before reporting any problems, please run the regression tests.*
99
100 Install as root via
101 ```
102 $ make install
103 ```
104
105 To enable low-level tracing, build the library as:
106 ```
107 $ CFLAGS=-DUSE_DEBUG ./configure [...]
108 ```
109
110 ### Autoconf flags
111
112 Standard configure flags should work. In particular, see:
113 ```
114  --disable-shared          Only build static libraries.
115  --prefix                  Install all files relative to this directory.
116 ```
117
118 The configure script also supports the following flags:
119 ```
120  --enable-gcc-warnings     Enable extra compiler checking with GCC.
121  --disable-malloc-replacement
122                            Don't let applications replace our memory
123                            management functions.
124  --disable-openssl         Disable support for OpenSSL encryption.
125  --disable-thread-support  Don't support multithreaded environments.
126  --enable-doxygen-doc      Build doxygen documentation
127 ```
128
129 ## Building on Windows
130 __Download CMake for Windows [here](https://cmake.org/download/)__
131 ```
132 > md build && cd build
133 > cmake -G "Visual Studio 10" ..   # Or use any generator you want to use. Run cmake --help for a list
134 > cmake --build . --config Release # Or "start libevent.sln" and build with menu in Visual Studio.
135 ```
136 In the above, the ".." refers to the dir containing the Libevent source code. You can build multiple versions (with different compile time settings) from the same source tree by creating other build directories.
137
138 It is highly recommended to build "out of source" when using CMake instead of "in source" like the normal behaviour of autoconf for this reason.
139
140 The "NMake Makefiles" CMake generator can be used to build entirely via the command line:
141 ```
142 > cmake -LH ..
143 ```
144
145 ## Building on Unix (CMake)
146 __Install Cmake with your distribution's package manager `apt-get`/`dnf`/etc__
147 ```
148 $ mkdir build && cd build
149 $ cmake .. # Default to Unix Makefiles
150 $ make
151 $ make verify # Optional
152 ```
153
154 ## CMake Variables
155 General options:
156 ```
157 # Type of the library to build (SHARED or STATIC)
158 # Default is: SHARED for MSVC, otherwise BOTH
159 EVENT__LIBRARY_TYPE:STRING=DEFAULT
160
161 # Installation directory for CMake files
162 EVENT_INSTALL_CMAKE_DIR:PATH=lib/cmake/libevent
163
164 # Enable running gcov to get a test coverage report (only works with
165 # GCC/CLang). Make sure to enable -DCMAKE_BUILD_TYPE=Debug as well.
166 EVENT__COVERAGE:BOOL=OFF
167
168 # Defines if Libevent should build without the benchmark executables
169 EVENT__DISABLE_BENCHMARK:BOOL=OFF
170
171 # Define if Libevent should build without support for a debug mode
172 EVENT__DISABLE_DEBUG_MODE:BOOL=OFF
173
174 # Define if Libevent should not allow replacing the mm functions
175 EVENT__DISABLE_MM_REPLACEMENT:BOOL=OFF
176
177 # Define if Libevent should build without support for OpenSSL encryption
178 EVENT__DISABLE_OPENSSL:BOOL=OFF
179
180 # Disable the regress tests
181 EVENT__DISABLE_REGRESS:BOOL=OFF
182
183 # Disable sample files
184 EVENT__DISABLE_SAMPLES:BOOL=OFF
185
186 # If tests should be compiled or not
187 EVENT__DISABLE_TESTS:BOOL=OFF
188
189 # Define if Libevent should not be compiled with thread support
190 EVENT__DISABLE_THREAD_SUPPORT:BOOL=OFF
191
192 # Enables verbose debugging
193 EVENT__ENABLE_VERBOSE_DEBUG:BOOL=OFF
194
195 # When cross compiling, forces running a test program that verifies that Kqueue
196 # works with pipes. Note that this requires you to manually run the test program
197 # on the the cross compilation target to verify that it works. See CMake
198 # documentation for try_run for more details
199 EVENT__FORCE_KQUEUE_CHECK:BOOL=OFF
200
201 # Build documentation with doxygen
202 EVENT__DOXYGEN:BOOL=OFF
203 ```
204 MSVC specific options:
205 ```
206 # Link static runtime libraries.
207 # Defaults to ON if EVENT_LIBRARY_TYPE is equal to "STATIC", otherwise OFF
208 EVENT__MSVC_STATIC_RUNTIME:BOOL
209 ```
210 GNUC specific options:
211 ```
212 # Disable verbose warnings with GCC
213 EVENT__DISABLE_GCC_WARNINGS:BOOL=OFF
214
215 # Enable compiler security checks
216 EVENT__ENABLE_GCC_HARDENING:BOOL=OFF
217
218 # Enable gcc function sections
219 EVENT__ENABLE_GCC_FUNCTION_SECTIONS:BOOL=OFF
220
221 # Make all GCC warnings into errors
222 EVENT__ENABLE_GCC_WARNINGS:BOOL=OFF
223 ```
224 __More variables can be found by running `cmake -LAH <sourcedir_path>`__
225
226 [Back to top &uarr;](#jump-to)