2015-03-02 02:32:02 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.12)
|
2015-05-23 22:43:54 +00:00
|
|
|
string(ASCII 27 ESC)
|
2015-05-20 20:27:53 +00:00
|
|
|
macro(WARNING_LOG MESSAGE)
|
2015-05-23 22:43:54 +00:00
|
|
|
message("-- ${ESC}[31m${MESSAGE}${ESC}[m")
|
2015-05-20 20:27:53 +00:00
|
|
|
endmacro(WARNING_LOG)
|
|
|
|
|
|
|
|
macro(LOG MESSAGE)
|
|
|
|
message("-- ${MESSAGE}")
|
|
|
|
endmacro(LOG)
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2015-05-27 23:50:57 +00:00
|
|
|
# If no explicit compiler override and clang++ exists, prefer clang.
|
|
|
|
find_file(CLANGXX_EXISTS "clang++")
|
|
|
|
if(DEFINED ENV{CC})
|
2015-05-07 04:58:23 +00:00
|
|
|
set(CMAKE_C_COMPILER "$ENV{CC}")
|
2015-04-30 22:47:33 +00:00
|
|
|
LOG("Overriding C compiler from clang to $ENV{CC}")
|
2015-05-27 23:50:57 +00:00
|
|
|
elseif(CLANGXX_EXISTS)
|
|
|
|
set(CMAKE_C_COMPILER "clang")
|
2015-05-07 04:58:23 +00:00
|
|
|
endif()
|
2015-05-27 23:50:57 +00:00
|
|
|
if(DEFINED ENV{CXX})
|
2015-05-07 04:58:23 +00:00
|
|
|
set(CMAKE_CXX_COMPILER "$ENV{CXX}")
|
2015-04-30 22:47:33 +00:00
|
|
|
LOG("Overriding CXX compiler from clang++ to $ENV{CXX}")
|
2015-05-27 23:50:57 +00:00
|
|
|
elseif(CLANGXX_EXISTS)
|
|
|
|
set(CMAKE_CXX_COMPILER "clang++")
|
2015-05-07 04:58:23 +00:00
|
|
|
endif()
|
|
|
|
|
2015-03-02 02:32:02 +00:00
|
|
|
add_compile_options(
|
2015-02-12 00:25:42 +00:00
|
|
|
-Wstrict-aliasing
|
2015-02-11 03:18:56 +00:00
|
|
|
-Wno-missing-field-initializers
|
2015-10-20 02:55:29 +00:00
|
|
|
-Wno-unused-local-typedef
|
2015-10-24 12:06:58 +00:00
|
|
|
-Wno-unknown-warning-option
|
2015-02-13 10:45:43 +00:00
|
|
|
-Wnon-virtual-dtor
|
|
|
|
-Wchar-subscripts
|
|
|
|
-Wpointer-arith
|
|
|
|
-Woverloaded-virtual
|
2015-02-12 00:25:42 +00:00
|
|
|
-Wformat
|
|
|
|
-Wformat-security
|
|
|
|
-Werror=format-security
|
2016-03-21 01:03:30 +00:00
|
|
|
-Wabi-tag
|
2015-02-12 00:25:42 +00:00
|
|
|
-fstack-protector-all
|
|
|
|
-fPIE
|
2015-05-24 01:52:42 +00:00
|
|
|
-fpie
|
|
|
|
-fPIC
|
|
|
|
-fpic
|
2015-06-12 01:13:37 +00:00
|
|
|
-pipe
|
2015-11-22 04:36:32 +00:00
|
|
|
-fdata-sections
|
|
|
|
-ffunction-sections
|
2015-02-11 03:18:56 +00:00
|
|
|
)
|
2015-05-27 04:15:43 +00:00
|
|
|
|
|
|
|
# osquery additional compiler flags added by CMake.
|
|
|
|
set(C_COMPILE_FLAGS "")
|
2015-02-13 10:45:43 +00:00
|
|
|
set(CXX_COMPILE_FLAGS "")
|
2015-02-11 03:18:56 +00:00
|
|
|
|
2015-05-07 04:58:23 +00:00
|
|
|
# Use osquery language to set platform/os
|
2015-05-13 07:31:02 +00:00
|
|
|
if(DEFINED ENV{OSQUERY_PLATFORM})
|
2016-02-16 21:20:49 +00:00
|
|
|
set(PLATFORM "$ENV{OSQUERY_PLATFORM}")
|
2015-05-13 07:31:02 +00:00
|
|
|
else()
|
|
|
|
execute_process(
|
|
|
|
COMMAND "${CMAKE_SOURCE_DIR}/tools/provision.sh" get_platform
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
OUTPUT_VARIABLE PLATFORM
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
endif()
|
2015-05-07 04:58:23 +00:00
|
|
|
|
2015-05-29 00:21:20 +00:00
|
|
|
if(PLATFORM STREQUAL "")
|
|
|
|
WARNING_LOG("Unable to detect osquery platform: ./tools/provision.sh failed")
|
2015-08-13 22:30:51 +00:00
|
|
|
message(FATAL_ERROR "Cannot proceed without knowing the build platform")
|
2015-05-29 00:21:20 +00:00
|
|
|
endif()
|
2015-05-07 04:58:23 +00:00
|
|
|
list(GET PLATFORM 0 OSQUERY_BUILD_PLATFORM)
|
|
|
|
list(GET PLATFORM 1 OSQUERY_BUILD_DISTRO)
|
|
|
|
string(REPLACE "." "_" PLATFORM "${PLATFORM}")
|
|
|
|
string(TOUPPER "${PLATFORM}" PLATFORM)
|
|
|
|
list(GET PLATFORM 0 OSQUERY_BUILD_PLATFORM_DEFINE)
|
|
|
|
list(GET PLATFORM 1 OSQUERY_BUILD_DISTRO_DEFINE)
|
|
|
|
|
2015-03-04 02:40:24 +00:00
|
|
|
# Set non-C compile flags and whole-loading linker flags.
|
|
|
|
# osquery needs ALL symbols in the libraries it includes for relaxed ctors
|
|
|
|
# late-loading modules and SQLite introspection utilities.
|
2014-09-05 14:54:41 +00:00
|
|
|
if(APPLE)
|
2015-10-18 23:27:45 +00:00
|
|
|
if(DEFINED ENV{OSX_VERSION_MIN})
|
2016-02-16 21:20:49 +00:00
|
|
|
set(OSX_VERSION_MIN "$ENV{OSX_VERSION_MIN}")
|
2015-10-18 23:27:45 +00:00
|
|
|
else()
|
|
|
|
set(OSX_VERSION_MIN "${OSQUERY_BUILD_DISTRO}")
|
|
|
|
endif()
|
2015-10-11 21:37:49 +00:00
|
|
|
add_compile_options(
|
2015-10-18 23:27:45 +00:00
|
|
|
-mmacosx-version-min=${OSX_VERSION_MIN}
|
2015-10-11 21:37:49 +00:00
|
|
|
)
|
|
|
|
|
2015-02-03 05:21:36 +00:00
|
|
|
set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} -std=c++11 -stdlib=libc++")
|
2014-12-31 16:28:48 +00:00
|
|
|
set(OS_WHOLELINK_PRE "-Wl,-force_load")
|
2014-09-06 01:12:37 +00:00
|
|
|
set(OS_WHOLELINK_POST "")
|
2015-02-03 05:21:36 +00:00
|
|
|
# Special compile flags for Objective-C++
|
2015-02-11 03:18:56 +00:00
|
|
|
set(OBJCXX_COMPILE_FLAGS
|
2015-10-11 21:37:49 +00:00
|
|
|
"-x objective-c++ -fobjc-arc -Wno-c++11-extensions")
|
2016-03-07 09:30:20 +00:00
|
|
|
elseif(WIN32)
|
|
|
|
# Windows
|
|
|
|
# C++11 features should be on by default in 2012 and beyond.
|
2014-09-05 14:54:41 +00:00
|
|
|
else()
|
2015-02-13 10:45:43 +00:00
|
|
|
set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} -std=c++11")
|
|
|
|
set(OS_WHOLELINK_PRE "-Wl,-whole-archive")
|
|
|
|
set(OS_WHOLELINK_POST "-Wl,-no-whole-archive")
|
2015-05-07 04:58:23 +00:00
|
|
|
# Set CMAKE variables depending on platform, to know which tables and what
|
|
|
|
# component-specific globbing is needed.
|
|
|
|
if(${OSQUERY_BUILD_PLATFORM} STREQUAL "freebsd")
|
|
|
|
set(FREEBSD TRUE)
|
|
|
|
set(LINUX FALSE)
|
2015-09-24 23:12:26 +00:00
|
|
|
set(ENV{SKIP_BENCHMARKS}, "TRUE")
|
2015-05-07 04:58:23 +00:00
|
|
|
else()
|
|
|
|
set(LINUX TRUE)
|
|
|
|
set(FREEBSD FALSE)
|
|
|
|
endif()
|
2014-12-25 20:46:59 +00:00
|
|
|
endif()
|
|
|
|
|
2015-04-13 01:03:09 +00:00
|
|
|
# RHEL6 uses a different gcc 4.9 runtime
|
2015-04-24 20:52:17 +00:00
|
|
|
if(${OSQUERY_BUILD_DISTRO} STREQUAL "rhel6")
|
2015-04-13 01:03:09 +00:00
|
|
|
set(GCC_RUNTIME "/opt/rh/devtoolset-3/root/usr/")
|
2015-04-30 22:47:33 +00:00
|
|
|
WARNING_LOG("Setting RHEL6 GCC runtime: ${GCC_RUNTIME}")
|
2015-05-27 04:15:43 +00:00
|
|
|
set(CMAKE_C_COMPILER "${CMAKE_C_COMPILER}" "--gcc-toolchain=${GCC_RUNTIME}")
|
|
|
|
set(CMAKE_CXX_COMPILER "${CMAKE_CXX_COMPILER}" "--gcc-toolchain=${GCC_RUNTIME}")
|
2015-05-21 08:22:00 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --gcc-toolchain=${GCC_RUNTIME}")
|
2015-04-13 01:03:09 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --gcc-toolchain=${GCC_RUNTIME}")
|
2015-05-27 04:15:43 +00:00
|
|
|
set(C_COMPILE_FLAGS "${C_COMPILE_FLAGS} --gcc-toolchain=${GCC_RUNTIME}")
|
|
|
|
set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} --gcc-toolchain=${GCC_RUNTIME}")
|
2015-04-04 23:49:17 +00:00
|
|
|
endif()
|
|
|
|
|
2016-01-06 00:31:17 +00:00
|
|
|
# Help Debian Wheezy find BZip2
|
|
|
|
if(${OSQUERY_BUILD_DISTRO} STREQUAL "wheezy")
|
|
|
|
set (CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu")
|
|
|
|
endif()
|
|
|
|
|
2015-05-13 07:31:02 +00:00
|
|
|
# Provisioning installs non-default C++11 runtimes on build hosts.
|
|
|
|
# List those distros that include a non-system-default runtime.
|
|
|
|
set(OSQUERY_REQUIRE_RUNTIMES
|
2015-05-27 23:50:57 +00:00
|
|
|
"lucid"
|
2015-05-13 07:31:02 +00:00
|
|
|
"precise"
|
|
|
|
"centos6"
|
|
|
|
"rhel6"
|
2015-05-27 23:50:57 +00:00
|
|
|
"oracle6"
|
2016-01-06 00:31:17 +00:00
|
|
|
"wheezy"
|
2015-05-13 07:31:02 +00:00
|
|
|
)
|
|
|
|
|
2015-02-03 05:21:36 +00:00
|
|
|
# make debug (environment variable from Makefile)
|
2015-01-31 11:09:30 +00:00
|
|
|
if(DEFINED ENV{DEBUG})
|
2015-05-04 21:15:19 +00:00
|
|
|
set(DEBUG TRUE)
|
2015-01-31 11:09:30 +00:00
|
|
|
set(CMAKE_BUILD_TYPE "Debug")
|
2016-03-05 17:29:51 +00:00
|
|
|
add_compile_options(
|
|
|
|
-g
|
|
|
|
-O0
|
|
|
|
-fstandalone-debug
|
|
|
|
)
|
2015-03-05 19:28:27 +00:00
|
|
|
add_definitions(-DDEBUG)
|
2015-04-30 22:47:33 +00:00
|
|
|
WARNING_LOG("Setting DEBUG build")
|
2015-02-13 10:45:43 +00:00
|
|
|
elseif(DEFINED ENV{SANITIZE})
|
2015-03-02 02:32:02 +00:00
|
|
|
# make sanitize (cannot make debug sanitize)
|
2016-03-05 17:29:51 +00:00
|
|
|
add_compile_options(
|
|
|
|
-g
|
|
|
|
-O1
|
|
|
|
-fstandalone-debug
|
|
|
|
-fno-omit-frame-pointer
|
|
|
|
-fno-optimize-sibling-calls
|
|
|
|
)
|
2015-03-05 19:28:27 +00:00
|
|
|
add_definitions(-DNDEBUG)
|
2015-05-04 03:02:01 +00:00
|
|
|
if(DEFINED ENV{SANITIZE_THREAD})
|
|
|
|
add_compile_options(-fsanitize=thread)
|
|
|
|
else()
|
2016-03-19 02:37:11 +00:00
|
|
|
add_compile_options(-fsanitize=address)
|
|
|
|
if (NOT APPLE)
|
|
|
|
add_compile_options(-fsanitize=leak)
|
|
|
|
endif()
|
2015-05-04 03:02:01 +00:00
|
|
|
endif()
|
|
|
|
set(SANITIZE_BLACKLIST "${CMAKE_SOURCE_DIR}/tools/tests/sanitize_blacklist.txt")
|
2016-02-23 05:40:00 +00:00
|
|
|
add_definitions(-fsanitize-blacklist=${SANITIZE_BLACKLIST})
|
2014-12-25 20:46:59 +00:00
|
|
|
else()
|
2015-05-04 21:15:19 +00:00
|
|
|
set(DEBUG FALSE)
|
2015-05-24 01:52:42 +00:00
|
|
|
add_compile_options(-Os)
|
2015-03-05 19:28:27 +00:00
|
|
|
add_definitions(-DNDEBUG)
|
2015-02-13 10:45:43 +00:00
|
|
|
# Do not enable fortify with clang: http://llvm.org/bugs/show_bug.cgi?id=16821
|
|
|
|
#set(C_COMPILE_FLAGS "${C_COMPILE_FLAGS} -D_FORTIFY_SOURCE=2")
|
2014-09-06 01:12:37 +00:00
|
|
|
endif()
|
2016-02-05 03:14:22 +00:00
|
|
|
# Generate a compile_commands.json for static analyzer input.
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
2014-09-06 01:12:37 +00:00
|
|
|
|
2015-06-12 01:13:37 +00:00
|
|
|
if(NOT DEFINED ENV{OPTIMIZED})
|
2015-08-07 00:09:26 +00:00
|
|
|
add_compile_options(-march=x86-64 -mno-avx)
|
2015-06-12 01:13:37 +00:00
|
|
|
endif()
|
|
|
|
|
2015-02-03 05:21:36 +00:00
|
|
|
# make analyze (environment variable from Makefile)
|
2015-01-31 11:09:30 +00:00
|
|
|
if(DEFINED ENV{ANALYZE})
|
|
|
|
set(CMAKE_CXX_COMPILER "${CMAKE_SOURCE_DIR}/tools/analysis/clang-analyze.sh")
|
|
|
|
endif()
|
|
|
|
|
2015-05-04 21:15:19 +00:00
|
|
|
# make sdk (tests building SDK-based extensions)
|
|
|
|
if(DEFINED ENV{SDK})
|
|
|
|
set(OSQUERY_BUILD_SDK_ONLY TRUE)
|
2016-03-15 16:30:40 +00:00
|
|
|
else()
|
|
|
|
set(OSQUERY_BUILD_SDK_ONLY FALSE)
|
2015-05-04 21:15:19 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# make packages will set release to true and blacklist development features,
|
|
|
|
# development plugins, etc.
|
|
|
|
if(DEFINED ENV{PACKAGE})
|
|
|
|
set(OSQUERY_BUILD_RELEASE TRUE)
|
|
|
|
else()
|
|
|
|
set(OSQUERY_BUILD_RELEASE FALSE)
|
|
|
|
endif()
|
|
|
|
|
2015-02-03 05:21:36 +00:00
|
|
|
# Finished setting compiler/compiler flags.
|
2015-02-01 12:10:57 +00:00
|
|
|
project(OSQUERY)
|
2015-04-30 22:47:33 +00:00
|
|
|
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE)
|
2015-05-20 20:27:53 +00:00
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" "${CMAKE_MODULE_PATH}")
|
|
|
|
include(CMakeLibs)
|
2015-04-30 22:47:33 +00:00
|
|
|
|
2015-05-23 22:43:54 +00:00
|
|
|
if(NOT IS_DIRECTORY ${CMAKE_SOURCE_DIR}/third-party/sqlite3)
|
2015-08-28 23:50:44 +00:00
|
|
|
WARNING_LOG("Cannot find git submodule third-party/sqlite3 directory")
|
2015-05-23 22:43:54 +00:00
|
|
|
WARNING_LOG("Please run: make deps or git submodule update --init")
|
|
|
|
message(FATAL_ERROR "No sqlite3 directory")
|
|
|
|
endif()
|
|
|
|
|
2015-05-07 04:58:23 +00:00
|
|
|
# Make sure deps were built before compiling (else show warning).
|
2014-11-11 15:55:04 +00:00
|
|
|
execute_process(
|
2014-12-03 23:31:09 +00:00
|
|
|
COMMAND "${CMAKE_SOURCE_DIR}/tools/provision.sh" check "${CMAKE_BINARY_DIR}"
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
2014-11-11 15:55:04 +00:00
|
|
|
OUTPUT_VARIABLE OSQUERY_DEPS_MESSAGE
|
|
|
|
RESULT_VARIABLE OSQUERY_DEPS_CHECK
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
if(OSQUERY_DEPS_CHECK)
|
2015-04-30 22:47:33 +00:00
|
|
|
WARNING_LOG("${OSQUERY_DEPS_MESSAGE}")
|
2014-11-11 15:55:04 +00:00
|
|
|
endif()
|
|
|
|
|
2015-05-07 04:58:23 +00:00
|
|
|
# Discover build version from an environment variable or from the git checkout.
|
|
|
|
if(DEFINED ENV{OSQUERY_BUILD_VERSION})
|
|
|
|
set(OSQUERY_BUILD_VERSION "$ENV{OSQUERY_BUILD_VERSION}")
|
|
|
|
else()
|
|
|
|
# Generate version from git
|
|
|
|
execute_process(
|
|
|
|
COMMAND git describe --tags HEAD --always
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
OUTPUT_VARIABLE OSQUERY_BUILD_VERSION
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Discover the SDK version from an environment variable or the build version.
|
2015-05-29 00:21:20 +00:00
|
|
|
if(OSQUERY_BUILD_VERSION STREQUAL "")
|
|
|
|
WARNING_LOG("Unable to detect osquery version: 'git describe' failed")
|
|
|
|
WARNING_LOG("Setting the version to: 1.0.0-unknown (beware!)")
|
|
|
|
set(OSQUERY_BUILD_VERSION "1.0.0-unknown")
|
|
|
|
endif()
|
2015-03-03 00:21:15 +00:00
|
|
|
if(DEFINED ENV{SDK_VERSION})
|
|
|
|
set(OSQUERY_BUILD_SDK_VERSION "${ENV{SDK_VERSION}}")
|
|
|
|
else()
|
|
|
|
string(REPLACE "-" ";" OSQUERY_BUILD_SDK_VERSION ${OSQUERY_BUILD_VERSION})
|
|
|
|
list(GET OSQUERY_BUILD_SDK_VERSION 0 OSQUERY_BUILD_SDK_VERSION)
|
|
|
|
endif()
|
2015-02-03 05:21:36 +00:00
|
|
|
|
|
|
|
# Set various platform/platform-version/build version/etc defines.
|
|
|
|
add_definitions(
|
2015-03-03 00:21:15 +00:00
|
|
|
-DOSQUERY_BUILD_SDK_VERSION=${OSQUERY_BUILD_SDK_VERSION}
|
2015-04-16 00:05:26 +00:00
|
|
|
-DOSQUERY_BUILD_PLATFORM=${OSQUERY_BUILD_PLATFORM}
|
2015-04-15 23:34:12 +00:00
|
|
|
-DOSQUERY_BUILD_DISTRO=${OSQUERY_BUILD_DISTRO}
|
2015-04-16 00:05:26 +00:00
|
|
|
-D${OSQUERY_BUILD_PLATFORM_DEFINE}
|
|
|
|
-D${OSQUERY_BUILD_PLATFORM_DEFINE}_${OSQUERY_BUILD_DISTRO_DEFINE}
|
2015-05-24 01:52:42 +00:00
|
|
|
-DSTRIP_FLAG_HELP=1
|
2015-05-13 06:46:02 +00:00
|
|
|
-DBOOST_NETWORK_ENABLE_HTTPS
|
2016-01-21 00:01:49 +00:00
|
|
|
-DBOOST_NO_CXX11_VARIADIC_TEMPLATES
|
2015-02-03 05:21:36 +00:00
|
|
|
)
|
|
|
|
|
2016-03-05 04:41:06 +00:00
|
|
|
if(DEFINED ENV{SQLITE_DEBUG})
|
|
|
|
add_definitions(
|
|
|
|
-DSQLITE_DEBUG=1
|
|
|
|
-DSQLITE_ENABLE_WHERETRACE=1
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2014-11-12 05:34:59 +00:00
|
|
|
if(APPLE)
|
2015-05-23 22:43:54 +00:00
|
|
|
LOG_PLATFORM("OS X")
|
2016-01-06 02:53:40 +00:00
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "debian")
|
|
|
|
set(DEBIAN_BASED TRUE)
|
|
|
|
set(DEBIAN TRUE)
|
|
|
|
LOG_PLATFORM("Debian")
|
2015-04-19 02:51:00 +00:00
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "ubuntu")
|
2015-04-30 22:47:33 +00:00
|
|
|
set(DEBIAN_BASED TRUE)
|
2014-11-12 05:34:59 +00:00
|
|
|
set(UBUNTU TRUE)
|
2015-05-23 22:43:54 +00:00
|
|
|
LOG_PLATFORM("Ubuntu")
|
2015-04-19 02:51:00 +00:00
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "centos")
|
2015-04-30 22:47:33 +00:00
|
|
|
set(REDHAT_BASED TRUE)
|
2014-11-12 05:34:59 +00:00
|
|
|
set(CENTOS TRUE)
|
2015-05-23 22:43:54 +00:00
|
|
|
LOG_PLATFORM("CentOS")
|
2015-04-19 02:51:00 +00:00
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "rhel")
|
2015-04-30 22:47:33 +00:00
|
|
|
set(REDHAT_BASED TRUE)
|
2015-04-04 00:18:27 +00:00
|
|
|
set(RHEL TRUE)
|
2015-05-23 22:43:54 +00:00
|
|
|
LOG_PLATFORM("RHEL")
|
2015-05-10 18:42:30 +00:00
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "amazon")
|
2015-04-30 22:47:33 +00:00
|
|
|
set(REDHAT_BASED TRUE)
|
2015-05-10 18:42:30 +00:00
|
|
|
set(AMAZON TRUE)
|
2015-05-23 22:43:54 +00:00
|
|
|
LOG_PLATFORM("Amazon Linux")
|
2015-04-30 22:47:33 +00:00
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "oracle")
|
|
|
|
set(REDHAT_BASED TRUE)
|
|
|
|
set(ORACLE TRUE)
|
2015-05-23 22:43:54 +00:00
|
|
|
LOG_PLATFORM("Oracle Linux")
|
2015-05-05 20:55:49 +00:00
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "freebsd")
|
|
|
|
set(FREEBSD TRUE)
|
2015-05-23 22:43:54 +00:00
|
|
|
LOG_PLATFORM("FreeBSD")
|
2016-03-07 09:30:20 +00:00
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "windows")
|
|
|
|
set(WINDOWS TRUE)
|
|
|
|
LOG_PLATFORM("Windows")
|
2015-04-30 22:47:33 +00:00
|
|
|
endif()
|
|
|
|
|
2016-03-15 02:51:03 +00:00
|
|
|
if("${OSQUERY_BUILD_DISTRO}" MATCHES "^(centos|rhel|oracle)7$")
|
|
|
|
# Useful for libudev version detection.
|
|
|
|
set(SYSTEMD TRUE)
|
|
|
|
endif()
|
|
|
|
|
2015-04-30 22:47:33 +00:00
|
|
|
if(REDHAT_BASED)
|
|
|
|
add_definitions(-DREDHAT_BASED=1)
|
|
|
|
elseif(DEBIAN_BASED)
|
|
|
|
add_definitions(-DDEBIAN_BASED=1)
|
2014-11-12 05:34:59 +00:00
|
|
|
endif()
|
|
|
|
|
2015-02-20 01:00:43 +00:00
|
|
|
# Make sure the generated paths exist
|
|
|
|
execute_process(COMMAND mkdir -p "${CMAKE_BINARY_DIR}/generated")
|
|
|
|
|
2015-08-18 08:43:37 +00:00
|
|
|
# We need to link some packages as dynamic/dependent.
|
2016-03-07 09:30:20 +00:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .dll .dylib .so .a)
|
2015-08-18 08:43:37 +00:00
|
|
|
find_package(BZip2 REQUIRED)
|
|
|
|
find_package(Dl REQUIRED)
|
|
|
|
find_package(Readline REQUIRED)
|
|
|
|
|
2015-08-13 22:30:51 +00:00
|
|
|
# Apple has deprecated OpenSSL, static link with brew bottled libressl
|
2015-08-30 08:11:45 +00:00
|
|
|
if(APPLE)
|
|
|
|
if(DEFINED ENV{BUILD_USE_LIBRESSL} OR ${OSQUERY_BUILD_DISTRO} STREQUAL "10.11")
|
|
|
|
if(NOT DEFINED ENV{BUILD_LINK_SHARED})
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .dylib .so)
|
|
|
|
endif()
|
|
|
|
execute_process(COMMAND brew --prefix OUTPUT_VARIABLE BREW_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
set(OPENSSL_ROOT_DIR "${BREW_PREFIX}/opt/libressl")
|
|
|
|
else()
|
|
|
|
# Some installs may find the optional brew /usr/local/lib/ as the root.
|
|
|
|
set(OPENSSL_ROOT_DIR "/usr")
|
2015-08-13 22:30:51 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
2015-08-18 08:43:37 +00:00
|
|
|
find_package(OpenSSL REQUIRED)
|
|
|
|
include_directories("${OPENSSL_INCLUDE_DIR}")
|
2015-01-05 16:05:41 +00:00
|
|
|
|
2015-05-21 08:22:00 +00:00
|
|
|
# Make sure the OpenSSL/ssl library has a TLS client method.
|
|
|
|
# Prefer the highest version of TLS, but accept 1.2, 1.1, or 1.0.
|
|
|
|
include(CheckLibraryExists)
|
2015-08-13 22:30:51 +00:00
|
|
|
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
|
|
|
|
set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
|
2015-10-18 22:26:01 +00:00
|
|
|
CHECK_LIBRARY_EXISTS(${OPENSSL_SSL_LIBRARY} "SSLv3_client_method" "" OPENSSL_SSL3)
|
2015-05-21 08:22:00 +00:00
|
|
|
CHECK_LIBRARY_EXISTS(${OPENSSL_SSL_LIBRARY} "TLSv1_2_client_method" "" OPENSSL_TLSV12)
|
|
|
|
CHECK_LIBRARY_EXISTS(${OPENSSL_SSL_LIBRARY} "TLSv1_1_client_method" "" OPENSSL_TLSV11)
|
|
|
|
CHECK_LIBRARY_EXISTS(${OPENSSL_SSL_LIBRARY} "TLSv1_client_method" "" OPENSSL_TLSV10)
|
|
|
|
|
|
|
|
# Add a define based on the highest TLS version found. Fatal if no TLS client.
|
|
|
|
if(OPENSSL_TLSV12)
|
2015-10-08 14:22:48 +00:00
|
|
|
add_definitions(-DHAS_SSL_TXT_TLSV1_2)
|
2015-05-21 08:22:00 +00:00
|
|
|
elseif(OPENSSL_TLSV11)
|
2015-10-08 14:22:48 +00:00
|
|
|
add_definitions(-DHAS_SSL_TXT_TLSV1_1)
|
2015-05-21 08:22:00 +00:00
|
|
|
elseif(OPENSSL_TLSV10)
|
2015-10-08 14:22:48 +00:00
|
|
|
add_definitions(-DHAS_SSL_TXT_TLSV1)
|
2015-05-21 08:22:00 +00:00
|
|
|
else()
|
2015-08-13 22:30:51 +00:00
|
|
|
message(FATAL_ERROR "Cannot find any TLS client methods")
|
2015-05-21 08:22:00 +00:00
|
|
|
endif()
|
2015-10-18 22:26:01 +00:00
|
|
|
if(NOT OPENSSL_SSL3)
|
|
|
|
add_definitions(-DNO_SSL_TXT_SSLV3)
|
|
|
|
endif()
|
2015-05-21 08:22:00 +00:00
|
|
|
|
2015-01-05 16:05:41 +00:00
|
|
|
# Most dependent packages/libs we want static.
|
2015-07-19 23:58:43 +00:00
|
|
|
if(NOT DEFINED ENV{BUILD_LINK_SHARED})
|
2015-06-12 01:13:37 +00:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .dylib .so)
|
|
|
|
endif()
|
2016-03-07 09:30:20 +00:00
|
|
|
|
|
|
|
if(DEFINED ENV{BOOST_ROOT})
|
|
|
|
set(BOOST_ROOT "$ENV{BOOST_ROOT}")
|
|
|
|
include_directories("${BOOST_ROOT}")
|
|
|
|
endif()
|
|
|
|
|
2015-05-23 22:43:54 +00:00
|
|
|
find_package(Gflags REQUIRED)
|
2015-01-05 16:05:41 +00:00
|
|
|
find_package(Gtest REQUIRED)
|
2016-02-05 23:44:30 +00:00
|
|
|
find_package(Thrift 0.9.3 REQUIRED)
|
2014-09-06 01:12:37 +00:00
|
|
|
|
2015-07-13 07:47:20 +00:00
|
|
|
# If using the RocksDB LITE version our code must also define ROCKSDB_LITE=1
|
2016-03-05 17:29:51 +00:00
|
|
|
if(NOT DEFINED ENV{SKIP_ROCKSDB})
|
|
|
|
set(ROCKSDB TRUE)
|
|
|
|
find_package(RocksDB REQUIRED)
|
2015-07-13 07:47:20 +00:00
|
|
|
endif()
|
|
|
|
|
2015-05-08 23:03:43 +00:00
|
|
|
# Python is used for table spec generation and formating.
|
2015-04-30 22:47:33 +00:00
|
|
|
if(PYTHON_VERSION_MAJOR STREQUAL "2" AND PYTHON_VERSION_MINOR STREQUAL "4")
|
|
|
|
WARNING_LOG("Found python 2.4, overriding to /usr/bin/python2.6")
|
|
|
|
set(PYTHON_EXECUTABLE "/usr/bin/python2.6")
|
|
|
|
endif()
|
2015-05-08 23:03:43 +00:00
|
|
|
|
2015-02-04 03:55:16 +00:00
|
|
|
enable_testing()
|
|
|
|
|
|
|
|
include(Packages)
|
|
|
|
include(Thrift)
|
|
|
|
|
2016-02-24 01:07:24 +00:00
|
|
|
include_directories("${CMAKE_SOURCE_DIR}/third-party/sqlite3")
|
2014-12-28 06:42:59 +00:00
|
|
|
include_directories("${CMAKE_SOURCE_DIR}/include")
|
|
|
|
include_directories("${CMAKE_SOURCE_DIR}")
|
|
|
|
include_directories("/usr/local/include")
|
|
|
|
link_directories("/usr/local/lib")
|
2014-09-24 05:06:32 +00:00
|
|
|
|
2016-02-23 22:15:23 +00:00
|
|
|
# Add custom homebrew paths
|
|
|
|
if(APPLE)
|
|
|
|
execute_process(COMMAND brew --prefix OUTPUT_VARIABLE BREW_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
include_directories("${BREW_PREFIX}/include")
|
|
|
|
link_directories("${BREW_PREFIX}/lib")
|
|
|
|
endif()
|
|
|
|
|
2015-05-09 02:10:43 +00:00
|
|
|
# Add sysroot overrides for each platform/distro.
|
2015-08-29 09:01:57 +00:00
|
|
|
if(APPLE)
|
|
|
|
include_directories("${CMAKE_SOURCE_DIR}/third-party/sysroots/darwin")
|
|
|
|
elseif(LINUX)
|
|
|
|
include_directories("${CMAKE_SOURCE_DIR}/third-party/sysroots/linux")
|
2015-05-09 02:10:43 +00:00
|
|
|
endif()
|
|
|
|
|
2016-02-24 01:07:24 +00:00
|
|
|
add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/sqlite3")
|
2014-12-28 06:42:59 +00:00
|
|
|
add_subdirectory(osquery)
|
2015-03-02 04:08:05 +00:00
|
|
|
add_subdirectory(tools/tests)
|
2014-09-24 05:06:32 +00:00
|
|
|
|
2015-06-30 21:20:04 +00:00
|
|
|
# Include the kernel building targets/macros
|
2016-03-15 16:30:40 +00:00
|
|
|
if(NOT ${OSQUERY_BUILD_SDK_ONLY})
|
|
|
|
add_subdirectory(kernel)
|
|
|
|
endif()
|
2015-06-30 21:20:04 +00:00
|
|
|
|
2014-09-24 03:12:53 +00:00
|
|
|
# make docs
|
2014-12-28 06:42:59 +00:00
|
|
|
find_package(Doxygen)
|
2014-09-24 03:12:53 +00:00
|
|
|
if(DOXYGEN_FOUND)
|
2014-12-28 06:42:59 +00:00
|
|
|
add_custom_target(
|
2014-09-24 03:12:53 +00:00
|
|
|
docs
|
2015-07-16 19:23:44 +00:00
|
|
|
COMMAND "${CMAKE_SOURCE_DIR}/tools/codegen/genapi.py" "${CMAKE_SOURCE_DIR}"
|
|
|
|
"--output" "--directory" "${CMAKE_SOURCE_DIR}/build/docs"
|
|
|
|
COMMAND echo "PROJECT_NUMBER=${OSQUERY_BUILD_VERSION}" |
|
2015-04-19 02:51:00 +00:00
|
|
|
cat ${CMAKE_SOURCE_DIR}/Doxyfile - |
|
|
|
|
"${DOXYGEN_EXECUTABLE}" -;
|
2014-12-03 23:31:09 +00:00
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
2014-09-24 03:12:53 +00:00
|
|
|
COMMENT "Generating API documentation with Doxygen" VERBATIM
|
|
|
|
)
|
|
|
|
endif(DOXYGEN_FOUND)
|
2014-09-24 06:38:23 +00:00
|
|
|
|
2014-11-02 19:30:56 +00:00
|
|
|
# make format-all
|
2014-12-28 06:42:59 +00:00
|
|
|
add_custom_target(
|
2014-11-02 19:30:56 +00:00
|
|
|
format-all
|
2015-04-11 08:05:58 +00:00
|
|
|
find osquery include tools \( -name "*.h" -o -name "*.cpp" -o -name "*.mm" \)
|
2015-03-09 00:00:14 +00:00
|
|
|
-exec clang-format -i {} +
|
2014-12-03 23:31:09 +00:00
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
2014-11-02 19:30:56 +00:00
|
|
|
COMMENT "Formatting all osquery code with clang-format" VERBATIM
|
2014-09-24 06:38:23 +00:00
|
|
|
)
|
2014-11-02 19:30:56 +00:00
|
|
|
|
2015-02-03 05:21:36 +00:00
|
|
|
# make format
|
2014-12-28 06:42:59 +00:00
|
|
|
add_custom_target(
|
2014-11-02 19:30:56 +00:00
|
|
|
format
|
2015-05-08 23:03:43 +00:00
|
|
|
${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/tools/formatting/git-clang-format.py"
|
2014-12-03 23:31:09 +00:00
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
2014-11-02 19:30:56 +00:00
|
|
|
COMMENT "Formatting code staged code changes with clang-format" VERBATIM
|
|
|
|
)
|
2015-02-20 01:00:43 +00:00
|
|
|
|
|
|
|
# make sync
|
|
|
|
add_custom_target(
|
|
|
|
sync
|
|
|
|
"${CMAKE_SOURCE_DIR}/tools/sync.sh" "${CMAKE_BINARY_DIR}"
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
COMMENT "Generating sdk sync: ${CMAKE_BINARY_DIR}/sync"
|
2015-05-05 20:55:49 +00:00
|
|
|
DEPENDS osquery_extensions osquery_amalgamation
|
2015-02-20 01:00:43 +00:00
|
|
|
)
|