osquery-1/osquery/CMakeLists.txt

287 lines
8.2 KiB
CMake
Raw Normal View History

2014-09-06 01:12:37 +00:00
SET(OSQUERY_LIBS
2014-09-23 02:27:19 +00:00
readline
pthread
dl
crypto
ssl
2014-09-06 01:12:37 +00:00
)
2014-11-09 00:55:19 +00:00
SET(OSQUERY_APPLE_LIBS
boost_thread-mt
boost_system
boost_filesystem
boost_program_options
boost_regex
thrift
rocksdb
gflags
glog
)
2014-11-13 06:33:27 +00:00
# Warning: Do not statically compile unwind
2014-11-09 00:55:19 +00:00
SET(OSQUERY_LINUX_LIBS
libgflags.a
libglog.a
librocksdb.a
libthrift.a
libboost_thread.a
libboost_system.a
libboost_filesystem.a
libboost_program_options.a
libboost_regex.a
2014-11-13 06:33:27 +00:00
unwind
2014-11-09 00:55:19 +00:00
udev
blkid
rt
)
SET(OSQUERY_UBUNTU_LIBS
libz.a
libbz2.a
libsnappy.a
liblzma.a
)
SET(OSQUERY_CENTOS_LIBS
libz.so
libbz2.so
libsnappy.so
liblzma.so
libproc.so
)
# Check for the explicit path to determine the version of procps
if(EXISTS "/usr/lib/libprocps.a"
OR EXISTS "/usr/lib/x86_64-linux-gnu/libprocps.a")
set(PROCPS TRUE)
endif()
2014-11-09 00:55:19 +00:00
# Fill in libraries for Apple, Uunbut, Centos
2014-09-06 01:12:37 +00:00
if(APPLE)
2014-11-09 00:55:19 +00:00
set(OSQUERY_LIBS ${OSQUERY_LIBS} ${OSQUERY_APPLE_LIBS})
2014-09-06 01:12:37 +00:00
else()
2014-11-09 00:55:19 +00:00
set(OSQUERY_LIBS ${OSQUERY_LIBS} ${OSQUERY_LINUX_LIBS})
if(UBUNTU)
if(PROCPS)
2014-11-09 00:55:19 +00:00
list(APPEND OSQUERY_UBUNTU_LIBS "libprocps.a")
else()
2014-11-09 00:55:19 +00:00
list(APPEND OSQUERY_UBUNTU_LIBS "libproc.a")
endif()
2014-11-09 00:55:19 +00:00
set(OSQUERY_LIBS ${OSQUERY_LIBS} ${OSQUERY_UBUNTU_LIBS})
elseif(CENTOS)
set(OSQUERY_LIBS ${OSQUERY_LIBS} ${OSQUERY_CENTOS_LIBS})
endif()
2014-09-06 01:12:37 +00:00
endif()
# Fill this in with objects for libosquery
2014-09-23 03:40:28 +00:00
set(OSQUERY_SOURCES "")
2014-09-06 01:12:37 +00:00
set(OSQUERY_ADDITIONAL_LINKS "")
if(NOT BUILD_SHARED)
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
endif()
2014-11-09 00:55:19 +00:00
# Generate version from git
execute_process(
COMMAND git describe --tags HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE OSQUERY_BUILD_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
ADD_DEFINITIONS("
-DOSQUERY_BUILD_VERSION=${OSQUERY_BUILD_VERSION}
-D${OSQUERY_BUILD_OS}
-D${OSQUERY_BUILD_OS}_${OSQUERY_BUILD_DISTRO}
")
2014-11-09 00:55:19 +00:00
2014-09-06 01:12:37 +00:00
MACRO(ADD_OSQUERY_LINK LINK)
list(APPEND OSQUERY_ADDITIONAL_LINKS ${LINK})
2014-09-23 03:40:28 +00:00
set(OSQUERY_ADDITIONAL_LINKS ${OSQUERY_ADDITIONAL_LINKS} PARENT_SCOPE)
2014-09-06 01:12:37 +00:00
ENDMACRO(ADD_OSQUERY_LINK)
MACRO(SET_OSQUERY_COMPILE TARGET)
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS ${OS_COMPILE_FLAGS})
SET(OPTIONAL_FLAGS ${ARGN})
LIST(LENGTH OPTIONAL_FLAGS NUM_OPTIONAL_FLAGS)
if(${NUM_OPTIONAL_FLAGS} GREATER 0)
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS ${OPTIONAL_FLAGS})
ENDIF()
ENDMACRO(SET_OSQUERY_COMPILE)
2014-09-23 03:40:28 +00:00
MACRO(ADD_OSQUERY_LIBRARY TARGET)
ADD_LIBRARY(${TARGET} OBJECT ${ARGN})
SET_OSQUERY_COMPILE(${TARGET})
list(APPEND OSQUERY_SOURCES $<TARGET_OBJECTS:${TARGET}>)
set(OSQUERY_SOURCES ${OSQUERY_SOURCES} PARENT_SCOPE)
ENDMACRO(ADD_OSQUERY_LIBRARY TARGET)
MACRO(ADD_OSQUERY_OBJCXX_LIBRARY TARGET)
ADD_LIBRARY(${TARGET} OBJECT ${ARGN})
SET_OSQUERY_COMPILE(${TARGET} "-x objective-c++ -fobjc-arc")
list(APPEND OSQUERY_SOURCES $<TARGET_OBJECTS:${TARGET}>)
set(OSQUERY_SOURCES ${OSQUERY_SOURCES} PARENT_SCOPE)
ENDMACRO(ADD_OSQUERY_OBJCXX_LIBRARY TARGET)
2014-09-23 02:54:59 +00:00
MACRO(ADD_OSQUERY_TEST TEST_NAME SOURCE)
2014-11-09 00:55:19 +00:00
if(NOT DEFINED ENV{SKIP_TESTS})
ADD_EXECUTABLE(${TEST_NAME} ${SOURCE})
TARGET_LINK_LIBRARIES(${TEST_NAME} osquery_shared)
TARGET_LINK_LIBRARIES(${TEST_NAME} gtest)
SET(OPTIONAL_FLAGS ${ARGN})
SET_OSQUERY_COMPILE(${TEST_NAME} ${OPTIONAL_FLAGS})
ADD_TEST(${TEST_NAME} ${TEST_NAME})
endif()
2014-09-06 01:12:37 +00:00
ENDMACRO(ADD_OSQUERY_TEST)
2014-09-10 04:37:08 +00:00
MACRO(ADD_OSQUERY_EXECUTABLE NAME SOURCE)
ADD_OSQUERY_TEST(${NAME} ${SOURCE})
TARGET_LINK_LIBRARIES(${NAME} osquery_shared)
ENDMACRO(ADD_OSQUERY_EXECUTABLE)
2014-09-06 01:12:37 +00:00
MACRO(TARGET_OSQUERY_LINK_WHOLE TARGET OSQUERY_LIB)
TARGET_LINK_LIBRARIES(${TARGET} "${OS_WHOLELINK_PRE}")
TARGET_LINK_LIBRARIES(${TARGET} ${OSQUERY_LIB})
2014-09-07 00:29:56 +00:00
TARGET_LINK_LIBRARIES(${TARGET} "${OS_WHOLELINK_POST}")
2014-09-06 01:12:37 +00:00
ENDMACRO(TARGET_OSQUERY_LINK_WHOLE)
2014-11-09 00:55:19 +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
)
# Table generation
file(GLOB TABLE_FILES "tables/specs/x/*.table")
if(APPLE)
file(GLOB TABLE_FILES_DARWIN "tables/specs/darwin/*.table")
list(APPEND TABLE_FILES ${TABLE_FILES_DARWIN})
else()
file(GLOB TABLE_FILES_LINUX "tables/specs/linux/*.table")
list(APPEND TABLE_FILES ${TABLE_FILES_LINUX})
endif()
SET(GENERATED_TABLE "")
foreach(TABLE_FILE ${TABLE_FILES})
SET(TABLE_FILE_GEN ${TABLE_FILE})
STRING(REPLACE "linux/" "" TABLE_FILE_GEN ${TABLE_FILE_GEN})
STRING(REPLACE "darwin/" "" TABLE_FILE_GEN ${TABLE_FILE_GEN})
STRING(REPLACE "x/" "" TABLE_FILE_GEN ${TABLE_FILE_GEN})
STRING(
REPLACE
"${CMAKE_SOURCE_DIR}/osquery/tables/specs"
"${CMAKE_BINARY_DIR}/generated/tables"
TABLE_FILE_GEN
${TABLE_FILE_GEN}
)
STRING(REPLACE ".table" ".cpp" TABLE_FILE_GEN ${TABLE_FILE_GEN})
ADD_CUSTOM_COMMAND(
OUTPUT ${TABLE_FILE_GEN}
2014-11-10 21:30:24 +00:00
COMMAND python ${CMAKE_SOURCE_DIR}/tools/gentable.py ${TABLE_FILE} ${TABLE_FILE_GEN} $ENV{DISABLE_BLACKLIST}
DEPENDS ${TABLE_FILE} ${CMAKE_SOURCE_DIR}/tools/gentable.py ${CMAKE_SOURCE_DIR}/osquery/tables/specs/blacklist
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
list(APPEND GENERATED_TABLES ${TABLE_FILE_GEN})
endforeach()
ADD_CUSTOM_TARGET(osquery_generated_tables_depends
DEPENDS ${GENERATED_TABLES}
)
ADD_LIBRARY(osquery_generated_tables OBJECT
${GENERATED_TABLES}
)
ADD_DEPENDENCIES(osquery_generated_tables osquery_generated_tables_depends)
SET_OSQUERY_COMPILE(osquery_generated_tables)
# Add subdirectories
ADD_SUBDIRECTORY(config)
ADD_SUBDIRECTORY(core)
ADD_SUBDIRECTORY(database)
ADD_SUBDIRECTORY(devtools)
2014-09-19 08:54:33 +00:00
ADD_SUBDIRECTORY(events)
2014-09-04 06:46:24 +00:00
ADD_SUBDIRECTORY(examples)
ADD_SUBDIRECTORY(filesystem)
ADD_SUBDIRECTORY(logger)
ADD_SUBDIRECTORY(dispatcher)
2014-09-06 01:12:37 +00:00
ADD_SUBDIRECTORY(registry)
ADD_SUBDIRECTORY(scheduler)
ADD_SUBDIRECTORY(tables)
2014-09-06 01:12:37 +00:00
SET(OSQUERY_LIB_OBJECTS
# Third-party objects
$<TARGET_OBJECTS:osquery_sqlite>
# Generated code
$<TARGET_OBJECTS:osquery_generated_tables>
2014-09-06 01:12:37 +00:00
# Build additional os-dependent libraries (may include tables)
2014-09-23 03:40:28 +00:00
${OSQUERY_SOURCES}
)
2014-11-09 00:55:19 +00:00
set(CMAKE_MACOSX_RPATH 0)
if(BUILD_SHARED)
ADD_LIBRARY(osquery_shared SHARED main/lib.cpp ${OSQUERY_LIB_OBJECTS})
else()
2014-09-06 01:12:37 +00:00
ADD_LIBRARY(osquery_static STATIC ${OSQUERY_LIB_OBJECTS})
SET_TARGET_PROPERTIES(osquery_static PROPERTIES OUTPUT_NAME osquery_static)
2014-09-12 16:39:43 +00:00
ADD_LIBRARY(osquery_shared STATIC main/lib.cpp)
2014-09-06 01:12:37 +00:00
TARGET_OSQUERY_LINK_WHOLE(osquery_shared osquery_static)
2014-11-09 00:55:19 +00:00
INSTALL(TARGETS osquery_static DESTINATION lib)
2014-09-06 01:12:37 +00:00
endif()
TARGET_LINK_LIBRARIES(osquery_shared ${OSQUERY_ADDITIONAL_LINKS})
TARGET_LINK_LIBRARIES(osquery_shared ${OSQUERY_LIBS})
SET_TARGET_PROPERTIES(osquery_shared PROPERTIES OUTPUT_NAME osquery)
INSTALL(TARGETS osquery_shared DESTINATION lib)
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include)
ADD_EXECUTABLE(shell main/shell.cpp)
2014-09-06 01:12:37 +00:00
TARGET_LINK_LIBRARIES(shell osquery_shared)
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME osqueryi)
2014-09-05 14:54:41 +00:00
SET_TARGET_PROPERTIES(shell PROPERTIES COMPILE_FLAGS ${OS_COMPILE_FLAGS})
INSTALL(TARGETS shell DESTINATION bin)
ADD_EXECUTABLE(daemon main/daemon.cpp)
2014-09-06 01:12:37 +00:00
TARGET_LINK_LIBRARIES(daemon osquery_shared)
SET_TARGET_PROPERTIES(daemon PROPERTIES OUTPUT_NAME osqueryd)
2014-09-05 14:54:41 +00:00
SET_TARGET_PROPERTIES(daemon PROPERTIES COMPILE_FLAGS ${OS_COMPILE_FLAGS})
INSTALL(TARGETS daemon DESTINATION bin)
2014-09-24 05:06:32 +00:00
# packages
if(NOT APPLE)
SET(CPACK_PACKAGE_NAME "osquery")
SET(CPACK_PACKAGE_VENDOR "facebook")
2014-11-09 00:55:19 +00:00
SET(CPACK_PACKAGE_VERSION "${OSQUERY_BUILD_VERSION}")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "osquery is an operating system instrumentation toolchain.")
EXECUTE_PROCESS(COMMAND uname -m OUTPUT_VARIABLE OSQUERY_ARCH)
STRING(REPLACE "\n" "" OSQUERY_ARCH ${OSQUERY_ARCH})
if(UBUNTU)
SET(CPACK_GENERATOR "DEB")
EXECUTE_PROCESS(COMMAND grep DISTRIB_CODENAME /etc/lsb-release OUTPUT_VARIABLE DISTRO)
STRING(REPLACE "DISTRIB_CODENAME=" "" DISTRO ${DISTRO})
STRING(REPLACE "\n" "" DISTRO ${DISTRO})
EXECUTE_PROCESS(COMMAND dpkg --print-architecture OUTPUT_VARIABLE DPKG_ARCH)
STRING(REPLACE "\n" "" DPKG_ARCH ${DPKG_ARCH})
SET(CPACK_SYSTEM_NAME "${DISTRO}.${DPKG_ARCH}")
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${DPKG_ARCH})
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "marpaia@fb.com")
endif()
INCLUDE(CPack)
endif()