configure_cmake.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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. # check for `cmake` command
  7. type cmake > /dev/null 2>&1 || {
  8. echo "\
  9. This package requires CMake, please install it first, then you may
  10. use this configure script to access CMake equivalent functionality.\
  11. " >&2;
  12. exit 1;
  13. }
  14. usage="\
  15. Usage: $0 [OPTION]... [VAR=VALUE]...
  16. --builddir= The build directory
  17. --generator= run cmake --help for a list of generators
  18. --prefix= Snort++ installation prefix
  19. Optional Features:
  20. --build-type=[Debug|Release|RelWithDebInfo|MinSizeRel]
  21. set cmake build type (defaults to RelWithDebInfo if neither
  22. CFLAGS nor CXXFLAGS are set)
  23. --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
  24. --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
  25. --enable-code-coverage Whether to enable code coverage support
  26. --enable-hardened-build Detect and use compile-time hardening options
  27. --enable-pie Attempt to produce a position-independent executable
  28. --disable-safec do not use libsafec bounds checking even if available
  29. --disable-static-ips-actions
  30. do not include ips actions in binary
  31. --disable-static-inspectors
  32. do not include inspectors in binary
  33. --disable-static-loggers
  34. do not include loggers in binary
  35. --disable-static-ips-options
  36. do not include ips options in binary
  37. --disable-static-search-engines
  38. do not include search engines in binary
  39. --disable-static-codecs do not include codecs in binary
  40. --enable-shell enable command line shell support
  41. --enable-large-pcap enable support for pcaps larger than 2 GB
  42. --enable-stdlog use file descriptor 3 instead of stdout for alerts
  43. --enable-tsc-clock use timestamp counter register clock (x86 and arm only)
  44. --enable-debug-msgs enable debug printing options (bugreports and
  45. developers only)
  46. --enable-debug enable debugging options (bugreports and developers
  47. only)
  48. --disable-gdb disable gdb debugging information
  49. --enable-gprof-profile enable gprof profiling options (developers only)
  50. --disable-snort-profiler
  51. disable snort performance profiling (cpu and memory) (developers only)
  52. --enable-memory-profiler
  53. enable memory profiler
  54. --enable-rule-profiler enable rule keyword profiler (developers only)
  55. --enable-deep-profiling enable deep (multi-level) profiling (developers only)
  56. --disable-corefiles prevent Snort from generating core files
  57. --enable-address-sanitizer
  58. enable address sanitizer support
  59. --enable-thread-sanitizer
  60. enable thread sanitizer support
  61. --enable-ub-sanitizer enable undefined behavior sanitizer support
  62. --enable-tcmalloc enable using tcmalloc for dynamic memory management
  63. --enable-jemalloc enable using jemalloc for dynamic memory management
  64. --enable-jemalloc-static
  65. same as --enable-jemalloc but linked statically
  66. --disable-tenant-id disable tenant ID in the FlowKey
  67. --enable-luajit-static enable luajit linked statically
  68. --enable-appid-third-party
  69. enable third party appid
  70. --enable-unit-tests build unit tests
  71. --enable-ccache enable ccache support
  72. --disable-static-daq link static DAQ modules
  73. --disable-html-docs don't create the HTML documentation
  74. --disable-pdf-docs don't create the PDF documentation
  75. --disable-text-docs don't create the TEXT documentation
  76. --disable-docs don't create documentation
  77. Optional Packages:
  78. --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
  79. --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
  80. --with-pcap-includes=DIR
  81. libpcap include directory
  82. --with-pcap-libraries=DIR
  83. libpcap library directory
  84. --with-luajit-includes=DIR
  85. luajit include directory
  86. --with-luajit-libraries=DIR
  87. luajit library directory
  88. --with-pcre-includes=DIR
  89. libpcre include directory
  90. --with-pcre-libraries=DIR
  91. libpcre library directory
  92. --with-dnet-includes=DIR
  93. libdnet include directory
  94. --with-dnet-libraries=DIR
  95. libdnet library directory
  96. --with-daq-includes=DIR DAQ include directory
  97. --with-daq-libraries=DIR
  98. DAQ library directory
  99. --with-openssl=DIR openssl installation root directory
  100. --with-hyperscan-includes=DIR
  101. libhs include directory
  102. --with-hyperscan-libraries=DIR
  103. libhs library directory
  104. --with-atomic-libraries=DIR
  105. atomic library directory
  106. --with-flex-prefix=DIR
  107. flex prefix directory
  108. --with-flex-includes=DIR
  109. flex include directory
  110. --with-iconv-includes=DIR
  111. libiconv include directory
  112. --with-iconv-libraries=DIR
  113. libiconv library directory
  114. --with-uuid-includes=DIR
  115. libuuid include directory
  116. --with-uuid-libraries=DIR
  117. libuuid library directory
  118. --with-libml-includes=DIR
  119. libml include directory
  120. --with-libml-libraries=DIR
  121. libml library directory
  122. --without-libml build Snort ML with mock of LibML
  123. Some influential variable definitions:
  124. SIGNAL_SNORT_RELOAD=<int>
  125. override the signal used to reload configuration (default: SIGHUP)
  126. SIGNAL_SNORT_DUMP_STATS=<int>
  127. override the signal used to dump run-time statistics (default: SIGUSR1)
  128. SIGNAL_SNORT_ROTATE_STATS=<int>
  129. override the signal used to force rotation of stats files (default: SIGUSR2)
  130. SIGNAL_SNORT_READ_ATTR_TBL=<int>
  131. override the signal used to reload the host attributes table (default: SIGURG)
  132. SNORT_BUILD_NUMBER=<int>
  133. define a build number for this build of Snort
  134. "
  135. sourcedir="$( cd "$( dirname "$0" )" && pwd )"
  136. # Function to append a CMake cache entry definition to the
  137. # CMakeCacheEntries variable
  138. # $1 is the cache entry variable name
  139. # $2 is the cache entry variable type
  140. # $3 is the cache entry variable value
  141. append_cache_entry () {
  142. CMakeCacheEntries="$CMakeCacheEntries -D $1:$2=$3"
  143. }
  144. # set defaults
  145. builddir=build
  146. prefix=/usr/local/snort
  147. CMakeCacheEntries=""
  148. append_cache_entry CMAKE_INSTALL_PREFIX PATH $prefix
  149. build_type=""
  150. [ -z "$CFLAGS" ] && [ -z "$CXXFLAGS" ] && build_type="RelWithDebInfo"
  151. # parse arguments
  152. while [ $# -ne 0 ]; do
  153. case "$1" in
  154. *=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  155. *) optarg= ;;
  156. esac
  157. case "$1" in
  158. --help|-h)
  159. echo "${usage}" 1>&2
  160. exit 1
  161. ;;
  162. --builddir=*)
  163. builddir=$optarg
  164. ;;
  165. --define=*)
  166. CMakeCacheEntries="$CMakeCacheEntries -D$optarg"
  167. ;;
  168. --generator=*)
  169. CMakeGenerator="$optarg"
  170. ;;
  171. --prefix=*)
  172. prefix=$optarg
  173. append_cache_entry CMAKE_INSTALL_PREFIX PATH $optarg
  174. ;;
  175. --enable-code-coverage)
  176. append_cache_entry ENABLE_CODE_COVERAGE BOOL true
  177. ;;
  178. --disable-code-coverage)
  179. append_cache_entry ENABLE_CODE_COVERAGE BOOL false
  180. ;;
  181. --enable-hardened-build)
  182. append_cache_entry ENABLE_HARDENED_BUILD BOOL true
  183. ;;
  184. --disable-hardened-build)
  185. append_cache_entry ENABLE_HARDENED_BUILD BOOL false
  186. ;;
  187. --enable-pie)
  188. append_cache_entry ENABLE_PIE BOOL true
  189. ;;
  190. --disable-pie)
  191. append_cache_entry ENABLE_PIE BOOL false
  192. ;;
  193. --disable-safec)
  194. append_cache_entry ENABLE_SAFEC BOOL false
  195. ;;
  196. --enable-safec)
  197. append_cache_entry ENABLE_SAFEC BOOL true
  198. ;;
  199. --disable-static-ips-actions)
  200. append_cache_entry STATIC_IPS_ACTIONS BOOL false
  201. ;;
  202. --enable-static-ips-actions)
  203. append_cache_entry STATIC_IPS_ACTIONS BOOL true
  204. ;;
  205. --disable-static-inspectors)
  206. append_cache_entry STATIC_INSPECTORS BOOL false
  207. ;;
  208. --enable-static-inspectors)
  209. append_cache_entry STATIC_INSPECTORS BOOL true
  210. ;;
  211. --disable-static-loggers)
  212. append_cache_entry STATIC_LOGGERS BOOL false
  213. ;;
  214. --enable-static-loggers)
  215. append_cache_entry STATIC_LOGGERS BOOL true
  216. ;;
  217. --disable-static-ips-options)
  218. append_cache_entry STATIC_IPS_OPTIONS BOOL false
  219. ;;
  220. --enable-static-ips-options)
  221. append_cache_entry STATIC_IPS_OPTIONS BOOL true
  222. ;;
  223. --disable-static-search-engines)
  224. append_cache_entry STATIC_SEARCH_ENGINES BOOL false
  225. ;;
  226. --enable-static-search-engines)
  227. append_cache_entry STATIC_SEARCH_ENGINES BOOL true
  228. ;;
  229. --disable-static-codecs)
  230. append_cache_entry STATIC_CODECS BOOL false
  231. ;;
  232. --enable-static-codecs)
  233. append_cache_entry STATIC_CODECS BOOL true
  234. ;;
  235. --enable-shell)
  236. append_cache_entry ENABLE_SHELL BOOL true
  237. ;;
  238. --disable-shell)
  239. append_cache_entry ENABLE_SHELL BOOL false
  240. ;;
  241. --enable-large-pcap)
  242. append_cache_entry ENABLE_LARGE_PCAP BOOL true
  243. ;;
  244. --enable-stdlog)
  245. append_cache_entry ENABLE_STDLOG BOOL true
  246. ;;
  247. --enable-tsc-clock)
  248. append_cache_entry ENABLE_TSC_CLOCK BOOL true
  249. ;;
  250. --disable-snort-profiler)
  251. append_cache_entry DISABLE_SNORT_PROFILER BOOL false
  252. ;;
  253. --enable-memory-profiler)
  254. append_cache_entry ENABLE_MEMORY_PROFILER BOOL true
  255. ;;
  256. --enable-rule-profiler)
  257. append_cache_entry ENABLE_RULE_PROFILER BOOL true
  258. ;;
  259. --enable-deep-profiling)
  260. append_cache_entry DEEP_PROFILING BOOL true
  261. ;;
  262. --disable-large-pcap)
  263. append_cache_entry ENABLE_LARGE_PCAP BOOL false
  264. ;;
  265. --enable-debug-msgs)
  266. append_cache_entry ENABLE_DEBUG_MSGS BOOL true
  267. ;;
  268. --disable-debug-msgs)
  269. append_cache_entry ENABLE_DEBUG_MSGS BOOL false
  270. ;;
  271. --enable-debug)
  272. append_cache_entry ENABLE_DEBUG BOOL true
  273. ;;
  274. --disable-debug)
  275. append_cache_entry ENABLE_DEBUG BOOL false
  276. ;;
  277. --enable-gdb)
  278. append_cache_entry ENABLE_GDB BOOL true
  279. ;;
  280. --disable-gdb)
  281. append_cache_entry ENABLE_GDB BOOL false
  282. ;;
  283. --enable-gprof-profile)
  284. append_cache_entry ENABLE_PROFILE BOOL true
  285. ;;
  286. --disable-gprof-profile)
  287. append_cache_entry ENABLE_PROFILE BOOL false
  288. ;;
  289. --disable-corefiles)
  290. append_cache_entry ENABLE_COREFILES BOOL false
  291. ;;
  292. --enable-corefiles)
  293. append_cache_entry ENABLE_COREFILES BOOL true
  294. ;;
  295. --enable-address-sanitizer)
  296. append_cache_entry ENABLE_ADDRESS_SANITIZER BOOL true
  297. ;;
  298. --disable-address-sanitizer)
  299. append_cache_entry ENABLE_ADDRESS_SANITIZER BOOL false
  300. ;;
  301. --enable-thread-sanitizer)
  302. append_cache_entry ENABLE_THREAD_SANITIZER BOOL true
  303. ;;
  304. --disable-thread-sanitizer)
  305. append_cache_entry ENABLE_THREAD_SANITIZER BOOL false
  306. ;;
  307. --enable-ub-sanitizer)
  308. append_cache_entry ENABLE_UB_SANITIZER BOOL true
  309. ;;
  310. --disable-ub-sanitizer)
  311. append_cache_entry ENABLE_UB_SANITIZER BOOL false
  312. ;;
  313. --enable-tcmalloc)
  314. append_cache_entry ENABLE_TCMALLOC BOOL true
  315. tcm=1
  316. ;;
  317. --disable-tcmalloc)
  318. append_cache_entry ENABLE_TCMALLOC BOOL false
  319. ;;
  320. --enable-jemalloc)
  321. append_cache_entry ENABLE_JEMALLOC BOOL true
  322. append_cache_entry STATIC_JEMALLOC BOOL false
  323. jem=1
  324. ;;
  325. --disable-jemalloc)
  326. append_cache_entry ENABLE_JEMALLOC BOOL false
  327. ;;
  328. --enable-jemalloc-static)
  329. append_cache_entry ENABLE_JEMALLOC BOOL true
  330. append_cache_entry STATIC_JEMALLOC BOOL true
  331. ;;
  332. --enable-luajit-static)
  333. append_cache_entry STATIC_LUAJIT BOOL true
  334. ;;
  335. --disable-jemalloc-static)
  336. append_cache_entry ENABLE_JEMALLOC BOOL false
  337. ;;
  338. --disable-tenant-id)
  339. append_cache_entry DISABLE_TENANT_ID BOOL true
  340. ;;
  341. --enable-appid-third-party)
  342. ;;
  343. --enable-unit-tests)
  344. append_cache_entry ENABLE_UNIT_TESTS BOOL true
  345. ;;
  346. --disable-unit-tests)
  347. append_cache_entry ENABLE_UNIT_TESTS BOOL false
  348. ;;
  349. --enable-benchmark-tests)
  350. append_cache_entry ENABLE_BENCHMARK_TESTS BOOL true
  351. ;;
  352. --disable-benchmark-tests)
  353. append_cache_entry ENABLE_BENCHMARK_TESTS BOOL false
  354. ;;
  355. --enable-ccache)
  356. append_cache_entry CMAKE_CXX_COMPILER_LAUNCHER STRING ccache
  357. append_cache_entry CMAKE_C_COMPILER_LAUNCHER STRING ccache
  358. ;;
  359. --disable-static-daq)
  360. append_cache_entry ENABLE_STATIC_DAQ BOOL false
  361. ;;
  362. --enable-static-daq)
  363. append_cache_entry ENABLE_STATIC_DAQ BOOL true
  364. ;;
  365. --disable-html-docs)
  366. append_cache_entry MAKE_HTML_DOC BOOL false
  367. ;;
  368. --enable-html-docs)
  369. append_cache_entry MAKE_HTML_DOC BOOL true
  370. ;;
  371. --disable-pdf-docs)
  372. append_cache_entry MAKE_PDF_DOC BOOL false
  373. ;;
  374. --enable-pdf-docs)
  375. append_cache_entry MAKE_PDF_DOC BOOL true
  376. ;;
  377. --disable-text-docs)
  378. append_cache_entry MAKE_TEXT_DOC BOOL false
  379. ;;
  380. --enable-text-docs)
  381. append_cache_entry MAKE_TEXT_DOC BOOL true
  382. ;;
  383. --disable-docs)
  384. append_cache_entry MAKE_DOC BOOL false
  385. ;;
  386. --enable-docs)
  387. append_cache_entry MAKE_DOC BOOL true
  388. ;;
  389. --build-type=*)
  390. if [ $optarg = "Debug" ] || [ $optarg = "Release" ] ||
  391. [ $optarg = "RelWithDebInfo" ] || [ $optarg = "MinSizeRel" ]; then
  392. build_type=$optarg
  393. else
  394. echo "Invalid build type '$optarg'. Try $0 --help to see available build types."
  395. exit 1
  396. fi
  397. ;;
  398. --with-pcap-includes=*)
  399. append_cache_entry PCAP_INCLUDE_DIR_HINT PATH $optarg
  400. ;;
  401. --with-pcap-libraries=*)
  402. append_cache_entry PCAP_LIBRARIES_DIR_HINT PATH $optarg
  403. ;;
  404. --with-luajit-includes=*)
  405. append_cache_entry LUAJIT_INCLUDE_DIR_HINT PATH $optarg
  406. ;;
  407. --with-luajit-libraries=*)
  408. append_cache_entry LUAJIT_LIBRARIES_DIR_HINT PATH $optarg
  409. ;;
  410. --with-pcre-includes=*)
  411. append_cache_entry PCRE_INCLUDE_DIR_HINT PATH $optarg
  412. ;;
  413. --with-pcre-libraries=*)
  414. append_cache_entry PCRE_LIBRARIES_DIR_HINT PATH $optarg
  415. ;;
  416. --with-dnet-includes=*)
  417. append_cache_entry DNET_INCLUDE_DIR_HINT PATH $optarg
  418. ;;
  419. --with-dnet-libraries=*)
  420. append_cache_entry DNET_LIBRARIES_DIR_HINT PATH $optarg
  421. ;;
  422. --with-daq-includes=*)
  423. append_cache_entry DAQ_INCLUDE_DIR_HINT PATH $optarg
  424. ;;
  425. --with-daq-libraries=*)
  426. append_cache_entry DAQ_LIBRARIES_DIR_HINT PATH $optarg
  427. ;;
  428. --with-openssl=*)
  429. append_cache_entry OPENSSL_ROOT_DIR PATH $optarg
  430. ;;
  431. --with-hyperscan-includes=*)
  432. append_cache_entry HS_INCLUDE_DIR PATH $optarg
  433. ;;
  434. --with-hyperscan-libraries=*)
  435. append_cache_entry HS_LIBRARIES_DIR PATH $optarg
  436. ;;
  437. --with-atomic-libraries=*)
  438. append_cache_entry ATOMIC_LIBRARIES_DIR_HINT PATH $optarg
  439. ;;
  440. --with-flex-prefix=*)
  441. append_cache_entry CMAKE_PREFIX_PATH PATH $optarg
  442. ;;
  443. --with-flex-includes=*)
  444. append_cache_entry FLEX_INCLUDE_DIR_HINT PATH $optarg
  445. ;;
  446. --with-iconv-includes=*)
  447. append_cache_entry ICONV_INCLUDE_DIR_HINT PATH $optarg
  448. ;;
  449. --with-iconv-libraries=*)
  450. append_cache_entry ICONV_LIBRARIES_DIR_HINT PATH $optarg
  451. ;;
  452. --with-uuid-includes=*)
  453. append_cache_entry UUID_INCLUDE_DIR_HINT PATH $optarg
  454. ;;
  455. --with-uuid-libraries=*)
  456. append_cache_entry UUID_LIBRARIES_DIR_HINT PATH $optarg
  457. ;;
  458. --with-toolchain=*)
  459. append_cache_entry CMAKE_TOOLCHAIN_FILE PATH $optarg
  460. ;;
  461. --with-libml-includes=*)
  462. append_cache_entry ML_INCLUDE_DIR_HINT PATH $optarg
  463. ;;
  464. --with-libml-libraries=*)
  465. append_cache_entry ML_LIBRARIES_DIR_HINT PATH $optarg
  466. ;;
  467. --without-libml)
  468. append_cache_entry ENABLE_KAIZEN_MOCK BOOL true
  469. ;;
  470. SIGNAL_SNORT_RELOAD=*)
  471. append_cache_entry SIGNAL_SNORT_RELOAD STRING $optarg
  472. ;;
  473. SIGNAL_SNORT_DUMP_STATS=*)
  474. append_cache_entry SIGNAL_SNORT_DUMP_STATS STRING $optarg
  475. ;;
  476. SIGNAL_SNORT_ROTATE_STATS=*)
  477. append_cache_entry SIGNAL_SNORT_ROTATE_STATS STRING $optarg
  478. ;;
  479. SIGNAL_SNORT_READ_ATTR_TBL=*)
  480. append_cache_entry SIGNAL_SNORT_READ_ATTR_TBL STRING $optarg
  481. ;;
  482. SNORT_BUILD_NUMBER=*)
  483. append_cache_entry VERSION_BUILD STRING $optarg
  484. ;;
  485. *)
  486. echo "Invalid option '$1'. Try $0 --help to see available options."
  487. exit 1
  488. ;;
  489. esac
  490. shift
  491. done
  492. if [ "$tcm" -eq 1 -a "$jem" -eq 1 ] ; then
  493. echo "--enable-jemalloc and --enable-tcmalloc are mutually exclusive; enable at most one"
  494. exit 2
  495. fi
  496. if [ -d $builddir ]; then
  497. # If build directory exists, check if it has a CMake cache
  498. if [ -f $builddir/CMakeCache.txt ]; then
  499. # If the CMake cache exists, delete it so that this configuration
  500. # is not tainted by a previous one
  501. rm -f $builddir/CMakeCache.txt
  502. fi
  503. else
  504. # Create build directory
  505. mkdir -p $builddir
  506. fi
  507. echo "Build Directory : $builddir"
  508. echo "Source Directory: $sourcedir"
  509. cd $builddir
  510. [ "$CMakeGenerator" ] && gen="-G $CMakeGenerator"
  511. cmake "$gen" \
  512. -DCMAKE_CXX_FLAGS:STRING="$CXXFLAGS $CPPFLAGS" \
  513. -DCMAKE_C_FLAGS:STRING="$CFLAGS $CPPFLAGS" \
  514. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
  515. -DCMAKE_BUILD_TYPE:STRING=$build_type \
  516. $CMakeCacheEntries $sourcedir
  517. echo "# This is the command used to configure this build" > config.status
  518. echo $command >> config.status
  519. chmod u+x config.status