]> git.ipfire.org Git - thirdparty/snort3.git/blob - configure_cmake.sh
Merge pull request #1044 in SNORT/snort3 from catch-update to master
[thirdparty/snort3.git] / configure_cmake.sh
1 #!/bin/sh
2 # Convenience wrapper for easily viewing/setting options that
3 # the project's CMake scripts will recognize
4 set -e
5 command="$0 $*"
6
7 # check for `cmake` command
8 type cmake > /dev/null 2>&1 || {
9 echo "\
10 This package requires CMake, please install it first, then you may
11 use this configure script to access CMake equivalent functionality.\
12 " >&2;
13 exit 1;
14 }
15
16 usage="\
17 Usage: $0 [OPTION]... [VAR=VALUE]...
18
19 --builddir= The build directory
20 --generator= run cmake --help for a list of generators
21 --prefix= Snort++ installation prefix
22
23 Optional Features:
24 --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
25 --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
26 --enable-code-coverage Whether to enable code coverage support
27 --enable-hardened-build Detect and use compile-time hardening options
28 --enable-pie Attempt to produce a position-independent executable
29 --disable-safec do not use libsafec bounds checking even if available
30 --disable-static-ips-actions
31 do not include ips actions in binary
32 --disable-static-inspectors
33 do not include inspectors in binary
34 --disable-static-loggers
35 do not include loggers in binary
36 --disable-static-ips-options
37 do not include ips options in binary
38 --disable-static-search-engines
39 do not include search engines in binary
40 --disable-static-codecs do not include codecs in binary
41 --enable-shell enable command line shell support
42 --enable-large-pcap enable support for pcaps larger than 2 GB
43 --disable-stdlog do not prefer file descriptor 3 over stdout for alerts
44 --enable-tsc-clock use timestamp counter register clock (x86 only)
45 --enable-debug-msgs enable debug printing options (bugreports and
46 developers only)
47 --enable-debug enable debugging options (bugreports and developers
48 only)
49 --enable-gdb enable gdb debugging information
50 --enable-gprof-profile enable gprof profiling options (developers only)
51 --disable-corefiles prevent Snort from generating core files
52 --enable-address-sanitizer
53 enable address sanitizer support
54 --enable-thread-sanitizer
55 enable thread sanitizer support
56 --enable-unit-tests build unit tests
57 --enable-piglet build piglet test harness
58 --disable-static-daq link static DAQ modules
59 --disable-html-docs don't create the HTML documentation
60 --disable-pdf-docs don't create the PDF documentation
61
62 Optional Packages:
63 --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
64 --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
65 --with-pcap-includes=DIR
66 libpcap include directory
67 --with-pcap-libraries=DIR
68 libpcap library directory
69 --with-luajit-includes=DIR
70 luajit include directory
71 --with-luajit-libraries=DIR
72 luajit library directory
73 --with-pcre-includes=DIR
74 libpcre include directory
75 --with-pcre-libraries=DIR
76 libpcre library directory
77 --with-dnet-includes=DIR
78 libdnet include directory
79 --with-dnet-libraries=DIR
80 libdnet library directory
81 --with-daq-includes=DIR DAQ include directory
82 --with-daq-libraries=DIR
83 DAQ library directory
84 --with-openssl=DIR openssl installation root directory
85 --with-hyperscan-includes=DIR
86 libhs include directory
87 --with-hyperscan-libraries=DIR
88 libhs library directory
89 --with-flatbuffers-includes=DIR
90 flatbuffers include directory
91 --with-flatbuffers-libraries=DIR
92 flatbuffers library directory
93
94 Some influential environment variables:
95 SIGNAL_SNORT_RELOAD=<value>
96 set the SIGNAL_SNORT_RELOAD value
97 SIGNAL_SNORT_DUMP_STATS<value>
98 set the SIGNAL_SNORT_DUMP_STATS value
99 SIGNAL_SNORT_ROTATE_STATS<value>
100 set the SIGNAL_SNORT_ROTATE_STATS value
101 SIGNAL_SNORT_READ_ATTR_TBL<value>
102 set the SIGNAL_SNORT_READ_ATTR_TBL value
103 "
104
105 sourcedir="$( cd "$( dirname "$0" )" && pwd )"
106
107 # Function to append a CMake cache entry definition to the
108 # CMakeCacheEntries variable
109 # $1 is the cache entry variable name
110 # $2 is the cache entry variable type
111 # $3 is the cache entry variable value
112 append_cache_entry () {
113 CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3"
114 }
115
116 check_and_append_cache_entry() {
117 if [ -f $3 ]; then
118 append_cache_entry $1 $2 $3
119 else
120 echo ""
121 echo "the $1 variable, which is specified using a --with-* options,"
122 echo "requires an absolute path to the library. Could not stat the"
123 echo "the library:"
124 echo " $3"
125 echo ""
126 exit 1
127 fi
128 }
129
130 # set defaults
131 builddir=build
132 prefix=/usr/local/snort
133 CMakeCacheEntries=""
134 append_cache_entry CMAKE_INSTALL_PREFIX PATH $prefix
135
136
137 # parse arguments
138 while [ $# -ne 0 ]; do
139 case "$1" in
140 -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
141 *) optarg= ;;
142 esac
143
144 case "$1" in
145 --help|-h)
146 echo "${usage}" 1>&2
147 exit 1
148 ;;
149 --builddir=*)
150 builddir=$optarg
151 ;;
152 --generator=*)
153 CMakeGenerator="$optarg"
154 ;;
155 --prefix=*)
156 prefix=$optarg
157 append_cache_entry CMAKE_INSTALL_PREFIX PATH $optarg
158 ;;
159 --enable-code-coverage)
160 append_cache_entry ENABLE_CODE_COVERAGE BOOL true
161 ;;
162 --disable-code-coverage)
163 append_cache_entry ENABLE_CODE_COVERAGE BOOL false
164 ;;
165 --enable-hardened-build)
166 append_cache_entry ENABLE_HARDENED_BUILD BOOL true
167 ;;
168 --disable-hardened-build)
169 append_cache_entry ENABLE_HARDENED_BUILD BOOL false
170 ;;
171 --enable-pie)
172 append_cache_entry ENABLE_PIE BOOL true
173 ;;
174 --disable-pie)
175 append_cache_entry ENABLE_PIE BOOL false
176 ;;
177 --disable-safec)
178 append_cache_entry ENABLE_SAFEC BOOL false
179 ;;
180 --enable-safec)
181 append_cache_entry ENABLE_SAFEC BOOL true
182 ;;
183 --disable-static-ips-actions)
184 append_cache_entry STATIC_IPS_ACTIONS BOOL false
185 ;;
186 --enable-static-ips-actions)
187 append_cache_entry STATIC_IPS_ACTIONS BOOL true
188 ;;
189 --disable-static-inspectors)
190 append_cache_entry STATIC_INSPECTORS BOOL false
191 ;;
192 --enable-static-inspectors)
193 append_cache_entry STATIC_INSPECTORS BOOL true
194 ;;
195 --disable-static-loggers)
196 append_cache_entry STATIC_LOGGERS BOOL false
197 ;;
198 --enable-static-loggers)
199 append_cache_entry STATIC_LOGGERS BOOL true
200 ;;
201 --disable-static-ips-options)
202 append_cache_entry STATIC_IPS_OPTIONS BOOL false
203 ;;
204 --enable-static-ips-options)
205 append_cache_entry STATIC_IPS_OPTIONS BOOL true
206 ;;
207 --disable-static-search-engines)
208 append_cache_entry STATIC_SEARCH_ENGINES BOOL false
209 ;;
210 --enable-static-search-engines)
211 append_cache_entry STATIC_SEARCH_ENGINES BOOL true
212 ;;
213 --disable-static-codecs)
214 append_cache_entry STATIC_CODECS BOOL false
215 ;;
216 --enable-static-codecs)
217 append_cache_entry STATIC_CODECS BOOL true
218 ;;
219 --enable-shell)
220 append_cache_entry ENABLE_SHELL BOOL true
221 ;;
222 --disable-shell)
223 append_cache_entry ENABLE_SHELL BOOL false
224 ;;
225 --enable-large-pcap)
226 append_cache_entry ENABLE_LARGE_PCAP BOOL true
227 ;;
228 --disable-stdlog)
229 append_cache_entry ENABLE_STDLOG BOOL false
230 ;;
231 --enable-tsc-clock)
232 append_cache_entry ENABLE_TSC_CLOCK BOOL true
233 ;;
234 --disable-large-pcap)
235 append_cache_entry ENABLE_LARGE_PCAP BOOL false
236 ;;
237 --enable-debug-msgs)
238 append_cache_entry ENABLE_DEBUG_MSGS BOOL true
239 ;;
240 --disable-debug-msgs)
241 append_cache_entry ENABLE_DEBUG_MSGS BOOL false
242 ;;
243 --enable-debug)
244 append_cache_entry ENABLE_DEBUG BOOL true
245 ;;
246 --disable-debug)
247 append_cache_entry ENABLE_DEBUG BOOL false
248 ;;
249 --enable-gdb)
250 append_cache_entry ENABLE_GDB BOOL true
251 ;;
252 --disable-gdb)
253 append_cache_entry ENABLE_GDB BOOL false
254 ;;
255 --enable-gprof-profile)
256 append_cache_entry ENABLE_PROFILE BOOL true
257 ;;
258 --disable-gprof-profile)
259 append_cache_entry ENABLE_PROFILE BOOL false
260 ;;
261 --disable-corefiles)
262 append_cache_entry ENABLE_COREFILES BOOL false
263 ;;
264 --enable-corefiles)
265 append_cache_entry ENABLE_COREFILES BOOL true
266 ;;
267 --enable-address-sanitizer)
268 append_cache_entry ENABLE_ADDRESS_SANITIZER BOOL true
269 ;;
270 --disable-address-sanitizer)
271 append_cache_entry ENABLE_ADDRESS_SANITIZER BOOL false
272 ;;
273 --enable-thread-sanitizer)
274 append_cache_entry ENABLE_THREAD_SANITIZER BOOL true
275 ;;
276 --disable-thread-sanitizer)
277 append_cache_entry ENABLE_THREAD_SANITIZER BOOL false
278 ;;
279 --enable-unit-tests)
280 append_cache_entry ENABLE_UNIT_TESTS BOOL true
281 ;;
282 --disable-unit-tests)
283 append_cache_entry ENABLE_UNIT_TESTS BOOL false
284 ;;
285 --enable-piglet)
286 append_cache_entry ENABLE_PIGLET BOOL true
287 ;;
288 --disable-piglet)
289 append_cache_entry ENABLE_PIGLET BOOL false
290 ;;
291 --disable-static-daq)
292 append_cache_entry ENABLE_STATIC_DAQ BOOL false
293 ;;
294 --enable-static-daq)
295 append_cache_entry ENABLE_STATIC_DAQ BOOL true
296 ;;
297 --disable-html-docs)
298 append_cache_entry MAKE_HTML_DOC BOOL false
299 ;;
300 --enable-html-docs)
301 append_cache_entry MAKE_HTML_DOC BOOL true
302 ;;
303 --disable-pdf-docs)
304 append_cache_entry MAKE_PDF_DOC BOOL false
305 ;;
306 --enable-pdf-docs)
307 append_cache_entry MAKE_PDF_DOC BOOL true
308 ;;
309 --with-pcap-includes=*)
310 append_cache_entry PCAP_INCLUDE_DIR PATH $optarg
311 ;;
312 --with-pcap-libraries=*)
313 append_cache_entry PCAP_LIBRARIES_DIR PATH $optarg
314 ;;
315 --with-luajit-includes=*)
316 append_cache_entry LUAJIT_INCLUDE_DIR_HINT PATH $optarg
317 ;;
318 --with-luajit-libraries=*)
319 append_cache_entry LUAJIT_LIBRARIES_DIR_HINT PATH $optarg
320 ;;
321 --with-pcre-includes=*)
322 append_cache_entry PCRE_INCLUDE_DIR_HINT PATH $optarg
323 ;;
324 --with-pcre-libraries=*)
325 append_cache_entry PCRE_LIBRARIES_DIR_HINT PATH $optarg
326 ;;
327 --with-dnet-includes=*)
328 append_cache_entry DNET_INCLUDE_DIR_HINT PATH $optarg
329 ;;
330 --with-dnet-libraries=*)
331 append_cache_entry DNET_LIBRARIES_DIR_HINT PATH $optarg
332 ;;
333 --with-daq-includes=*)
334 append_cache_entry DAQ_INCLUDE_DIR_HINT PATH $optarg
335 ;;
336 --with-daq-libraries=*)
337 append_cache_entry DAQ_LIBRARIES_DIR_HINT PATH $optarg
338 ;;
339 --with-openssl=*)
340 append_cache_entry OPENSSL_ROOT_DIR PATH $optarg
341 ;;
342 --with-hyperscan-includes=*)
343 append_cache_entry HS_INCLUDE_DIR PATH $optarg
344 ;;
345 --with-hyperscan-libraries=*)
346 append_cache_entry HS_LIBRARIES_DIR PATH $optarg
347 ;;
348 --with-flatbuffers-includes=*)
349 append_cache_entry FLATBUFFERS_INCLUDE_DIR_HINT PATH $optarg
350 ;;
351 --with-flatbuffers-libraries=*)
352 append_cache_entry FLATBUFFERS_LIBRARIES_DIR_HINT PATH $optarg
353 ;;
354 SIGNAL_SNORT_RELOAD=*)
355 append_cache_entry SIGNAL_SNORT_RELOAD STRING $optarg
356 ;;
357 SIGNAL_SNORT_DUMP_STATS=*)
358 append_cache_entry SIGNAL_SNORT_DUMP_STATS STRING $optarg
359 ;;
360 SIGNAL_SNORT_ROTATE_STATS=*)
361 append_cache_entry SIGNAL_SNORT_ROTATE_STATS STRING $optarg
362 ;;
363 SIGNAL_SNORT_READ_ATTR_TBL=*)
364 append_cache_entry SIGNAL_SNORT_READ_ATTR_TBL STRING $optarg
365 ;;
366 *)
367 echo "Invalid option '$1'. Try $0 --help to see available options."
368 exit 1
369 ;;
370 esac
371 shift
372 done
373
374 if [ -d $builddir ]; then
375 # If build directory exists, check if it has a CMake cache
376 if [ -f $builddir/CMakeCache.txt ]; then
377 # If the CMake cache exists, delete it so that this configuration
378 # is not tainted by a previous one
379 rm -f $builddir/CMakeCache.txt
380 fi
381 else
382 # Create build directory
383 mkdir -p $builddir
384 fi
385
386 echo "Build Directory : $builddir"
387 echo "Source Directory: $sourcedir"
388 cd $builddir
389
390 gen=""
391 [ "$CMakeGenerator" ] && gen+=" -G $CMakeGenerator"
392
393 cmake $gen \
394 -DCMAKE_CXX_FLAGS:STRING="$CXXFLAGS $CPPFLAGS" \
395 -DCMAKE_C_FLAGS:STRING="$CFLAGS $CPPFLAGS" \
396 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
397 $CMakeCacheEntries $sourcedir
398
399 echo "# This is the command used to configure this build" > config.status
400 echo $command >> config.status
401 chmod u+x config.status
402