2015-04-27 09:12:58 +00:00
|
|
|
# osquery core source files included with the SDK (libosquery).
|
2015-01-05 16:05:41 +00:00
|
|
|
set(OSQUERY_SOURCES "")
|
|
|
|
set(OSQUERY_LINKS "")
|
2015-04-27 09:12:58 +00:00
|
|
|
set(OSQUERY_TESTS "")
|
2015-06-30 21:20:04 +00:00
|
|
|
set(OSQUERY_KERNEL_TESTS "")
|
2015-04-27 09:12:58 +00:00
|
|
|
|
2015-07-23 23:42:46 +00:00
|
|
|
# osquery benchmarking sources
|
|
|
|
set(OSQUERY_BENCHMARKS "")
|
|
|
|
set(OSQUERY_KERNEL_BENCHMARKS "")
|
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
# osquery core additional sources files not included with SDK (libosquery_additional).
|
2015-01-05 16:05:41 +00:00
|
|
|
set(OSQUERY_ADDITIONAL_SOURCES "")
|
|
|
|
set(OSQUERY_ADDITIONAL_LINKS "")
|
2015-04-27 09:12:58 +00:00
|
|
|
set(OSQUERY_ADDITIONAL_TESTS "")
|
|
|
|
set(OSQUERY_TABLES_TESTS "")
|
2014-11-09 00:55:19 +00:00
|
|
|
|
2015-01-05 16:05:41 +00:00
|
|
|
# The core set of osquery libraries most discovered with find_package.
|
|
|
|
set(OSQUERY_LIBS
|
2015-07-13 07:47:20 +00:00
|
|
|
# This includes librocksdb[_lite] and libsnappy.
|
|
|
|
${ROCKSDB_LIBRARIES}
|
|
|
|
${THRIFT_LIBRARY}
|
2015-01-05 16:05:41 +00:00
|
|
|
${GLOG_LIBRARY}
|
|
|
|
${GFLAGS_LIBRARY}
|
|
|
|
${OPENSSL_CRYPTO_LIBRARY}
|
|
|
|
${OPENSSL_SSL_LIBRARY}
|
2015-04-11 08:05:58 +00:00
|
|
|
${CPP-NETLIB_LIBRARY}
|
2015-05-23 22:43:54 +00:00
|
|
|
${READLINE_LIBRARIES}
|
2014-12-23 19:39:03 +00:00
|
|
|
|
2015-01-05 16:05:41 +00:00
|
|
|
pthread
|
2014-11-18 21:03:13 +00:00
|
|
|
bz2
|
2014-12-23 19:39:03 +00:00
|
|
|
z
|
2014-11-13 20:00:41 +00:00
|
|
|
)
|
|
|
|
|
2015-05-05 20:55:49 +00:00
|
|
|
if(NOT FREEBSD)
|
|
|
|
set(OSQUERY_LIBS ${OSQUERY_LIBS} dl)
|
2015-05-08 23:03:43 +00:00
|
|
|
else()
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("icuuc")
|
2015-05-05 20:55:49 +00:00
|
|
|
endif()
|
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
# Add default linking details (the first argument means SDK + core).
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("-rdynamic")
|
2015-05-13 07:31:02 +00:00
|
|
|
foreach(DISTRO ${OSQUERY_REQUIRE_RUNTIMES})
|
|
|
|
if(${OSQUERY_BUILD_DISTRO} STREQUAL ${DISTRO})
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("-static-libstdc++")
|
2015-05-13 07:31:02 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2015-03-04 16:45:21 +00:00
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
# The platform-specific SDK + core libraries.
|
2015-01-05 16:05:41 +00:00
|
|
|
if(APPLE)
|
2015-10-18 23:27:45 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("-mmacosx-version-min=${OSX_VERSION_MIN}")
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("boost_thread-mt")
|
|
|
|
ADD_OSQUERY_LINK_CORE("lz4")
|
2014-12-03 23:14:02 +00:00
|
|
|
else()
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("-Wl,-zrelro -Wl,-znow")
|
|
|
|
ADD_OSQUERY_LINK_CORE("boost_thread")
|
2015-05-24 01:52:42 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("librt.so")
|
2014-10-29 10:38:21 +00:00
|
|
|
endif()
|
|
|
|
|
2015-01-05 16:05:41 +00:00
|
|
|
# The remaining boost libraries are discovered with find_library.
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("boost_system")
|
|
|
|
ADD_OSQUERY_LINK_CORE("boost_filesystem")
|
|
|
|
ADD_OSQUERY_LINK_CORE("boost_regex")
|
|
|
|
ADD_OSQUERY_LINK_CORE("yara")
|
2014-11-09 00:55:19 +00:00
|
|
|
|
2015-08-30 08:11:45 +00:00
|
|
|
# Remaining additional development libraries.
|
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("libcppnetlib-uri.a")
|
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("libcppnetlib-client-connections.a")
|
|
|
|
|
2015-05-04 03:02:01 +00:00
|
|
|
if(DEFINED ENV{SANITIZE})
|
|
|
|
if(DEFINED ENV{SANITIZE_THREAD})
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE(-fsanitize=thread)
|
2015-05-04 03:02:01 +00:00
|
|
|
else()
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE(-fsanitize=address -fsanitize=leak)
|
2015-05-04 03:02:01 +00:00
|
|
|
endif()
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE(-fsanitize-blacklist=${SANITIZE_BLACKLIST})
|
2015-05-04 03:02:01 +00:00
|
|
|
endif()
|
|
|
|
|
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).
|
2014-12-28 06:42:59 +00:00
|
|
|
set(OSQUERY_OBJECTS $<TARGET_OBJECTS:osquery_sqlite>)
|
2014-12-24 04:07:12 +00:00
|
|
|
|
2014-09-24 00:55:54 +00:00
|
|
|
# Add subdirectories
|
2014-12-28 06:42:59 +00:00
|
|
|
add_subdirectory(config)
|
|
|
|
add_subdirectory(core)
|
|
|
|
add_subdirectory(database)
|
|
|
|
add_subdirectory(devtools)
|
|
|
|
add_subdirectory(dispatcher)
|
2015-02-26 19:35:54 +00:00
|
|
|
add_subdirectory(distributed)
|
2014-12-28 06:42:59 +00:00
|
|
|
add_subdirectory(events)
|
2015-02-04 03:55:16 +00:00
|
|
|
add_subdirectory(extensions)
|
2014-12-28 06:42:59 +00:00
|
|
|
add_subdirectory(filesystem)
|
|
|
|
add_subdirectory(logger)
|
2015-01-30 18:44:25 +00:00
|
|
|
add_subdirectory(registry)
|
2015-04-11 08:05:58 +00:00
|
|
|
add_subdirectory(remote)
|
2015-02-03 05:21:36 +00:00
|
|
|
add_subdirectory(sql)
|
2015-05-24 01:52:42 +00:00
|
|
|
|
|
|
|
if(NOT ENV{SKIP_TABLES})
|
|
|
|
add_subdirectory(tables)
|
|
|
|
endif()
|
2014-12-24 04:07:12 +00:00
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
# Amalgamate the utility tables needed to compile.
|
2015-06-01 22:53:52 +00:00
|
|
|
GENERATE_UTILITIES("${CMAKE_SOURCE_DIR}")
|
2014-12-25 20:46:59 +00:00
|
|
|
AMALGAMATE("${CMAKE_SOURCE_DIR}" "utils" AMALGAMATION_UTILS)
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LIBRARY_CORE(osquery_amalgamation ${AMALGAMATION_UTILS})
|
2014-09-02 08:00:58 +00:00
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
# Bubble the subdirectory (component) sources and links for this build.
|
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
|
|
|
|
2014-11-09 00:55:19 +00:00
|
|
|
set(CMAKE_MACOSX_RPATH 0)
|
2015-05-04 03:02:01 +00:00
|
|
|
set(CMAKE_SKIP_RPATH TRUE)
|
2015-05-20 20:27:53 +00:00
|
|
|
|
|
|
|
# Create the static libosquery (everything but non-utility tables).
|
2015-02-03 05:21:36 +00:00
|
|
|
add_library(libosquery STATIC main/lib.cpp ${OSQUERY_OBJECTS})
|
|
|
|
target_link_libraries(libosquery ${OSQUERY_LIBS})
|
|
|
|
set_target_properties(libosquery PROPERTIES OUTPUT_NAME osquery)
|
2015-06-12 01:13:37 +00:00
|
|
|
set_target_properties(libosquery PROPERTIES COMPILE_FLAGS
|
2015-10-30 00:53:26 +00:00
|
|
|
"-DOSQUERY_BUILD_VERSION=${OSQUERY_BUILD_VERSION} ${CXX_COMPILE_FLAGS}")
|
2014-09-06 01:12:37 +00:00
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
# A friendly echo printed after the library is built.
|
|
|
|
add_custom_target(osquery_library ALL
|
2015-02-26 22:10:39 +00:00
|
|
|
DEPENDS libosquery
|
2015-04-27 09:12:58 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan --bold
|
2015-05-23 22:43:54 +00:00
|
|
|
"-- Built libosquery: ${CMAKE_BINARY_DIR}/libosquery.a"
|
2015-02-26 22:10:39 +00:00
|
|
|
)
|
|
|
|
|
2015-02-03 05:21:36 +00:00
|
|
|
# make devel (implies install)
|
2015-01-08 23:53:51 +00:00
|
|
|
add_custom_target(devel
|
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
-D COMPONENT=devel
|
|
|
|
-P cmake_install.cmake
|
|
|
|
DEPENDS libosquery_basic
|
|
|
|
)
|
2015-02-03 05:21:36 +00:00
|
|
|
add_dependencies(devel libosquery)
|
2015-01-08 23:53:51 +00:00
|
|
|
|
2015-02-03 05:21:36 +00:00
|
|
|
if(NOT OSQUERY_BUILD_SDK_ONLY)
|
2015-04-27 09:12:58 +00:00
|
|
|
# Generate the osquery additional tables (the non-util).
|
2015-06-01 22:53:52 +00:00
|
|
|
GENERATE_TABLES("${CMAKE_SOURCE_DIR}")
|
2015-04-27 09:12:58 +00:00
|
|
|
AMALGAMATE("${CMAKE_SOURCE_DIR}" "additional" AMALGAMATION)
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LIBRARY_ADDITIONAL(osquery_additional_amalgamation ${AMALGAMATION})
|
2015-04-27 09:12:58 +00:00
|
|
|
|
2015-02-03 05:21:36 +00:00
|
|
|
# Create the static libosquery_additional.
|
|
|
|
add_library(libosquery_additional STATIC ${OSQUERY_ADDITIONAL_SOURCES})
|
|
|
|
target_link_libraries(libosquery_additional ${OSQUERY_ADDITIONAL_LINKS})
|
|
|
|
set_target_properties(libosquery_additional PROPERTIES OUTPUT_NAME osquery_additional)
|
|
|
|
|
2015-03-05 07:10:38 +00:00
|
|
|
add_executable(shell devtools/shell.cpp main/shell.cpp)
|
2015-02-03 05:21:36 +00:00
|
|
|
TARGET_OSQUERY_LINK_WHOLE(shell libosquery)
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(shell libosquery_additional)
|
2015-04-27 09:12:58 +00:00
|
|
|
SET_OSQUERY_COMPILE(shell "${CXX_COMPILE_FLAGS}")
|
2015-02-03 05:21:36 +00:00
|
|
|
set_target_properties(shell PROPERTIES OUTPUT_NAME osqueryi)
|
|
|
|
|
2015-02-09 00:00:43 +00:00
|
|
|
add_executable(daemon main/daemon.cpp)
|
2015-02-03 05:21:36 +00:00
|
|
|
TARGET_OSQUERY_LINK_WHOLE(daemon libosquery)
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(daemon libosquery_additional)
|
2015-04-27 09:12:58 +00:00
|
|
|
SET_OSQUERY_COMPILE(daemon "${CXX_COMPILE_FLAGS}")
|
2015-02-03 05:21:36 +00:00
|
|
|
set_target_properties(daemon PROPERTIES OUTPUT_NAME osqueryd)
|
|
|
|
|
|
|
|
# Include the public API includes if make devel.
|
|
|
|
install(TARGETS libosquery ARCHIVE DESTINATION lib COMPONENT devel OPTIONAL)
|
2015-05-11 16:36:15 +00:00
|
|
|
install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/osquery"
|
2015-05-08 21:00:09 +00:00
|
|
|
DESTINATION include
|
|
|
|
COMPONENT devel OPTIONAL
|
|
|
|
PATTERN ".*" EXCLUDE
|
|
|
|
)
|
2015-02-03 05:21:36 +00:00
|
|
|
|
|
|
|
# make install (executables)
|
|
|
|
install(TARGETS shell RUNTIME DESTINATION bin COMPONENT main)
|
|
|
|
install(TARGETS daemon RUNTIME DESTINATION bin COMPONENT main)
|
2015-07-15 18:32:55 +00:00
|
|
|
install(FILES "${CMAKE_SOURCE_DIR}/tools/deployment/osqueryctl"
|
|
|
|
DESTINATION bin COMPONENT main)
|
2015-02-03 05:21:36 +00:00
|
|
|
|
|
|
|
# make install (config files)
|
|
|
|
install(FILES "${CMAKE_SOURCE_DIR}/tools/deployment/osquery.example.conf"
|
2015-01-22 19:07:19 +00:00
|
|
|
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/osquery/" COMPONENT main)
|
2015-07-23 23:05:51 +00:00
|
|
|
install(DIRECTORY DESTINATION "${CMAKE_INSTALL_PREFIX}/var/osquery")
|
2015-07-17 23:03:15 +00:00
|
|
|
|
|
|
|
install(DIRECTORY "${CMAKE_SOURCE_DIR}/packs/"
|
|
|
|
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/osquery/packs" COMPONENT main)
|
2015-02-03 05:21:36 +00:00
|
|
|
if(APPLE)
|
|
|
|
install(FILES "${CMAKE_SOURCE_DIR}/tools/deployment/com.facebook.osqueryd.plist"
|
|
|
|
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/osquery/" COMPONENT main)
|
|
|
|
else()
|
|
|
|
install(PROGRAMS "${CMAKE_SOURCE_DIR}/tools/deployment/osqueryd.initd"
|
|
|
|
DESTINATION "/etc/init.d/" RENAME "osqueryd" COMPONENT main)
|
|
|
|
endif()
|
2015-01-08 23:53:51 +00:00
|
|
|
endif()
|
2015-01-08 02:55:14 +00:00
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
if(NOT DEFINED ENV{SKIP_TESTS})
|
|
|
|
# osquery testing library (testing helper methods/libs).
|
|
|
|
add_library(libosquery_testing STATIC core/test_util.cpp)
|
|
|
|
add_dependencies(libosquery_testing libosquery)
|
|
|
|
SET_OSQUERY_COMPILE(libosquery_testing "${CXX_COMPILE_FLAGS}")
|
|
|
|
set_target_properties(libosquery_testing PROPERTIES OUTPUT_NAME osquery_testing)
|
|
|
|
|
|
|
|
# osquery core set of unit tests build with SDK.
|
|
|
|
add_executable(osquery_tests main/tests.cpp ${OSQUERY_TESTS})
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_tests libosquery)
|
|
|
|
target_link_libraries(osquery_tests gtest libosquery_testing)
|
|
|
|
SET_OSQUERY_COMPILE(osquery_tests "${CXX_COMPILE_FLAGS} -DGTEST_HAS_TR1_TUPLE=0")
|
|
|
|
add_test(osquery_tests osquery_tests)
|
|
|
|
|
2015-06-30 21:20:04 +00:00
|
|
|
# osquery kernel tests.
|
|
|
|
add_executable(osquery_kernel_tests main/tests.cpp ${OSQUERY_KERNEL_TESTS})
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_kernel_tests libosquery)
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_kernel_tests libosquery_additional)
|
|
|
|
target_link_libraries(osquery_kernel_tests gtest libosquery_testing)
|
|
|
|
SET_OSQUERY_COMPILE(osquery_kernel_tests "${CXX_COMPILE_FLAGS} -DKERNEL_TEST=1 -DGTEST_HAS_TR1_TUPLE=0")
|
|
|
|
|
2015-07-23 23:42:46 +00:00
|
|
|
# osquery benchmarks.
|
2015-10-11 21:37:49 +00:00
|
|
|
if(NOT DEFINED ENV{SKIP_BENCHMARKS})
|
|
|
|
add_executable(osquery_benchmarks main/benchmarks.cpp ${OSQUERY_BENCHMARKS})
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_benchmarks libosquery)
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_benchmarks libosquery_additional)
|
|
|
|
target_link_libraries(osquery_benchmarks benchmark libosquery_testing)
|
|
|
|
SET_OSQUERY_COMPILE(osquery_benchmarks "${CXX_COMPILE_FLAGS}")
|
|
|
|
set(BENCHMARK_TARGET "$<TARGET_FILE:osquery_benchmarks>")
|
|
|
|
|
|
|
|
# osquery kernel benchmarks.
|
|
|
|
add_executable(osquery_kernel_benchmarks main/benchmarks.cpp ${OSQUERY_KERNEL_BENCHMARKS})
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_kernel_benchmarks libosquery)
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_kernel_benchmarks libosquery_additional)
|
|
|
|
target_link_libraries(osquery_kernel_benchmarks benchmark libosquery_testing)
|
|
|
|
SET_OSQUERY_COMPILE(osquery_kernel_benchmarks "${CXX_COMPILE_FLAGS} -DKERNEL_TEST=1")
|
|
|
|
|
|
|
|
# make benchmark
|
|
|
|
add_custom_target(
|
|
|
|
run-benchmark
|
|
|
|
COMMAND bash -c "${BENCHMARK_TARGET} $ENV{BENCHMARK_TO_FILE}"
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
DEPENDS osquery_benchmarks
|
|
|
|
)
|
|
|
|
endif()
|
2015-07-24 16:52:29 +00:00
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
if(NOT OSQUERY_BUILD_SDK_ONLY)
|
|
|
|
# osquery core (additional) set of unit tests built outside of SDK.
|
|
|
|
add_executable(osquery_additional_tests main/tests.cpp ${OSQUERY_ADDITIONAL_TESTS})
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_additional_tests libosquery)
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_additional_tests libosquery_additional)
|
|
|
|
target_link_libraries(osquery_additional_tests gtest libosquery_testing)
|
|
|
|
SET_OSQUERY_COMPILE(osquery_additional_tests "${CXX_COMPILE_FLAGS} -DGTEST_HAS_TR1_TUPLE=0")
|
|
|
|
add_test(osquery_additional_tests osquery_additional_tests)
|
|
|
|
|
|
|
|
# osquery tables set of unit tests (extracted for organization).
|
|
|
|
add_executable(osquery_tables_tests main/tests.cpp ${OSQUERY_TABLES_TESTS})
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_tables_tests libosquery)
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_tables_tests libosquery_additional)
|
|
|
|
target_link_libraries(osquery_tables_tests gtest libosquery_testing)
|
|
|
|
SET_OSQUERY_COMPILE(osquery_tables_tests "${CXX_COMPILE_FLAGS} -DGTEST_HAS_TR1_TUPLE=0")
|
|
|
|
add_test(osquery_tables_tests osquery_tables_tests)
|
|
|
|
|
|
|
|
# osquery table run profiler built outside of SDK.
|
|
|
|
add_executable(run main/run.cpp)
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(run libosquery)
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(run libosquery_additional)
|
|
|
|
SET_OSQUERY_COMPILE(run "${CXX_COMPILE_FLAGS}")
|
|
|
|
set_target_properties(run PROPERTIES OUTPUT_NAME run)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Build the example extension with the SDK.
|
2015-04-21 22:40:02 +00:00
|
|
|
ADD_OSQUERY_EXTENSION(example_extension examples/example_extension.cpp)
|
2015-03-04 02:40:24 +00:00
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
# Build the example extension module with the SDK.
|
2015-04-21 22:40:02 +00:00
|
|
|
ADD_OSQUERY_MODULE(modexample examples/example_module.cpp)
|
|
|
|
endif()
|