osquery-1/CMakeLists.txt

252 lines
7.7 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 2.8.12)
2014-07-31 00:35:19 +00:00
2015-04-04 23:49:17 +00:00
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
add_compile_options(
2015-02-11 03:18:56 +00:00
-Wall
-Wextra
-Wstrict-aliasing
2015-02-11 03:18:56 +00:00
-Wno-unused-parameter
-Wno-unused-result
2015-02-11 03:18:56 +00:00
-Wno-missing-field-initializers
-Wno-sign-compare
-Wnon-virtual-dtor
-Wchar-subscripts
-Wpointer-arith
-Woverloaded-virtual
-Wformat
-Wformat-security
-Werror=format-security
-fstack-protector-all
-fPIE
2015-02-11 03:18:56 +00:00
)
set(CXX_COMPILE_FLAGS "")
2015-02-11 03:18:56 +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)
set(APPLE_MIN_ABI "10.9")
2015-02-03 05:21:36 +00:00
set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} -std=c++11 -stdlib=libc++")
set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} -mmacosx-version-min=${APPLE_MIN_ABI}")
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
"-x objective-c++ -fobjc-arc -Wno-c++11-extensions -mmacosx-version-min=${APPLE_MIN_ABI}")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(FREEBSD TRUE)
2015-05-05 20:55:49 +00:00
set(LINUX FALSE)
set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} -std=c++11 -stdlib=libc++")
set(OS_WHOLELINK_PRE "")
set(OS_WHOLELINK_POST "")
2014-09-05 14:54:41 +00:00
else()
2015-05-05 20:55:49 +00:00
set(FREEBSD FALSE)
set(LINUX TRUE)
# Do not use the shared linker flags for modules.
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")
endif()
# Use osquery language to set platform/os
execute_process(
COMMAND "${CMAKE_SOURCE_DIR}/tools/provision.sh" get_platform
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE PLATFORM
OUTPUT_STRIP_TRAILING_WHITESPACE
)
2015-04-16 00:05:26 +00:00
list(GET PLATFORM 0 OSQUERY_BUILD_PLATFORM)
list(GET PLATFORM 1 OSQUERY_BUILD_DISTRO)
string(REPLACE "." "_" PLATFORM "${PLATFORM}")
string(TOUPPER "${PLATFORM}" PLATFORM)
2015-04-16 00:05:26 +00:00
list(GET PLATFORM 0 OSQUERY_BUILD_PLATFORM_DEFINE)
list(GET PLATFORM 1 OSQUERY_BUILD_DISTRO_DEFINE)
# RHEL6 uses a different gcc 4.9 runtime
2015-04-24 20:52:17 +00:00
if(${OSQUERY_BUILD_DISTRO} STREQUAL "rhel6")
set(GCC_RUNTIME "/opt/rh/devtoolset-3/root/usr/")
message("-- Setting RHEL6 GCC runtime: ${GCC_RUNTIME}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --gcc-toolchain=${GCC_RUNTIME}")
2015-04-04 23:49:17 +00:00
endif()
2015-02-03 05:21:36 +00:00
# make debug (environment variable from Makefile)
if(DEFINED ENV{DEBUG})
2015-05-04 21:15:19 +00:00
set(DEBUG TRUE)
set(CMAKE_BUILD_TYPE "Debug")
add_compile_options(-g -O0 -pg)
add_definitions(-DDEBUG)
message("-- Setting DEBUG build")
elseif(DEFINED ENV{SANITIZE})
# make sanitize (cannot make debug sanitize)
add_compile_options(-g -O0 -fno-omit-frame-pointer)
add_definitions(-DNDEBUG)
2015-05-04 03:02:01 +00:00
if(DEFINED ENV{SANITIZE_THREAD})
add_compile_options(-fsanitize=thread)
else()
add_compile_options(-fsanitize=leak -fsanitize=address)
endif()
set(SANITIZE_BLACKLIST "${CMAKE_SOURCE_DIR}/tools/tests/sanitize_blacklist.txt")
add_compile_options(-fsanitize-blacklist=${SANITIZE_BLACKLIST})
else()
2015-05-04 21:15:19 +00:00
set(DEBUG FALSE)
add_compile_options(-O2)
add_definitions(-DNDEBUG)
# 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()
2015-02-03 05:21:36 +00:00
# make analyze (environment variable from Makefile)
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)
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-02-03 05:21:36 +00:00
# Make sure deps were built before compiling (else show warning)
execute_process(
COMMAND "${CMAKE_SOURCE_DIR}/tools/provision.sh" check "${CMAKE_BINARY_DIR}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE OSQUERY_DEPS_MESSAGE
RESULT_VARIABLE OSQUERY_DEPS_CHECK
OUTPUT_STRIP_TRAILING_WHITESPACE
)
2015-01-10 21:52:20 +00:00
string(ASCII 27 Esc)
if(OSQUERY_DEPS_CHECK)
2014-11-11 15:59:42 +00:00
message(WARNING "${Esc}[31m${OSQUERY_DEPS_MESSAGE}${Esc}[m")
endif()
2015-02-03 05:21:36 +00:00
# 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
)
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(
-DOSQUERY_BUILD_VERSION=${OSQUERY_BUILD_VERSION}
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}
-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-02-03 05:21:36 +00:00
)
if(APPLE)
message("-- Building for OS X")
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "ubuntu")
set(UBUNTU TRUE)
message("-- Building for Ubuntu")
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "centos")
set(CENTOS TRUE)
message("-- Building for CentOS")
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "rhel")
2015-04-04 00:18:27 +00:00
set(RHEL TRUE)
2015-04-03 23:53:02 +00:00
message("-- Building for RHEL")
2015-05-05 20:55:49 +00:00
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "freebsd")
set(FREEBSD TRUE)
message("-- Building for FreeBSD")
endif()
# Make sure the generated paths exist
execute_process(COMMAND mkdir -p "${CMAKE_BINARY_DIR}/generated")
2014-12-28 06:42:59 +00:00
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" "${CMAKE_MODULE_PATH}")
2015-01-08 23:53:51 +00:00
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE)
# We need to link some packages as dynamic/dependent.
set(CMAKE_FIND_LIBRARY_SUFFIXES .dylib .so)
2014-12-28 06:42:59 +00:00
find_package(OpenSSL REQUIRED)
find_package(Crypto REQUIRED)
find_package(BZip2 REQUIRED)
2014-12-28 06:42:59 +00:00
find_package(Dl REQUIRED)
find_package(Readline REQUIRED)
# Most dependent packages/libs we want static.
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .dylib .so)
find_package(CppNetlib 0.11.0 REQUIRED)
find_package(Gflags REQUIRED)
find_package(Glog REQUIRED)
find_package(Gtest REQUIRED)
find_package(RocksDB REQUIRED)
find_package(Snappy REQUIRED)
find_package(Sqlite3 REQUIRED)
find_package(Thrift 0.9.1 REQUIRED)
2014-09-06 01:12:37 +00:00
2015-02-04 03:55:16 +00:00
enable_testing()
include(CMakeLibs)
include(Packages)
include(Thrift)
2015-01-18 01:23:41 +00:00
include_directories("${GLOG_INCLUDE_DIRS}")
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
2014-12-28 06:42:59 +00:00
add_subdirectory(osquery)
add_subdirectory(tools/tests)
2014-09-24 05:06:32 +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
echo "PROJECT_NUMBER=${OSQUERY_BUILD_VERSION}" |
cat ${CMAKE_SOURCE_DIR}/Doxyfile - |
"${DOXYGEN_EXECUTABLE}" -;
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
# make format-all
2014-12-28 06:42:59 +00:00
add_custom_target(
format-all
find osquery include tools \( -name "*.h" -o -name "*.cpp" -o -name "*.mm" \)
2015-03-09 00:00:14 +00:00
-exec clang-format -i {} +
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMENT "Formatting all osquery code with clang-format" VERBATIM
2014-09-24 06:38:23 +00:00
)
2015-02-03 05:21:36 +00:00
# make format
2014-12-28 06:42:59 +00:00
add_custom_target(
format
python "${CMAKE_SOURCE_DIR}/tools/formatting/git-clang-format.py"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMENT "Formatting code staged code changes with clang-format" VERBATIM
)
# 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
)