2014-09-06 01:12:37 +00:00
|
|
|
SET(OSQUERY_LIBS
|
2014-09-23 02:27:19 +00:00
|
|
|
readline
|
|
|
|
pthread
|
2014-09-06 01:12:37 +00:00
|
|
|
)
|
|
|
|
|
2014-11-09 00:55:19 +00:00
|
|
|
SET(OSQUERY_APPLE_LIBS
|
2014-12-09 21:40:53 +00:00
|
|
|
/usr/local/lib/libboost_thread-mt.a
|
|
|
|
/usr/local/lib/libboost_system.a
|
|
|
|
/usr/local/lib/libboost_filesystem.a
|
|
|
|
/usr/local/lib/libboost_program_options.a
|
|
|
|
/usr/local/lib/libboost_regex.a
|
|
|
|
/usr/local/lib/libthrift.a
|
|
|
|
/usr/local/lib/librocksdb.a
|
|
|
|
/usr/local/lib/libsnappy.a
|
|
|
|
/usr/local/lib/liblz4.a
|
|
|
|
/usr/local/lib/libgflags.a
|
|
|
|
/usr/local/lib/libglog.a
|
2014-12-16 09:15:58 +00:00
|
|
|
/usr/local/opt/openssl/lib/libcrypto.a
|
|
|
|
/usr/local/opt/openssl/lib/libssl.a
|
2014-11-13 20:00:41 +00:00
|
|
|
dl
|
2014-12-09 21:40:53 +00:00
|
|
|
bz2
|
|
|
|
z
|
2014-11-09 00:55:19 +00:00
|
|
|
)
|
|
|
|
|
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-12-23 19:39:03 +00:00
|
|
|
|
|
|
|
bz2
|
2014-12-16 09:15:58 +00:00
|
|
|
crypto
|
2014-12-23 19:39:03 +00:00
|
|
|
dl
|
|
|
|
rt
|
2014-12-16 09:15:58 +00:00
|
|
|
ssl
|
2014-12-23 19:39:03 +00:00
|
|
|
unwind
|
|
|
|
z
|
2014-11-09 00:55:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
SET(OSQUERY_UBUNTU_LIBS
|
|
|
|
libsnappy.a
|
|
|
|
liblzma.a
|
|
|
|
)
|
|
|
|
|
|
|
|
SET(OSQUERY_CENTOS_LIBS
|
|
|
|
libsnappy.so
|
|
|
|
liblzma.so
|
|
|
|
)
|
|
|
|
|
2014-11-13 20:00:41 +00:00
|
|
|
SET(OSQUERY_FREEBSD_LIBS
|
2014-11-18 21:03:13 +00:00
|
|
|
gflags
|
|
|
|
glog
|
|
|
|
rocksdb
|
|
|
|
thrift
|
|
|
|
boost_thread
|
|
|
|
boost_system
|
|
|
|
boost_filesystem
|
|
|
|
boost_program_options
|
|
|
|
boost_regex
|
2014-12-23 19:39:03 +00:00
|
|
|
|
2014-11-18 21:03:13 +00:00
|
|
|
bz2
|
2014-12-16 09:15:58 +00:00
|
|
|
crypto
|
2014-12-23 19:39:03 +00:00
|
|
|
lzma
|
|
|
|
rt
|
|
|
|
snappy
|
2014-12-16 09:15:58 +00:00
|
|
|
ssl
|
2014-12-23 19:39:03 +00:00
|
|
|
unwind
|
|
|
|
z
|
2014-11-13 20:00:41 +00:00
|
|
|
)
|
|
|
|
|
2014-10-29 10:38:21 +00:00
|
|
|
# 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")
|
2014-12-23 19:39:03 +00:00
|
|
|
set(PROCPS True)
|
2014-12-03 23:14:02 +00:00
|
|
|
else()
|
2014-12-23 19:39:03 +00:00
|
|
|
set(PROCPS False)
|
2014-10-29 10:38:21 +00:00
|
|
|
endif()
|
|
|
|
|
2014-09-06 01:12:37 +00:00
|
|
|
# Fill this in with objects for libosquery
|
2014-09-23 03:40:28 +00:00
|
|
|
set(OSQUERY_SOURCES "")
|
2014-12-23 22:35:48 +00:00
|
|
|
# Fill this in with links and linker options for libosquery
|
|
|
|
set(OSQUERY_LINKS "")
|
|
|
|
# Fill this in in with non-core links and linker options (for tables)
|
|
|
|
set(OSQUERY_ADDITIONAL_SOURCES "")
|
2014-09-06 01:12:37 +00:00
|
|
|
set(OSQUERY_ADDITIONAL_LINKS "")
|
|
|
|
|
2014-12-23 22:35:48 +00:00
|
|
|
set(Boost_USE_STATIC_LIBS ON)
|
2014-10-29 10:38:21 +00:00
|
|
|
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(
|
2014-12-09 17:52:36 +00:00
|
|
|
COMMAND git describe --tags HEAD --always
|
2014-12-03 23:14:02 +00:00
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
2014-11-09 00:55:19 +00:00
|
|
|
OUTPUT_VARIABLE OSQUERY_BUILD_VERSION
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
2014-11-12 05:34:59 +00:00
|
|
|
ADD_DEFINITIONS("
|
|
|
|
-DOSQUERY_BUILD_VERSION=${OSQUERY_BUILD_VERSION}
|
2014-11-12 20:52:04 +00:00
|
|
|
-D${OSQUERY_BUILD_OS}
|
|
|
|
-D${OSQUERY_BUILD_OS}_${OSQUERY_BUILD_DISTRO}
|
2014-11-12 05:34:59 +00:00
|
|
|
")
|
2014-11-09 00:55:19 +00:00
|
|
|
|
2014-12-23 22:35:48 +00:00
|
|
|
# Core/non core link helping macros (tell the build to link ALL).
|
2014-12-24 04:07:12 +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-12-24 04:07:12 +00:00
|
|
|
endmacro(ADD_OSQUERY_LINK)
|
|
|
|
|
|
|
|
macro(ADD_OSQUERY_CORE_LINK LINK)
|
2014-12-23 22:35:48 +00:00
|
|
|
list(APPEND OSQUERY_LINKS ${LINK})
|
|
|
|
set(OSQUERY_LINKS ${OSQUERY_LINKS} PARENT_SCOPE)
|
2014-12-24 04:07:12 +00:00
|
|
|
endmacro(ADD_OSQUERY_CORE_LINK)
|
2014-09-06 01:12:37 +00:00
|
|
|
|
2014-12-23 22:35:48 +00:00
|
|
|
# Core/non core lists of target source files.
|
2014-12-24 04:07:12 +00:00
|
|
|
macro(ADD_OSQUERY_LIBRARY TARGET)
|
|
|
|
add_library(${TARGET} OBJECT ${ARGN})
|
2014-12-23 22:35:48 +00:00
|
|
|
SET_OSQUERY_COMPILE(${TARGET})
|
|
|
|
list(APPEND OSQUERY_ADDITIONAL_SOURCES $<TARGET_OBJECTS:${TARGET}>)
|
2014-12-24 04:07:12 +00:00
|
|
|
set(OSQUERY_ADDITIONAL_SOURCES ${OSQUERY_ADDITIONAL_SOURCES} PARENT_SCOPE)
|
|
|
|
endmacro(ADD_OSQUERY_LIBRARY TARGET)
|
|
|
|
|
|
|
|
macro(ADD_OSQUERY_CORE_LIBRARY TARGET)
|
|
|
|
add_library(${TARGET} OBJECT ${ARGN})
|
2014-09-23 03:40:28 +00:00
|
|
|
SET_OSQUERY_COMPILE(${TARGET})
|
|
|
|
list(APPEND OSQUERY_SOURCES $<TARGET_OBJECTS:${TARGET}>)
|
|
|
|
set(OSQUERY_SOURCES ${OSQUERY_SOURCES} PARENT_SCOPE)
|
2014-12-24 04:07:12 +00:00
|
|
|
endmacro(ADD_OSQUERY_CORE_LIBRARY TARGET)
|
2014-09-23 03:40:28 +00:00
|
|
|
|
2014-12-23 22:35:48 +00:00
|
|
|
# Core/non core lists of target source files compiled as ObjC++.
|
2014-12-24 04:07:12 +00:00
|
|
|
macro(ADD_OSQUERY_OBJCXX_LIBRARY TARGET)
|
|
|
|
add_library(${TARGET} OBJECT ${ARGN})
|
2014-12-23 22:35:48 +00:00
|
|
|
SET_OSQUERY_COMPILE(${TARGET} "${OBJCXX_COMPILE_FLAGS}")
|
|
|
|
list(APPEND OSQUERY_ADDITIONAL_SOURCES $<TARGET_OBJECTS:${TARGET}>)
|
|
|
|
set(OSQUERY_ADDITIONAL_SOURCES ${OSQUERY_SOURCES} PARENT_SCOPE)
|
2014-12-24 04:07:12 +00:00
|
|
|
endmacro(ADD_OSQUERY_OBJCXX_LIBRARY TARGET)
|
|
|
|
|
|
|
|
macro(ADD_OSQUERY_CORE_OBJCXX_LIBRARY TARGET)
|
|
|
|
add_library(${TARGET} OBJECT ${ARGN})
|
2014-12-03 23:14:02 +00:00
|
|
|
SET_OSQUERY_COMPILE(${TARGET} "${OBJCXX_COMPILE_FLAGS}")
|
2014-09-23 03:40:28 +00:00
|
|
|
list(APPEND OSQUERY_SOURCES $<TARGET_OBJECTS:${TARGET}>)
|
|
|
|
set(OSQUERY_SOURCES ${OSQUERY_SOURCES} PARENT_SCOPE)
|
2014-12-24 04:07:12 +00:00
|
|
|
endmacro(ADD_OSQUERY_CORE_OBJCXX_LIBRARY TARGET)
|
2014-09-10 04:37:08 +00:00
|
|
|
|
2014-12-23 22:35:48 +00:00
|
|
|
# Helper to abstract OS/Compiler whole linking.
|
2014-12-24 04:07:12 +00:00
|
|
|
macro(TARGET_OSQUERY_LINK_WHOLE TARGET OSQUERY_LIB)
|
2014-09-06 01:12:37 +00:00
|
|
|
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-12-24 04:07:12 +00:00
|
|
|
endmacro(TARGET_OSQUERY_LINK_WHOLE)
|
2014-09-06 01:12:37 +00:00
|
|
|
|
2014-11-21 02:02:38 +00:00
|
|
|
# Fill in libraries for Apple, Uunbut, Centos, FreeBSD
|
|
|
|
if(APPLE)
|
|
|
|
set(OSQUERY_LIBS ${OSQUERY_LIBS} ${OSQUERY_APPLE_LIBS})
|
|
|
|
ADD_OSQUERY_LINK("-mmacosx-version-min=${APPLE_MIN_ABI}")
|
|
|
|
elseif(FREEBSD)
|
|
|
|
set(OSQUERY_LIBS ${OSQUERY_LIBS} ${OSQUERY_FREEBSD_LIBS})
|
|
|
|
else()
|
|
|
|
set(OSQUERY_LIBS ${OSQUERY_LIBS} ${OSQUERY_LINUX_LIBS})
|
|
|
|
if(UBUNTU)
|
|
|
|
set(OSQUERY_LIBS ${OSQUERY_LIBS} ${OSQUERY_UBUNTU_LIBS})
|
|
|
|
elseif(CENTOS)
|
|
|
|
set(OSQUERY_LIBS ${OSQUERY_LIBS} ${OSQUERY_CENTOS_LIBS})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2014-11-09 00:55:19 +00:00
|
|
|
# Make sure deps were built before compiling
|
|
|
|
execute_process(
|
2014-12-03 23:14:02 +00:00
|
|
|
COMMAND "${CMAKE_SOURCE_DIR}/tools/provision.sh" check "${CMAKE_BINARY_DIR}"
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
2014-11-09 00:55:19 +00:00
|
|
|
OUTPUT_VARIABLE OSQUERY_DEPS_MESSAGE
|
|
|
|
RESULT_VARIABLE OSQUERY_DEPS_CHECK
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
2014-12-24 04:07:12 +00:00
|
|
|
# Construct a set of all object files, starting with third-party and all
|
|
|
|
# of the osquery core objects (sources from ADD_CORE_LIBRARY macros).
|
|
|
|
SET(OSQUERY_OBJECTS $<TARGET_OBJECTS:osquery_sqlite>)
|
|
|
|
|
2014-09-24 00:55:54 +00:00
|
|
|
# Add subdirectories
|
2014-09-02 08:00:58 +00:00
|
|
|
ADD_SUBDIRECTORY(config)
|
|
|
|
ADD_SUBDIRECTORY(core)
|
|
|
|
ADD_SUBDIRECTORY(database)
|
|
|
|
ADD_SUBDIRECTORY(devtools)
|
2014-12-23 22:35:48 +00:00
|
|
|
ADD_SUBDIRECTORY(dispatcher)
|
2014-09-19 08:54:33 +00:00
|
|
|
ADD_SUBDIRECTORY(events)
|
2014-09-04 06:46:24 +00:00
|
|
|
ADD_SUBDIRECTORY(examples)
|
2014-09-02 08:00:58 +00:00
|
|
|
ADD_SUBDIRECTORY(filesystem)
|
|
|
|
ADD_SUBDIRECTORY(logger)
|
|
|
|
ADD_SUBDIRECTORY(scheduler)
|
|
|
|
|
2014-12-24 04:07:12 +00:00
|
|
|
# Include the tables and build the utilities tables.
|
|
|
|
include(tables/CMakeLibs.txt)
|
|
|
|
ADD_SUBDIRECTORY(tables)
|
|
|
|
|
|
|
|
# If the builder wants to include the additional non-utility core tables.
|
|
|
|
GENERATE_TABLES("${CMAKE_SOURCE_DIR}/osquery/tables" "${CMAKE_SOURCE_DIR}")
|
|
|
|
list(APPEND OSQUERY_OBJECTS ${OSQUERY_ADDITIONAL_SOURCES})
|
|
|
|
list(APPEND OSQUERY_LIBS ${OSQUERY_ADDITIONAL_LINKS})
|
|
|
|
|
|
|
|
# Utility tables are table specs that are ALWAYS built into osquery core.
|
|
|
|
GENERATE_UTILITY("osquery_info")
|
|
|
|
GENERATE_UTILITY("osquery_flags")
|
|
|
|
GENERATE_UTILITY("time")
|
|
|
|
GENERATE_UTILITY("file")
|
|
|
|
GENERATE_UTILITY("hash")
|
|
|
|
|
|
|
|
# Finally amalgamate all the tables.
|
2014-12-24 04:53:59 +00:00
|
|
|
AMALGAMATE("${CMAKE_SOURCE_DIR}" "amalgamate" AMALGAMATION_CORE)
|
2014-12-24 04:07:12 +00:00
|
|
|
ADD_OSQUERY_CORE_LIBRARY(osquery_core_tables ${AMALGAMATION_CORE})
|
2014-09-02 08:00:58 +00:00
|
|
|
|
2014-12-24 04:07:12 +00:00
|
|
|
list(APPEND OSQUERY_OBJECTS ${OSQUERY_SOURCES})
|
|
|
|
list(APPEND OSQUERY_LIBS ${OSQUERY_LINKS})
|
2014-12-23 22:35:48 +00:00
|
|
|
|
|
|
|
# Create the static libosquery
|
2014-11-09 00:55:19 +00:00
|
|
|
set(CMAKE_MACOSX_RPATH 0)
|
2014-12-24 04:07:12 +00:00
|
|
|
ADD_LIBRARY(libosquery STATIC main/lib.cpp ${OSQUERY_OBJECTS})
|
2014-12-23 22:35:48 +00:00
|
|
|
TARGET_LINK_LIBRARIES(libosquery ${OSQUERY_LIBS})
|
|
|
|
SET_TARGET_PROPERTIES(libosquery PROPERTIES OUTPUT_NAME osquery)
|
|
|
|
INSTALL(TARGETS libosquery DESTINATION lib)
|
2014-09-06 01:12:37 +00:00
|
|
|
|
2014-12-23 22:35:48 +00:00
|
|
|
# Include the public API includes
|
2014-12-03 23:14:02 +00:00
|
|
|
INSTALL(DIRECTORY "${CMAKE_SOURCE_DIR}/include/" DESTINATION include)
|
2014-09-02 08:00:58 +00:00
|
|
|
|
|
|
|
ADD_EXECUTABLE(shell main/shell.cpp)
|
2014-12-24 04:07:12 +00:00
|
|
|
TARGET_OSQUERY_LINK_WHOLE(shell libosquery)
|
2014-09-02 08:00:58 +00:00
|
|
|
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})
|
2014-09-02 08:00:58 +00:00
|
|
|
INSTALL(TARGETS shell DESTINATION bin)
|
|
|
|
|
|
|
|
ADD_EXECUTABLE(daemon main/daemon.cpp)
|
2014-12-23 22:35:48 +00:00
|
|
|
TARGET_LINK_LIBRARIES(daemon libosquery)
|
2014-09-02 08:00:58 +00:00
|
|
|
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})
|
2014-09-02 08:00:58 +00:00
|
|
|
INSTALL(TARGETS daemon DESTINATION bin)
|
2014-09-23 23:58:32 +00:00
|
|
|
|
2014-09-24 05:06:32 +00:00
|
|
|
# packages
|
|
|
|
|
2014-11-16 20:45:58 +00:00
|
|
|
if(LINUX)
|
2014-09-23 23:58:32 +00:00
|
|
|
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}")
|
2014-09-23 23:58:32 +00:00
|
|
|
|
|
|
|
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})
|
|
|
|
|
2014-10-29 10:38:21 +00:00
|
|
|
if(UBUNTU)
|
2014-09-23 23:58:32 +00:00
|
|
|
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()
|