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
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
# Set expected directory for within-build dependencies
|
|
|
|
if(DEFINED ENV{OSQUERY_DEPS})
|
|
|
|
set(BUILD_DEPS "$ENV{OSQUERY_DEPS}")
|
|
|
|
else()
|
|
|
|
set(BUILD_DEPS "/usr/local/osquery")
|
|
|
|
endif()
|
|
|
|
|
2016-08-10 21:06:47 +00:00
|
|
|
if(WIN32)
|
|
|
|
set(WINDOWS_DEP_DIR "$ENV{ChocolateyInstall}/lib")
|
|
|
|
string(REGEX REPLACE "\\\\" "/" WINDOWS_DEP_DIR ${WINDOWS_DEP_DIR})
|
|
|
|
list(APPEND WINDOWS_DEP_LIST ${WINDOWS_DEP_DIR})
|
|
|
|
|
|
|
|
list(APPEND CMAKE_PROGRAM_PATH "${WINDOWS_DEP_DIR}/*/tools")
|
|
|
|
endif()
|
|
|
|
|
2015-05-27 23:50:57 +00:00
|
|
|
# If no explicit compiler override and clang++ exists, prefer clang.
|
2016-08-14 05:06:42 +00:00
|
|
|
find_program(CLANGXX_EXECUTABLE "clang++" ENV PATH)
|
2015-05-27 23:50:57 +00:00
|
|
|
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}")
|
2016-08-14 05:06:42 +00:00
|
|
|
elseif(CLANGXX_EXECUTABLE)
|
2015-05-27 23:50:57 +00:00
|
|
|
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}")
|
2016-08-14 05:06:42 +00:00
|
|
|
elseif(CLANGXX_EXECUTABLE)
|
2015-05-27 23:50:57 +00:00
|
|
|
set(CMAKE_CXX_COMPILER "clang++")
|
2015-05-07 04:58:23 +00:00
|
|
|
endif()
|
|
|
|
|
2016-08-14 05:06:42 +00:00
|
|
|
find_program(CCACHE_EXECUTABLE ccache ENV PATH)
|
|
|
|
if(CCACHE_EXECUTABLE)
|
2016-07-31 18:32:31 +00:00
|
|
|
if(NOT DEFINED CCACHE_FOUND_LOG)
|
|
|
|
set(CCACHE_FOUND_LOG TRUE CACHE BOOL "Write log line for ccache.")
|
2016-08-14 05:06:42 +00:00
|
|
|
LOG("Found ccache ${CCACHE_EXECUTABLE}")
|
2016-07-31 18:32:31 +00:00
|
|
|
LOG("Using ccache to speed up compilation")
|
|
|
|
endif()
|
2016-07-01 01:41:32 +00:00
|
|
|
set(ENV{CCACHE_CPP2} "yes")
|
2016-08-14 05:06:42 +00:00
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_EXECUTABLE}")
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_EXECUTABLE}")
|
|
|
|
endif()
|
2016-06-29 17:18:52 +00:00
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
if(NOT WIN32)
|
2016-04-15 21:01:16 +00:00
|
|
|
add_compile_options(
|
2016-07-01 01:41:32 +00:00
|
|
|
-Qunused-arguments
|
2016-04-15 21:01:16 +00:00
|
|
|
-Wstrict-aliasing
|
|
|
|
-Wno-missing-field-initializers
|
|
|
|
-Wno-unused-local-typedef
|
2016-07-31 18:32:31 +00:00
|
|
|
-Wno-deprecated-register
|
2016-04-15 21:01:16 +00:00
|
|
|
-Wno-unknown-warning-option
|
|
|
|
-Wnon-virtual-dtor
|
|
|
|
-Wchar-subscripts
|
|
|
|
-Wpointer-arith
|
|
|
|
-Woverloaded-virtual
|
|
|
|
-Wformat
|
|
|
|
-Wformat-security
|
|
|
|
-Werror=format-security
|
|
|
|
-Wabi-tag
|
2016-06-30 03:15:58 +00:00
|
|
|
-fpermissive
|
2016-04-15 21:01:16 +00:00
|
|
|
-fstack-protector-all
|
|
|
|
-pipe
|
|
|
|
-fdata-sections
|
|
|
|
-ffunction-sections
|
|
|
|
)
|
|
|
|
endif()
|
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
|
|
|
|
2016-12-17 02:12:02 +00:00
|
|
|
find_program(PYTHON_EXECUTABLE "python" ${BUILD_DEPS} ENV PATH)
|
|
|
|
find_program(THRIFT_COMPILER "thrift" ${BUILD_DEPS} ENV PATH)
|
2016-07-31 18:32:31 +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(
|
2016-08-14 05:06:42 +00:00
|
|
|
COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/tools/get_platform.py"
|
2015-05-13 07:31:02 +00:00
|
|
|
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 "")
|
2016-04-15 21:01:16 +00:00
|
|
|
WARNING_LOG("Unable to detect osquery platform: ./tools/get_platform.py 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
|
|
|
)
|
|
|
|
|
2017-01-07 20:21:35 +00:00
|
|
|
set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} -std=c++14 -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.
|
2016-06-24 15:47:48 +00:00
|
|
|
set(OS_WHOLELINK_PRE "-WHOLEARCHIVE:")
|
|
|
|
set(OS_WHOLELINK_POST "")
|
2016-08-10 03:27:42 +00:00
|
|
|
set(WINDOWS TRUE)
|
2014-09-05 14:54:41 +00:00
|
|
|
else()
|
2015-02-13 10:45:43 +00:00
|
|
|
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)
|
2017-02-27 02:25:49 +00:00
|
|
|
include_directories("/usr/local/include")
|
|
|
|
include_directories("/usr/include")
|
|
|
|
set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} -std=c++14 -stdlib=libc++")
|
2015-05-07 04:58:23 +00:00
|
|
|
else()
|
|
|
|
set(LINUX TRUE)
|
2017-02-27 02:25:49 +00:00
|
|
|
set(CXX_COMPILE_FLAGS "${CXX_COMPILE_FLAGS} -std=c++14 -stdlib=libstdc++")
|
2015-05-07 04:58:23 +00:00
|
|
|
endif()
|
2014-12-25 20:46:59 +00:00
|
|
|
endif()
|
|
|
|
|
2017-01-22 09:51:56 +00:00
|
|
|
if(LINUX AND CMAKE_CXX_COMPILER MATCHES "clang")
|
|
|
|
# Use the LLVM versions of ar and ranlib to support LTO builds
|
|
|
|
find_program(LLVMRANLIB_EXECUTABLE "llvm-ranlib" ENV PATH)
|
|
|
|
find_program(LLVMAR_EXECUTABLE "llvm-ar" ENV PATH)
|
|
|
|
set(CMAKE_AR "${LLVMAR_EXECUTABLE}")
|
|
|
|
set(CMAKE_RANLIB "${LLVMRANLIB_EXECUTABLE}")
|
|
|
|
set(CMAKE_C_ARCHIVE_CREATE "${LLVMAR_EXECUTABLE} qc <TARGET> <LINK_FLAGS> <OBJECTS>")
|
|
|
|
set(CMAKE_CXX_ARCHIVE_CREATE "${LLVMAR_EXECUTABLE} qc <TARGET> <LINK_FLAGS> <OBJECTS>")
|
|
|
|
set(CMAKE_C_ARCHIVE_FINISH "${LLVMRANLIB_EXECUTABLE} <TARGET>")
|
|
|
|
set(CMAKE_CXX_ARCHIVE_FINISH "${CMAKE_C_ARCHIVE_FINISH}")
|
|
|
|
endif()
|
|
|
|
|
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-08-10 21:06:47 +00:00
|
|
|
if(WINDOWS)
|
2016-04-15 21:01:16 +00:00
|
|
|
# TODO(#1985): Is there a MSVC flag congruent to -fstandalone-debug?
|
|
|
|
add_compile_options(
|
|
|
|
/Zi
|
2016-07-01 01:41:32 +00:00
|
|
|
/Od
|
2016-04-15 21:01:16 +00:00
|
|
|
)
|
|
|
|
else()
|
|
|
|
add_compile_options(
|
|
|
|
-g
|
|
|
|
-O0
|
|
|
|
-fstandalone-debug
|
|
|
|
)
|
|
|
|
endif()
|
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-09-21 22:15:25 +00:00
|
|
|
set(SANITIZE_BLACKLIST "${CMAKE_SOURCE_DIR}/tools/analysis/sanitize_blacklist.txt")
|
2016-03-05 17:29:51 +00:00
|
|
|
add_compile_options(
|
|
|
|
-g
|
|
|
|
-fstandalone-debug
|
|
|
|
-fno-omit-frame-pointer
|
|
|
|
-fno-optimize-sibling-calls
|
2016-09-21 17:52:52 +00:00
|
|
|
-fsanitize-blacklist=${SANITIZE_BLACKLIST}
|
2016-03-05 17:29:51 +00:00
|
|
|
)
|
2016-09-21 17:52:52 +00:00
|
|
|
if (DEFINED ENV{SANITIZE_THREAD})
|
2015-05-04 03:02:01 +00:00
|
|
|
add_compile_options(-fsanitize=thread)
|
|
|
|
else()
|
2016-11-18 07:39:07 +00:00
|
|
|
add_compile_options(-fsanitize=address)
|
|
|
|
if(LINUX)
|
|
|
|
# LSAN is not available on OS X 10.12.
|
|
|
|
add_compile_options(-fsanitize=leak)
|
|
|
|
endif()
|
2015-05-04 03:02:01 +00:00
|
|
|
endif()
|
2014-12-25 20:46:59 +00:00
|
|
|
else()
|
2015-05-04 21:15:19 +00:00
|
|
|
set(DEBUG FALSE)
|
2016-08-10 21:06:47 +00:00
|
|
|
if(WINDOWS)
|
2016-04-15 21:01:16 +00:00
|
|
|
add_compile_options(/Ot)
|
|
|
|
else()
|
|
|
|
add_compile_options(-Os)
|
|
|
|
endif()
|
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")
|
2016-08-01 05:41:37 +00:00
|
|
|
|
2016-08-10 21:06:47 +00:00
|
|
|
# Visual Studio does not support generation of PIC code
|
|
|
|
if(NOT WINDOWS)
|
|
|
|
# TSAN and MSAN do not like PIE/PIC on Linux 4.1.
|
|
|
|
# To be safe, only include them when building 'release' outputs.
|
|
|
|
add_compile_options(
|
|
|
|
-fPIE
|
|
|
|
-fpie
|
|
|
|
-fPIC
|
|
|
|
-fpic
|
|
|
|
)
|
2017-02-27 02:25:49 +00:00
|
|
|
if (CMAKE_CXX_COMPILER MATCHES "clang" AND NOT FREEBSD)
|
2017-02-01 16:03:16 +00:00
|
|
|
# Only enale LTO builds when using clang on Unix, for now
|
2017-02-15 15:54:03 +00:00
|
|
|
add_compile_options(-flto)
|
2017-02-01 16:03:16 +00:00
|
|
|
endif()
|
2016-08-10 21:06:47 +00:00
|
|
|
endif()
|
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})
|
2016-08-10 21:06:47 +00:00
|
|
|
if(WINDOWS)
|
2016-07-01 01:41:32 +00:00
|
|
|
# It is unclear if AVX must be managed on Windows.
|
2016-07-21 06:48:55 +00:00
|
|
|
add_compile_options(/favor:AMD64)
|
2016-04-15 21:01:16 +00:00
|
|
|
else()
|
|
|
|
add_compile_options(-march=x86-64 -mno-avx)
|
|
|
|
endif()
|
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})
|
2016-07-31 18:32:31 +00:00
|
|
|
# TODO(#1985): clang-analyze on Windows
|
2016-08-10 21:06:47 +00:00
|
|
|
if(WINDOWS)
|
2016-04-15 21:01:16 +00:00
|
|
|
message(FATAL_ERROR "Cannot analyze on Windows right now." )
|
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_COMPILER "${CMAKE_SOURCE_DIR}/tools/analysis/clang-analyze.sh")
|
|
|
|
endif()
|
2015-01-31 11:09:30 +00:00
|
|
|
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()
|
|
|
|
|
2016-08-13 02:25:28 +00:00
|
|
|
if(DEFINED ENV{FAST})
|
|
|
|
set(ENV{OSQUERY_BUILD_SHARED} TRUE)
|
|
|
|
endif()
|
|
|
|
|
2015-05-04 21:15:19 +00:00
|
|
|
# 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
|
|
|
|
2016-08-22 22:27:12 +00:00
|
|
|
if(WINDOWS)
|
|
|
|
foreach(flag_var
|
|
|
|
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
|
|
|
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
|
|
|
|
if(${flag_var} MATCHES "/MD")
|
|
|
|
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
|
|
|
endif(${flag_var} MATCHES "/MD")
|
2016-09-21 17:52:52 +00:00
|
|
|
|
2016-09-02 22:04:03 +00:00
|
|
|
# Ignore unused parameter messages for C-based projects (e.g. sqlite3)
|
|
|
|
if (flag_var MATCHES "^CMAKE_C_FLAGS*")
|
|
|
|
set(${flag_var} "${${flag_var}} /wd4101")
|
|
|
|
endif(flag_var MATCHES "^CMAKE_C_FLAGS*")
|
2016-08-22 22:27:12 +00:00
|
|
|
endforeach(flag_var)
|
2016-09-21 17:52:52 +00:00
|
|
|
|
2016-09-02 22:04:03 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG")
|
2017-02-27 02:25:49 +00:00
|
|
|
elseif(NOT FREEBSD)
|
2017-01-22 09:51:56 +00:00
|
|
|
if (CMAKE_CXX_COMPILER MATCHES "clang")
|
|
|
|
# Clang on Unix uses LTO; we also need to pass -flto when linking
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
|
2017-02-15 15:54:03 +00:00
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto")
|
2017-01-22 09:51:56 +00:00
|
|
|
endif()
|
|
|
|
|
2016-08-22 22:27:12 +00:00
|
|
|
endif()
|
|
|
|
|
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
|
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)
|
|
|
|
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)
|
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)
|
2015-05-23 22:43:54 +00:00
|
|
|
LOG_PLATFORM("CentOS")
|
2016-03-30 06:41:52 +00:00
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "scientific")
|
|
|
|
set(REDHAT_BASED TRUE)
|
|
|
|
LOG_PLATFORM("Scientific Linux")
|
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-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-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)
|
2015-05-23 22:43:54 +00:00
|
|
|
LOG_PLATFORM("Oracle Linux")
|
2016-11-22 22:55:30 +00:00
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "gentoo")
|
|
|
|
set(GENTOO_BASED TRUE)
|
|
|
|
LOG_PLATFORM("Gentoo Linux")
|
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "funtoo")
|
|
|
|
set(GENTOO_BASED TRUE)
|
|
|
|
LOG_PLATFORM("Funtoo Linux")
|
2015-05-05 20:55:49 +00:00
|
|
|
elseif(OSQUERY_BUILD_PLATFORM STREQUAL "freebsd")
|
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")
|
|
|
|
LOG_PLATFORM("Windows")
|
2015-04-30 22:47:33 +00:00
|
|
|
endif()
|
|
|
|
|
2016-03-30 06:41:52 +00:00
|
|
|
if("${OSQUERY_BUILD_DISTRO}" MATCHES "^(centos|rhel|scientific|oracle)7$")
|
2016-03-15 02:51:03 +00:00
|
|
|
# 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)
|
2016-11-22 22:55:30 +00:00
|
|
|
elseif(GENTOO_BASED)
|
|
|
|
add_definitions(-DGENTOO_BASED=1)
|
2014-11-12 05:34:59 +00:00
|
|
|
endif()
|
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
# Add sysroot overrides for each platform/distro.
|
|
|
|
# These should be prioritized over all other includes.
|
|
|
|
if(APPLE)
|
|
|
|
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/third-party/sysroots/darwin")
|
|
|
|
elseif(LINUX)
|
|
|
|
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/third-party/sysroots/linux")
|
|
|
|
endif()
|
|
|
|
|
2016-08-10 21:06:47 +00:00
|
|
|
if(NOT WINDOWS)
|
2016-07-31 18:32:31 +00:00
|
|
|
include_directories(SYSTEM "${BUILD_DEPS}/legacy/include")
|
|
|
|
include_directories(SYSTEM "${BUILD_DEPS}/include")
|
|
|
|
include_directories("${BUILD_DEPS}/include/openssl")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
include_directories("${CMAKE_SOURCE_DIR}/third-party/sqlite3")
|
|
|
|
include_directories("${CMAKE_SOURCE_DIR}/include")
|
|
|
|
include_directories("${CMAKE_SOURCE_DIR}")
|
|
|
|
|
2016-04-15 21:01:16 +00:00
|
|
|
set(MKDIR_OPTS "")
|
2016-08-10 21:06:47 +00:00
|
|
|
if(WINDOWS)
|
2016-05-31 19:20:38 +00:00
|
|
|
set(PROCESS_FAMILY "windows")
|
2016-07-01 01:41:32 +00:00
|
|
|
|
2016-04-15 21:01:16 +00:00
|
|
|
# Win64 specific gflags
|
2016-09-12 16:46:52 +00:00
|
|
|
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build static gtest/gmock library" FORCE)
|
2016-07-01 01:41:32 +00:00
|
|
|
|
2016-08-10 21:06:47 +00:00
|
|
|
file(GLOB INCLUDE_DIRS LIST_DIRECTORIES true "${WINDOWS_DEP_DIR}/*/*/include")
|
|
|
|
include_directories(${INCLUDE_DIRS})
|
2016-09-20 21:18:58 +00:00
|
|
|
include_directories("${WINDOWS_DEP_DIR}/boost-msvc14/local")
|
2016-11-06 09:17:48 +00:00
|
|
|
|
2016-08-10 21:06:47 +00:00
|
|
|
## TODO(FIXME): temporary for now
|
2016-06-24 15:47:48 +00:00
|
|
|
include_directories("${WINDOWS_DEP_DIR}/linenoise-ng/local/include/linenoise")
|
|
|
|
include_directories("${WINDOWS_DEP_DIR}/snappy-msvc/tools/snappy-windows-1.1.1.8/include")
|
2016-04-15 21:01:16 +00:00
|
|
|
else()
|
2016-07-31 18:32:31 +00:00
|
|
|
set(PROCESS_FAMILY "posix")
|
|
|
|
set(MKDIR_OPTS "-p")
|
2016-04-15 21:01:16 +00:00
|
|
|
endif()
|
2014-09-24 05:06:32 +00:00
|
|
|
|
2016-08-10 21:06:47 +00:00
|
|
|
if(WINDOWS)
|
|
|
|
foreach(DEP_DIR ${WINDOWS_DEP_LIST})
|
|
|
|
file(GLOB_RECURSE WINDOWS_LOCAL_LIB_DIRS LIST_DIRECTORIES false "${DEP_DIR}/*.lib")
|
|
|
|
foreach(LIB_FILE ${WINDOWS_LOCAL_LIB_DIRS})
|
|
|
|
get_filename_component(LIB_DIR ${LIB_FILE} DIRECTORY)
|
|
|
|
list(APPEND OS_LIB_DIRS ${LIB_DIR})
|
|
|
|
endforeach()
|
|
|
|
endforeach()
|
|
|
|
list(REMOVE_DUPLICATES OS_LIB_DIRS)
|
|
|
|
link_directories(${OS_LIB_DIRS})
|
|
|
|
else()
|
|
|
|
set(OS_LIB_DIRS
|
|
|
|
"/lib"
|
|
|
|
"/lib64"
|
|
|
|
"/usr/lib"
|
|
|
|
"/usr/lib64"
|
|
|
|
"/usr/lib/x86_64-linux-gnu/"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
# Make sure the generated paths exist
|
|
|
|
execute_process(COMMAND mkdir ${MKDIR_OPTS} "${CMAKE_BINARY_DIR}/generated")
|
2016-02-23 22:15:23 +00:00
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
# We need to link some packages as dynamic/dependent.
|
2016-08-10 21:06:47 +00:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dylib .so .a)
|
2017-02-15 15:54:03 +00:00
|
|
|
set(CMAKE_SKIP_RPATH TRUE)
|
2016-07-31 18:32:31 +00:00
|
|
|
|
2017-02-27 02:25:49 +00:00
|
|
|
# FreeBSD does not use the osquery build system, link discovered libraries.
|
|
|
|
if(FREEBSD)
|
|
|
|
set(ENV{BUILD_LINK_SHARED} TRUE)
|
|
|
|
endif()
|
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
# Most dependent packages/libs we want static.
|
|
|
|
if(DEFINED ENV{BUILD_LINK_SHARED})
|
|
|
|
set(ENV{OSQUERY_BUILD_LINK_SHARED} TRUE)
|
2015-05-09 02:10:43 +00:00
|
|
|
endif()
|
2016-07-31 18:32:31 +00:00
|
|
|
if(NOT DEFINED ENV{OSQUERY_BUILD_LINK_SHARED})
|
2016-08-10 21:06:47 +00:00
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a .dylib .so)
|
2016-07-31 18:32:31 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Previously, this would find_package for Gtest.
|
|
|
|
# We can supply the known include paths within each test as compile flags.
|
|
|
|
enable_testing()
|
2016-09-20 21:19:21 +00:00
|
|
|
set(CTEST_TEST_TIMEOUT 600)
|
|
|
|
|
2016-08-10 03:27:42 +00:00
|
|
|
# Detect TR1 usage.
|
|
|
|
include(CheckIncludeFileCXX)
|
2016-09-12 16:46:52 +00:00
|
|
|
if(WINDOWS)
|
|
|
|
check_include_file_cxx("tuple" HAVE_TR1_TUPLE)
|
|
|
|
else()
|
|
|
|
check_include_file_cxx("tr1/tuple" HAVE_TR1_TUPLE)
|
|
|
|
endif()
|
|
|
|
|
2016-08-10 03:27:42 +00:00
|
|
|
if("${HAVE_TR1_TUPLE}" STREQUAL "")
|
|
|
|
set(GTEST_FLAGS "-DGTEST_USE_OWN_TR1_TUPLE=1")
|
|
|
|
else()
|
|
|
|
set(GTEST_FLAGS "-DGTEST_USE_OWN_TR1_TUPLE=0")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(GTEST_FLAGS
|
|
|
|
${GTEST_FLAGS}
|
|
|
|
"-I${CMAKE_SOURCE_DIR}/third-party/gtest-1.7.0/include"
|
|
|
|
"-I${CMAKE_SOURCE_DIR}/third-party/gmock-1.7.0/include"
|
2016-09-12 16:46:52 +00:00
|
|
|
"-I${CMAKE_SOURCE_DIR}/third-party/gmock-1.7.0/gtest/include"
|
2016-08-10 03:27:42 +00:00
|
|
|
)
|
|
|
|
join("${GTEST_FLAGS}" " " GTEST_FLAGS)
|
2016-07-31 18:32:31 +00:00
|
|
|
|
|
|
|
include(Thrift)
|
2015-05-09 02:10:43 +00:00
|
|
|
|
2016-02-24 01:07:24 +00:00
|
|
|
add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/sqlite3")
|
2016-07-31 18:32:31 +00:00
|
|
|
add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/gmock-1.7.0")
|
|
|
|
|
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
|
|
|
|
2016-07-21 00:21:20 +00:00
|
|
|
# Packages must be included after all other CMake includes.
|
2016-08-09 21:44:48 +00:00
|
|
|
if(NOT ${OSQUERY_BUILD_SDK_ONLY})
|
|
|
|
include(Packages)
|
|
|
|
endif()
|
2016-07-21 00:21:20 +00:00
|
|
|
|
2014-09-24 03:12:53 +00:00
|
|
|
# make docs
|
2016-08-14 05:06:42 +00:00
|
|
|
add_custom_target(
|
|
|
|
docs
|
|
|
|
COMMAND "${PYTHON_EXECUTABLE}"
|
|
|
|
"${CMAKE_SOURCE_DIR}/tools/codegen/genapi.py" "${CMAKE_SOURCE_DIR}"
|
|
|
|
"--output" "--directory" "${CMAKE_SOURCE_DIR}/build/docs"
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
COMMENT "Generating API documentation with Doxygen/mkdocs" VERBATIM
|
|
|
|
)
|
|
|
|
|
|
|
|
find_program(DOXYGEN_EXECUTABLE doxygen ENV PATH)
|
|
|
|
if(DOXYGEN_EXECUTABLE)
|
|
|
|
add_custom_command(TARGET docs POST_BUILD
|
2015-07-16 19:23:44 +00:00
|
|
|
COMMAND echo "PROJECT_NUMBER=${OSQUERY_BUILD_VERSION}" |
|
2016-08-14 05:06:42 +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
|
|
|
)
|
2016-08-14 05:06:42 +00:00
|
|
|
else(DEFINED ENV{DOCS})
|
|
|
|
WARNING_LOG("Cannot find Doxygen executable in path")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_program(MKDOCS_EXECUTABLE mkdocs ENV PATH)
|
|
|
|
if(MKDOCS_EXECUTABLE)
|
|
|
|
add_custom_command(TARGET docs POST_BUILD
|
|
|
|
COMMAND "${MKDOCS_EXECUTABLE}" build --clean -s
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
)
|
|
|
|
elseif(DEFINED ENV{DOCS})
|
|
|
|
WARNING_LOG("Cannot find mkdocs executable in path")
|
|
|
|
endif()
|
2014-09-24 06:38:23 +00:00
|
|
|
|
2014-11-02 19:30:56 +00:00
|
|
|
# make format-all
|
2016-08-14 05:06:42 +00:00
|
|
|
find_program(CLANGFORMAT_EXECUTABLE "clang-format" ENV PATH)
|
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" \)
|
2016-08-14 05:06:42 +00:00
|
|
|
-exec "${CLANGFORMAT_EXECUTABLE}" -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
|
2016-08-15 08:33:17 +00:00
|
|
|
"${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/tools/formatting/git-clang-format.py" "-f"
|
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
|
|
|
)
|