2014-09-08 22:03:35 +00:00
|
|
|
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
|
2014-07-31 00:35:19 +00:00
|
|
|
PROJECT(OSQUERY)
|
|
|
|
|
2014-09-05 14:54:41 +00:00
|
|
|
if(APPLE)
|
2014-11-22 20:53:19 +00:00
|
|
|
set(APPLE_MIN_ABI "10.9")
|
|
|
|
set(OS_COMPILE_FLAGS "-std=c++11 -stdlib=libc++ -mmacosx-version-min=${APPLE_MIN_ABI}")
|
2014-09-06 01:12:37 +00:00
|
|
|
set(OS_WHOLELINK_PRE "-Wl,-all_load")
|
|
|
|
set(OS_WHOLELINK_POST "")
|
2014-09-05 14:54:41 +00:00
|
|
|
else()
|
2014-11-16 21:09:38 +00:00
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
|
|
|
set(FREEBSD TRUE)
|
|
|
|
set(OS_COMPILE_FLAGS "-std=c++11 -stdlib=libc++")
|
2014-11-18 21:03:13 +00:00
|
|
|
set(OS_WHOLELINK_PRE "")
|
|
|
|
set(OS_WHOLELINK_POST "")
|
2014-11-16 21:09:38 +00:00
|
|
|
else()
|
|
|
|
set(LINUX TRUE)
|
|
|
|
set(OS_COMPILE_FLAGS "-std=c++11")
|
2014-11-18 21:03:13 +00:00
|
|
|
set(OS_WHOLELINK_PRE "-Wl,-whole-archive")
|
|
|
|
set(OS_WHOLELINK_POST "-Wl,-no-whole-archive")
|
2014-11-16 21:09:38 +00:00
|
|
|
endif()
|
2014-11-09 10:07:49 +00:00
|
|
|
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
2014-11-12 20:52:04 +00:00
|
|
|
set(OS_COMPILE_FLAGS "${OS_COMPILE_FLAGS} -g -DDEBUG")
|
2014-11-09 10:07:49 +00:00
|
|
|
endif()
|
2014-09-06 01:12:37 +00:00
|
|
|
endif()
|
|
|
|
|
2014-11-12 05:34:59 +00:00
|
|
|
# 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
|
|
|
|
)
|
|
|
|
string(REPLACE "." "_" PLATFORM "${PLATFORM}")
|
|
|
|
string(TOUPPER "${PLATFORM}" PLATFORM)
|
|
|
|
list(GET PLATFORM 0 OSQUERY_BUILD_OS)
|
|
|
|
list(GET PLATFORM 1 OSQUERY_BUILD_DISTRO)
|
2014-10-29 10:38:21 +00:00
|
|
|
|
2014-11-11 15:55:04 +00:00
|
|
|
# Make sure deps were built before compiling
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
|
|
if(OSQUERY_DEPS_CHECK)
|
|
|
|
string(ASCII 27 Esc)
|
2014-11-11 15:59:42 +00:00
|
|
|
message(WARNING "${Esc}[31m${OSQUERY_DEPS_MESSAGE}${Esc}[m")
|
2014-11-11 15:55:04 +00:00
|
|
|
endif()
|
|
|
|
|
2014-11-12 05:34:59 +00:00
|
|
|
if(APPLE)
|
|
|
|
message("-- Building for OS X")
|
|
|
|
elseif(OSQUERY_BUILD_OS STREQUAL "UBUNTU")
|
|
|
|
set(UBUNTU TRUE)
|
|
|
|
message("-- Building for Ubuntu")
|
|
|
|
elseif(OSQUERY_BUILD_OS STREQUAL "CENTOS")
|
|
|
|
set(CENTOS TRUE)
|
|
|
|
message("-- Building for CentOS")
|
2014-11-06 11:15:04 +00:00
|
|
|
elseif(FREEBSD)
|
|
|
|
message("-- Building for FreeBSD")
|
2014-11-12 05:34:59 +00:00
|
|
|
endif()
|
|
|
|
|
2014-09-23 04:29:44 +00:00
|
|
|
if(BUILD_SHARED_LIBS)
|
2014-09-21 01:53:49 +00:00
|
|
|
set(USER_COMPILE_FLAGS "-fPIC")
|
2014-09-23 00:27:57 +00:00
|
|
|
else()
|
2014-09-23 04:29:44 +00:00
|
|
|
# Building/linking statically (no libosquery)
|
2014-09-23 03:40:28 +00:00
|
|
|
set(USER_COMPILE_FLAGS "-static")
|
2014-09-05 14:54:41 +00:00
|
|
|
endif()
|
|
|
|
|
2014-09-06 01:12:37 +00:00
|
|
|
set(OS_COMPILE_FLAGS "${OS_COMPILE_FLAGS} ${USER_COMPILE_FLAGS}")
|
|
|
|
|
|
|
|
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
|
|
|
|
FIND_PACKAGE(Gtest REQUIRED)
|
|
|
|
FIND_PACKAGE(Sqlite3 REQUIRED)
|
2014-09-24 02:44:58 +00:00
|
|
|
FIND_PACKAGE(BZip2 REQUIRED)
|
|
|
|
FIND_PACKAGE(Glog REQUIRED)
|
|
|
|
FIND_PACKAGE(Gflags REQUIRED)
|
|
|
|
FIND_PACKAGE(Thrift 0.9.1 REQUIRED)
|
|
|
|
FIND_PACKAGE(Readline REQUIRED)
|
|
|
|
FIND_PACKAGE(OpenSSL REQUIRED)
|
|
|
|
FIND_PACKAGE(Snappy REQUIRED)
|
|
|
|
FIND_PACKAGE(RocksDB REQUIRED)
|
|
|
|
FIND_PACKAGE(Crypto REQUIRED)
|
|
|
|
FIND_PACKAGE(Dl REQUIRED)
|
|
|
|
if(NOT APPLE)
|
|
|
|
FIND_PACKAGE(Unwind REQUIRED)
|
|
|
|
FIND_PACKAGE(LZMA REQUIRED)
|
|
|
|
endif()
|
2014-09-06 01:12:37 +00:00
|
|
|
|
2014-09-24 05:06:32 +00:00
|
|
|
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include")
|
|
|
|
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}")
|
|
|
|
INCLUDE_DIRECTORIES("/usr/local/include")
|
|
|
|
LINK_DIRECTORIES("/usr/local/lib")
|
|
|
|
|
|
|
|
ENABLE_TESTING()
|
|
|
|
|
|
|
|
ADD_SUBDIRECTORY(osquery)
|
|
|
|
ADD_SUBDIRECTORY(tools)
|
|
|
|
|
2014-09-24 03:12:53 +00:00
|
|
|
# make docs
|
|
|
|
FIND_PACKAGE(Doxygen)
|
|
|
|
if(DOXYGEN_FOUND)
|
|
|
|
ADD_CUSTOM_TARGET(
|
|
|
|
docs
|
|
|
|
${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Doxyfile
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
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-09-24 06:38:23 +00:00
|
|
|
ADD_CUSTOM_TARGET(
|
2014-11-02 19:30:56 +00:00
|
|
|
format-all
|
2014-09-24 06:38:23 +00:00
|
|
|
find osquery include tools \( -name "*.h" -o -name "*.cpp" -o -name "*.mm" \) -exec clang-format -i {} +
|
|
|
|
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
|
|
|
|
|
|
|
ADD_CUSTOM_TARGET(
|
|
|
|
format
|
|
|
|
python tools/git-clang-format.py
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
COMMENT "Formatting code staged code changes with clang-format" VERBATIM
|
|
|
|
)
|
|
|
|
|