2017-04-28 20:45:41 +00:00
|
|
|
# Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
2017-12-19 00:04:06 +00:00
|
|
|
# This source code is licensed under both the Apache 2.0 license (found in the
|
|
|
|
# LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
|
|
# in the COPYING file in the root directory of this source tree).
|
|
|
|
# You may select, at your option, one of the above-listed licenses.
|
2017-04-28 20:45:41 +00:00
|
|
|
|
2018-01-15 01:14:40 +00:00
|
|
|
cmake_policy(SET CMP0068 NEW)
|
|
|
|
|
2016-08-10 03:27:42 +00:00
|
|
|
# The 'core' source files define the osquery SDK (libosquery).
|
|
|
|
# There are macros throughout CMake to append sources to this list.
|
2015-01-05 16:05:41 +00:00
|
|
|
set(OSQUERY_SOURCES "")
|
2016-08-10 03:27:42 +00:00
|
|
|
|
|
|
|
# A separate list of library links (and linking options) is maintained for
|
|
|
|
# the 'core' set of sources.
|
2015-01-05 16:05:41 +00:00
|
|
|
set(OSQUERY_LINKS "")
|
2016-08-10 03:27:42 +00:00
|
|
|
|
2018-06-17 18:21:07 +00:00
|
|
|
# Finally a set of 'core' tests, and benchmark tests, is kept.
|
2015-04-27 09:12:58 +00:00
|
|
|
set(OSQUERY_TESTS "")
|
2015-07-23 23:42:46 +00:00
|
|
|
set(OSQUERY_BENCHMARKS "")
|
|
|
|
|
2016-08-10 03:27:42 +00:00
|
|
|
# The 'additional' source files are NOT included with SDK (libosquery_additional).
|
2015-01-05 16:05:41 +00:00
|
|
|
set(OSQUERY_ADDITIONAL_SOURCES "")
|
2018-06-21 14:46:39 +00:00
|
|
|
|
2018-07-18 21:11:19 +00:00
|
|
|
# Temporary hack for additional library, this library is sourceless
|
2018-06-21 14:46:39 +00:00
|
|
|
# so for some reason CMake adds "rm -f" as PostBuild step to XCode project
|
|
|
|
if(CMAKE_GENERATOR STREQUAL Xcode)
|
|
|
|
set(OSQUERY_ADDITIONAL_SOURCES main/empty.cpp)
|
|
|
|
endif()
|
|
|
|
|
2015-01-05 16:05:41 +00:00
|
|
|
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
|
|
|
|
2016-03-05 17:29:51 +00:00
|
|
|
# Add all and extra for osquery code.
|
2018-01-07 22:32:24 +00:00
|
|
|
if(CLANG AND POSIX)
|
2016-11-06 09:17:04 +00:00
|
|
|
add_compile_options(
|
|
|
|
-Wall
|
|
|
|
-Wextra
|
|
|
|
-pedantic
|
|
|
|
-Wuseless-cast
|
|
|
|
-Wno-c99-extensions
|
|
|
|
-Wno-zero-length-array
|
|
|
|
-Wno-unused-parameter
|
|
|
|
-Wno-gnu-case-range
|
2017-08-20 09:44:38 +00:00
|
|
|
-Weffc++
|
2016-11-06 09:17:04 +00:00
|
|
|
)
|
2017-03-27 06:53:06 +00:00
|
|
|
if(NOT FREEBSD)
|
|
|
|
add_compile_options(
|
2018-05-02 02:17:53 +00:00
|
|
|
-Wshadow-all
|
|
|
|
-Wno-shadow-field
|
2017-03-27 06:53:06 +00:00
|
|
|
)
|
|
|
|
endif()
|
2016-04-15 21:01:16 +00:00
|
|
|
endif()
|
2016-03-05 17:29:51 +00:00
|
|
|
|
2017-04-29 00:48:45 +00:00
|
|
|
if(DEFINED ENV{SANITIZE})
|
|
|
|
if(DEFINED ENV{SANITIZE_THREAD})
|
|
|
|
ADD_OSQUERY_LINK_CORE(-fsanitize=thread)
|
2017-05-28 07:40:08 +00:00
|
|
|
elseif(DEFINED ENV{SANITIZE_UNDEFINED})
|
|
|
|
ADD_OSQUERY_LINK_CORE(-fsanitize=undefined)
|
2017-04-29 00:48:45 +00:00
|
|
|
else()
|
|
|
|
ADD_OSQUERY_LINK_CORE(-fsanitize=address -fsanitize=leak)
|
|
|
|
endif()
|
|
|
|
ADD_OSQUERY_LINK_CORE(-fsanitize-blacklist=${SANITIZE_BLACKLIST})
|
2018-05-13 01:56:00 +00:00
|
|
|
if(DEFINED ENV{FUZZ})
|
|
|
|
ADD_OSQUERY_LINK_CORE(-fsanitize=fuzzer)
|
|
|
|
endif()
|
2017-04-29 00:48:45 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Construct a set of all object files, starting with third-party and all
|
|
|
|
# of the osquery core objects (sources from ADD_CORE_LIBRARY macros).
|
2018-03-05 14:13:05 +00:00
|
|
|
if(FREEBSD)
|
|
|
|
set(OSQUERY_OBJECTS $<TARGET_OBJECTS:osquery_sqlite>)
|
|
|
|
else()
|
|
|
|
set(OSQUERY_OBJECTS
|
|
|
|
$<TARGET_OBJECTS:osquery_sqlite>
|
|
|
|
$<TARGET_OBJECTS:linenoise-ng>
|
|
|
|
)
|
|
|
|
endif()
|
2017-04-29 00:48:45 +00:00
|
|
|
|
2018-06-26 15:54:08 +00:00
|
|
|
#main library
|
|
|
|
add_library(libosquery STATIC main/lib.cpp)
|
|
|
|
|
2017-04-29 00:48:45 +00:00
|
|
|
# Add subdirectories
|
2018-06-26 15:54:08 +00:00
|
|
|
include(config/CMakeLists.txt)
|
|
|
|
include(core/CMakeLists.txt)
|
|
|
|
include(database/CMakeLists.txt)
|
|
|
|
include(devtools/CMakeLists.txt)
|
|
|
|
include(dispatcher/CMakeLists.txt)
|
|
|
|
include(distributed/CMakeLists.txt)
|
2018-06-26 17:27:24 +00:00
|
|
|
include(events/CMakeLists.txt)
|
|
|
|
include(extensions/CMakeLists.txt)
|
|
|
|
include(filesystem/CMakeLists.txt)
|
|
|
|
include(logger/CMakeLists.txt)
|
2018-07-18 21:11:19 +00:00
|
|
|
|
|
|
|
include(killswitch/CMakeLists.txt)
|
2018-06-27 17:08:52 +00:00
|
|
|
include(registry/CMakeLists.txt)
|
|
|
|
include(sql/CMakeLists.txt)
|
|
|
|
include(remote/CMakeLists.txt)
|
|
|
|
include(utils/CMakeLists.txt)
|
2018-07-09 12:19:50 +00:00
|
|
|
include(numeric_monitoring/CMakeLists.txt)
|
|
|
|
|
2017-06-15 16:40:58 +00:00
|
|
|
if(NOT SKIP_CARVER)
|
2018-06-27 17:08:52 +00:00
|
|
|
include(carver/CMakeLists.txt)
|
2017-06-15 16:40:58 +00:00
|
|
|
endif()
|
2017-04-29 00:48:45 +00:00
|
|
|
|
|
|
|
# Add externals directory from parent
|
2018-05-13 01:56:00 +00:00
|
|
|
if(NOT DEFINED ENV{FUZZ})
|
|
|
|
add_subdirectory("${CMAKE_SOURCE_DIR}/external" "${CMAKE_BINARY_DIR}/external")
|
|
|
|
endif()
|
2017-04-29 00:48:45 +00:00
|
|
|
|
|
|
|
if(NOT SKIP_TABLES)
|
|
|
|
add_subdirectory(tables)
|
|
|
|
|
|
|
|
# Amalgamate the utility tables needed to compile.
|
|
|
|
GENERATE_UTILITIES("${CMAKE_SOURCE_DIR}")
|
|
|
|
AMALGAMATE("${CMAKE_SOURCE_DIR}" "utils" AMALGAMATION_UTILS)
|
|
|
|
ADD_OSQUERY_LIBRARY_CORE(osquery_amalgamation ${AMALGAMATION_UTILS})
|
|
|
|
endif()
|
|
|
|
|
2018-06-26 15:54:08 +00:00
|
|
|
target_group_sources(libosquery "${CMAKE_CURRENT_LIST_DIR}")
|
|
|
|
|
2016-08-10 03:27:42 +00:00
|
|
|
if(WINDOWS)
|
2018-06-21 14:46:39 +00:00
|
|
|
if(CMAKE_BUILD_TYPE EQUAL "DEBUG")
|
2017-06-16 03:59:53 +00:00
|
|
|
set(WB_KEY "sgd")
|
|
|
|
set(WO_KEY "_dbg")
|
|
|
|
set(WT_KEY "d_dbg")
|
|
|
|
else()
|
|
|
|
set(WB_KEY "s")
|
|
|
|
set(WO_KEY "")
|
|
|
|
endif()
|
2018-01-05 18:53:02 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("ntdll.lib")
|
2016-12-06 22:25:08 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("ws2_32.lib")
|
|
|
|
ADD_OSQUERY_LINK_CORE("iphlpapi.lib")
|
2016-07-31 18:32:31 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("netapi32.lib")
|
|
|
|
ADD_OSQUERY_LINK_CORE("rpcrt4.lib")
|
|
|
|
ADD_OSQUERY_LINK_CORE("shlwapi.lib")
|
2017-06-27 17:50:36 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("version.lib")
|
2017-01-08 21:19:09 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("Wtsapi32.lib")
|
2016-07-31 18:32:31 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("wbemuuid.lib")
|
2017-04-13 14:53:49 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("taskschd.lib")
|
2017-12-29 05:09:10 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("dbghelp.lib")
|
|
|
|
ADD_OSQUERY_LINK_CORE("dbgeng.lib")
|
2017-08-04 01:01:10 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("libboost_system-mt-${WB_KEY}")
|
|
|
|
ADD_OSQUERY_LINK_CORE("libboost_regex-mt-${WB_KEY}")
|
|
|
|
ADD_OSQUERY_LINK_CORE("libboost_filesystem-mt-${WB_KEY}")
|
|
|
|
ADD_OSQUERY_LINK_CORE("libboost_context-mt-${WB_KEY}")
|
2018-07-08 15:20:45 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("libboost_thread-mt-${WB_KEY}")
|
2017-09-07 00:03:29 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("rocksdb${WO_KEY}")
|
2017-06-16 03:59:53 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("thriftmt${WT_KEY}")
|
|
|
|
ADD_OSQUERY_LINK_CORE("gflags_static${WO_KEY}")
|
2016-08-31 23:45:06 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("ssleay32")
|
|
|
|
ADD_OSQUERY_LINK_CORE("eay32")
|
2016-09-20 21:18:58 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("zlibstatic")
|
2017-03-08 22:51:41 +00:00
|
|
|
|
2017-02-11 02:10:22 +00:00
|
|
|
# Enable control flow guard
|
|
|
|
ADD_OSQUERY_LINK_CORE("-guard:cf")
|
2016-05-11 21:16:32 +00:00
|
|
|
else()
|
2016-07-31 18:32:31 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("libpthread")
|
|
|
|
ADD_OSQUERY_LINK_CORE("libz")
|
2016-08-10 21:06:47 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("gflags")
|
|
|
|
ADD_OSQUERY_LINK_CORE("thrift")
|
2016-03-05 17:29:51 +00:00
|
|
|
endif()
|
2016-01-13 17:26:51 +00:00
|
|
|
|
2016-03-07 09:30:20 +00:00
|
|
|
if(APPLE OR LINUX)
|
2016-07-31 18:32:31 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("libdl")
|
2017-02-27 02:25:49 +00:00
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("rocksdb_lite")
|
2016-03-07 09:30:20 +00:00
|
|
|
elseif(FREEBSD)
|
2015-05-20 20:27:53 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("icuuc")
|
2018-03-05 14:13:05 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("linenoise")
|
2017-06-16 03:59:53 +00:00
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("rocksdb-lite")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(POSIX)
|
2017-02-27 02:25:49 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("boost_system")
|
|
|
|
ADD_OSQUERY_LINK_CORE("boost_filesystem")
|
|
|
|
ADD_OSQUERY_LINK_CORE("boost_thread")
|
2017-03-16 01:46:42 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("boost_context")
|
2017-02-27 02:25:49 +00:00
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("boost_regex")
|
2015-05-05 20:55:49 +00:00
|
|
|
endif()
|
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
if(LINUX OR FREEBSD)
|
|
|
|
ADD_OSQUERY_LINK_CORE("librt")
|
|
|
|
ADD_OSQUERY_LINK_CORE("libc")
|
2016-03-15 02:51:03 +00:00
|
|
|
endif()
|
|
|
|
|
2016-08-10 21:06:47 +00:00
|
|
|
# Remaining additional development libraries.
|
2017-06-16 03:59:53 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("glog${WO_KEY}")
|
2016-04-15 21:01:16 +00:00
|
|
|
|
2017-04-28 20:45:41 +00:00
|
|
|
if(POSIX)
|
2018-05-02 01:54:23 +00:00
|
|
|
# Hashing methods in core use libcrypto.
|
|
|
|
ADD_OSQUERY_LINK_CORE("crypto")
|
|
|
|
|
2016-08-10 21:06:47 +00:00
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("ssl")
|
2016-11-15 09:19:08 +00:00
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("libpthread")
|
2017-04-29 00:48:45 +00:00
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("magic")
|
2016-04-15 21:01:16 +00:00
|
|
|
endif()
|
2014-11-09 00:55:19 +00:00
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
if(APPLE)
|
|
|
|
ADD_OSQUERY_LINK_CORE("liblzma libbz2")
|
|
|
|
else()
|
2017-04-28 20:45:41 +00:00
|
|
|
if(POSIX)
|
2016-08-10 21:06:47 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("lzma")
|
|
|
|
endif()
|
|
|
|
ADD_OSQUERY_LINK_CORE("bz2")
|
2016-07-31 18:32:31 +00:00
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("bz2")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# The platform-specific SDK + core linker flags.
|
2017-04-28 20:45:41 +00:00
|
|
|
if(POSIX)
|
2016-08-10 21:06:47 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("-rdynamic")
|
|
|
|
endif()
|
2017-04-28 20:45:41 +00:00
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
if(APPLE)
|
|
|
|
ADD_OSQUERY_LINK_CORE("-Wl,-dead_strip")
|
|
|
|
ADD_OSQUERY_LINK_CORE("-mmacosx-version-min=${OSX_VERSION_MIN}")
|
2017-05-13 22:44:40 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("-Wl,-cache_path_lto,${CMAKE_BINARY_DIR}/ltocache")
|
2018-01-13 01:34:45 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("-Wl,-no_weak_imports")
|
2016-07-31 18:32:31 +00:00
|
|
|
elseif(LINUX OR FREEBSD)
|
2016-08-01 05:41:37 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("-Wl,-zrelro -Wl,-znow")
|
2018-06-21 14:46:39 +00:00
|
|
|
if(NOT DEFINED ENV{SANITIZE} AND (CMAKE_BUILD_TYPE STREQUAL "RELEASE"))
|
2016-08-01 05:41:37 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("-pie")
|
|
|
|
endif()
|
2016-07-31 18:32:31 +00:00
|
|
|
endif()
|
|
|
|
|
2017-04-28 20:45:41 +00:00
|
|
|
if(LINUX)
|
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("uuid")
|
|
|
|
if(NOT DEFINED ENV{OSQUERY_BUILD_LINK_SHARED})
|
|
|
|
ADD_OSQUERY_LINK_CORE("-static-libstdc++")
|
|
|
|
ADD_OSQUERY_LINK_ADDITIONAL("-static-libstdc++")
|
|
|
|
endif()
|
|
|
|
# For Ubuntu/CentOS packages add the build SHA1.
|
|
|
|
ADD_OSQUERY_LINK_CORE("-Wl,--build-id")
|
2018-01-07 22:32:24 +00:00
|
|
|
if (CLANG AND DEPS)
|
2018-01-05 07:05:21 +00:00
|
|
|
# If using GCC, libgcc_s may be needed.
|
2017-05-14 21:23:50 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("-fuse-ld=lld")
|
2018-01-05 07:05:21 +00:00
|
|
|
ADD_OSQUERY_LINK_CORE("c++")
|
|
|
|
ADD_OSQUERY_LINK_CORE("c++abi")
|
|
|
|
ADD_OSQUERY_LINK_CORE("unwind")
|
|
|
|
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0.0)
|
|
|
|
ADD_OSQUERY_LINK_CORE("-Wl,--thinlto-cache-dir=${CMAKE_BINARY_DIR}/cache")
|
|
|
|
ADD_OSQUERY_LINK_CORE("-Wl,--thinlto-cache-policy,cache_size_bytes=2g")
|
|
|
|
endif()
|
|
|
|
ADD_OSQUERY_LINK_CORE("-B${BUILD_DEPS}/legacy/lib")
|
2017-05-14 21:23:50 +00:00
|
|
|
endif()
|
2017-04-28 20:45:41 +00:00
|
|
|
endif()
|
|
|
|
|
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
|
|
|
|
2016-08-10 03:27:42 +00:00
|
|
|
# A final map from CMake build platform to a enum using for runtime detection.
|
|
|
|
# The goal is to provide a minimum set of compile code paths.
|
|
|
|
# See ./include/core.h for the enum class.
|
|
|
|
# POSIX = 0x01
|
|
|
|
# WINDOWS = 0x02
|
|
|
|
# BSD = 0x04
|
|
|
|
# LINUX = 0x08 && POSIX
|
|
|
|
# OS X = 0x10 && BSD && POSIX
|
|
|
|
# FREEBSD = 0x20 && BSD && POSIX
|
|
|
|
if(WINDOWS)
|
2016-08-13 02:25:28 +00:00
|
|
|
math(EXPR PLATFORM_MASK "2")
|
2016-08-10 03:27:42 +00:00
|
|
|
elseif(LINUX)
|
2016-08-13 02:25:28 +00:00
|
|
|
math(EXPR PLATFORM_MASK "1 + 8")
|
2016-08-10 03:27:42 +00:00
|
|
|
elseif(APPLE)
|
2016-08-13 02:25:28 +00:00
|
|
|
math(EXPR PLATFORM_MASK "1 + 4 + 16")
|
2016-08-10 03:27:42 +00:00
|
|
|
elseif(FREEBSD)
|
2016-08-13 02:25:28 +00:00
|
|
|
math(EXPR PLATFORM_MASK "1 + 4 + 32")
|
2016-08-10 03:27:42 +00:00
|
|
|
endif()
|
|
|
|
|
2015-05-20 20:27:53 +00:00
|
|
|
# Create the static libosquery (everything but non-utility tables).
|
2016-08-13 02:25:28 +00:00
|
|
|
set(OSQUERY_LIBRARY_FLAGS
|
|
|
|
-DOSQUERY_BUILD_VERSION=${OSQUERY_BUILD_VERSION}
|
|
|
|
-DOSQUERY_PLATFORM_MASK=${PLATFORM_MASK}
|
|
|
|
)
|
2017-04-28 20:45:41 +00:00
|
|
|
JOIN("${OSQUERY_LIBRARY_FLAGS}" " " OSQUERY_LIBRARY_FLAGS)
|
2016-08-13 02:25:28 +00:00
|
|
|
|
2018-06-26 15:54:08 +00:00
|
|
|
target_sources(libosquery PRIVATE ${OSQUERY_OBJECTS})
|
2015-02-03 05:21:36 +00:00
|
|
|
target_link_libraries(libosquery ${OSQUERY_LIBS})
|
|
|
|
set_target_properties(libosquery PROPERTIES OUTPUT_NAME osquery)
|
2016-08-13 02:25:28 +00:00
|
|
|
set_target_properties(libosquery PROPERTIES COMPILE_FLAGS "${OSQUERY_LIBRARY_FLAGS}")
|
2014-09-06 01:12:37 +00:00
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
# Create the dynamic libosquery.
|
|
|
|
if(DEFINED ENV{OSQUERY_BUILD_SHARED})
|
2018-06-26 15:54:08 +00:00
|
|
|
add_library(a_shared SHARED main/lib.cpp ${OSQUERY_OBJECTS})
|
2016-11-06 09:17:48 +00:00
|
|
|
target_link_libraries(libosquery_shared PRIVATE ${OSQUERY_LIBS})
|
2016-08-13 02:25:28 +00:00
|
|
|
set_target_properties(libosquery_shared PROPERTIES COMPILE_FLAGS "${OSQUERY_LIBRARY_FLAGS}")
|
2016-07-31 18:32:31 +00:00
|
|
|
set_target_properties(libosquery_shared PROPERTIES OUTPUT_NAME osquery)
|
|
|
|
endif()
|
|
|
|
|
2015-04-27 09:12:58 +00:00
|
|
|
# A friendly echo printed after the library is built.
|
|
|
|
add_custom_target(osquery_library ALL
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan --bold
|
2016-08-10 21:06:47 +00:00
|
|
|
"-- Built libosquery: $<TARGET_FILE:libosquery>"
|
2016-08-10 03:27:42 +00:00
|
|
|
DEPENDS libosquery
|
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
|
2016-08-10 03:27:42 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -D COMPONENT=devel -P cmake_install.cmake
|
|
|
|
DEPENDS libosquery_basic
|
2015-01-08 23:53:51 +00:00
|
|
|
)
|
2015-02-03 05:21:36 +00:00
|
|
|
add_dependencies(devel libosquery)
|
2015-01-08 23:53:51 +00:00
|
|
|
|
2017-04-28 20:45:41 +00:00
|
|
|
if(NOT OSQUERY_BUILD_SDK_ONLY)
|
|
|
|
if(NOT SKIP_TABLES)
|
2016-07-31 18:32:31 +00:00
|
|
|
# Generate the osquery additional tables (the non-util).
|
|
|
|
GENERATE_TABLES("${CMAKE_SOURCE_DIR}")
|
|
|
|
AMALGAMATE("${CMAKE_SOURCE_DIR}" "additional" AMALGAMATION)
|
|
|
|
ADD_OSQUERY_LIBRARY_ADDITIONAL(osquery_additional_amalgamation ${AMALGAMATION})
|
|
|
|
|
2018-05-13 01:56:00 +00:00
|
|
|
AMALGAMATE("${CMAKE_SOURCE_DIR}" "foreign" AMALGAMATION_FOREIGN)
|
|
|
|
ADD_OSQUERY_LIBRARY_ADDITIONAL(osquery_foreign_amalgamation ${AMALGAMATION_FOREIGN})
|
|
|
|
endif()
|
2016-04-11 16:33:45 +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)
|
2018-05-13 01:56:00 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(FUZZ)
|
|
|
|
add_executable(fuzz
|
|
|
|
main/fuzz.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
ADD_DEFAULT_LINKS(fuzz TRUE)
|
|
|
|
SET_OSQUERY_COMPILE(fuzz)
|
|
|
|
set_target_properties(fuzz PROPERTIES OUTPUT_NAME osqueryf)
|
|
|
|
endif()
|
2015-02-03 05:21:36 +00:00
|
|
|
|
2018-05-13 01:56:00 +00:00
|
|
|
if(NOT OSQUERY_BUILD_SDK_ONLY AND NOT FUZZ)
|
2016-07-31 18:32:31 +00:00
|
|
|
# Create the dynamic libosquery_additional.
|
|
|
|
if(DEFINED ENV{OSQUERY_BUILD_SHARED})
|
|
|
|
add_library(libosquery_additional_shared SHARED ${OSQUERY_ADDITIONAL_SOURCES})
|
2017-09-10 00:08:46 +00:00
|
|
|
target_link_libraries(libosquery_additional_shared PRIVATE ${OSQUERY_LINKS} ${OSQUERY_ADDITIONAL_LINKS})
|
2016-07-31 18:32:31 +00:00
|
|
|
set_target_properties(libosquery_additional_shared PROPERTIES OUTPUT_NAME osquery_additional)
|
|
|
|
endif()
|
|
|
|
|
2017-09-02 18:22:56 +00:00
|
|
|
set(DAEMON_SOURCE_FILES
|
2017-08-27 18:09:25 +00:00
|
|
|
devtools/shell.cpp
|
|
|
|
main/main.cpp
|
|
|
|
main/${PROCESS_FAMILY}/main.cpp
|
|
|
|
)
|
2017-09-02 18:22:56 +00:00
|
|
|
# Add the versioning information for Windows binaries
|
|
|
|
if(WINDOWS)
|
|
|
|
# The windows version resource requires a version string, as well
|
|
|
|
# as version components separated by a comma. First we replace the `-`
|
|
|
|
# values that may exist for commit hash versions, then we grab the
|
|
|
|
# major version components
|
|
|
|
string(REPLACE "-" "." OSQUERY_VER_TEMP "${OSQUERY_BUILD_VERSION}")
|
|
|
|
string(REPLACE "." ";" OSQUERY_VERSION_LIST "${OSQUERY_VER_TEMP}")
|
|
|
|
list(GET OSQUERY_VERSION_LIST 0 OSQUERY_PRODUCT_NUMBER)
|
|
|
|
list(GET OSQUERY_VERSION_LIST 1 OSQUERY_PRODUCT_VERSION)
|
|
|
|
list(GET OSQUERY_VERSION_LIST 2 OSQUERY_BUILD_NUMBER)
|
|
|
|
|
|
|
|
configure_file(
|
2017-12-12 22:15:38 +00:00
|
|
|
${CMAKE_SOURCE_DIR}/tools/windows_resources.rc.in
|
|
|
|
${CMAKE_BINARY_DIR}/osquery/windows_resources.rc
|
2017-09-02 18:22:56 +00:00
|
|
|
@ONLY)
|
2017-12-12 22:15:38 +00:00
|
|
|
list(APPEND DAEMON_SOURCE_FILES ${CMAKE_BINARY_DIR}/osquery/windows_resources.rc)
|
2017-09-02 18:22:56 +00:00
|
|
|
endif()
|
|
|
|
add_executable(daemon
|
|
|
|
${DAEMON_SOURCE_FILES}
|
|
|
|
)
|
|
|
|
|
2016-08-13 02:25:28 +00:00
|
|
|
ADD_DEFAULT_LINKS(daemon TRUE)
|
2017-10-09 07:27:28 +00:00
|
|
|
SET_OSQUERY_COMPILE(daemon)
|
2015-02-03 05:21:36 +00:00
|
|
|
set_target_properties(daemon PROPERTIES OUTPUT_NAME osqueryd)
|
|
|
|
|
2016-08-10 21:06:47 +00:00
|
|
|
# A friendly echo printed before building the daemon
|
|
|
|
add_custom_command(TARGET daemon PRE_BUILD
|
2016-03-18 02:11:18 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan --bold
|
2016-08-10 21:06:47 +00:00
|
|
|
"-- Building osqueryd: $<TARGET_FILE:daemon>"
|
2016-03-18 02:11:18 +00:00
|
|
|
)
|
|
|
|
|
2017-09-10 00:36:32 +00:00
|
|
|
set(SHELL_EXECUTABLE "osqueryi")
|
2017-08-27 18:09:25 +00:00
|
|
|
if(WINDOWS)
|
|
|
|
set(SHELL_EXECUTABLE "${SHELL_EXECUTABLE}.exe")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_target(shell ALL
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
2017-09-10 00:36:32 +00:00
|
|
|
$<TARGET_FILE:daemon> "$<TARGET_FILE_DIR:daemon>/${SHELL_EXECUTABLE}")
|
2017-08-27 18:09:25 +00:00
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
TARGET shell POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan --bold
|
2017-09-10 00:36:32 +00:00
|
|
|
"-- Creating osqueryi: $<TARGET_FILE_DIR:daemon>/${SHELL_EXECUTABLE}")
|
2017-08-27 18:09:25 +00:00
|
|
|
|
|
|
|
# This is no longer supported.
|
|
|
|
# Include the public API includes if make devel.
|
|
|
|
# install(TARGETS libosquery ARCHIVE DESTINATION lib COMPONENT devel OPTIONAL)
|
|
|
|
# install(DIRECTORY "${CMAKE_SOURCE_DIR}/include/osquery"
|
|
|
|
# DESTINATION include
|
|
|
|
# COMPONENT devel OPTIONAL
|
|
|
|
# PATTERN ".*" EXCLUDE
|
|
|
|
# )
|
|
|
|
|
2015-02-03 05:21:36 +00:00
|
|
|
# make install (executables)
|
|
|
|
install(TARGETS daemon RUNTIME DESTINATION bin COMPONENT main)
|
2017-08-27 18:09:25 +00:00
|
|
|
install(PROGRAMS ${CMAKE_BINARY_DIR}/osquery/osqueryi 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"
|
2017-08-27 18:09:25 +00:00
|
|
|
DESTINATION "${CMAKE_INSTALL_PREFIX}/etc/init.d/" RENAME "osqueryd" COMPONENT main)
|
2015-02-03 05:21:36 +00:00
|
|
|
endif()
|
2015-01-08 23:53:51 +00:00
|
|
|
endif()
|
2015-01-08 02:55:14 +00:00
|
|
|
|
2017-04-28 20:45:41 +00:00
|
|
|
if(NOT SKIP_TESTS)
|
2015-04-27 09:12:58 +00:00
|
|
|
# osquery testing library (testing helper methods/libs).
|
2016-06-09 17:49:26 +00:00
|
|
|
add_library(libosquery_testing STATIC tests/test_util.cpp)
|
2015-04-27 09:12:58 +00:00
|
|
|
add_dependencies(libosquery_testing libosquery)
|
2017-10-09 07:27:28 +00:00
|
|
|
SET_OSQUERY_COMPILE(libosquery_testing)
|
2015-04-27 09:12:58 +00:00
|
|
|
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})
|
2016-08-13 02:25:28 +00:00
|
|
|
ADD_DEFAULT_LINKS(osquery_tests FALSE)
|
2016-07-21 19:33:14 +00:00
|
|
|
target_link_libraries(osquery_tests gtest gmock libosquery_testing)
|
2017-10-09 07:27:28 +00:00
|
|
|
SET_OSQUERY_COMPILE(osquery_tests "${GTEST_FLAGS}")
|
2017-08-13 09:01:05 +00:00
|
|
|
add_test(osquery_tests osquery_tests ${TEST_ARGS})
|
2015-04-27 09:12:58 +00:00
|
|
|
|
2015-07-23 23:42:46 +00:00
|
|
|
# osquery benchmarks.
|
2017-04-28 20:45:41 +00:00
|
|
|
if(NOT SKIP_BENCHMARKS AND NOT OSQUERY_BUILD_SDK_ONLY)
|
2015-10-11 21:37:49 +00:00
|
|
|
add_executable(osquery_benchmarks main/benchmarks.cpp ${OSQUERY_BENCHMARKS})
|
2016-11-15 09:19:08 +00:00
|
|
|
target_link_libraries(osquery_benchmarks benchmark libosquery_testing pthread)
|
2016-08-14 02:38:55 +00:00
|
|
|
ADD_DEFAULT_LINKS(osquery_benchmarks TRUE)
|
2017-10-09 07:27:28 +00:00
|
|
|
SET_OSQUERY_COMPILE(osquery_benchmarks "${GTEST_FLAGS}")
|
2015-10-11 21:37:49 +00:00
|
|
|
set(BENCHMARK_TARGET "$<TARGET_FILE:osquery_benchmarks>")
|
|
|
|
|
|
|
|
# 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
|
|
|
|
2017-04-28 20:45:41 +00:00
|
|
|
if(NOT OSQUERY_BUILD_SDK_ONLY)
|
2015-04-27 09:12:58 +00:00
|
|
|
# osquery core (additional) set of unit tests built outside of SDK.
|
2016-11-03 00:08:44 +00:00
|
|
|
add_executable(osquery_additional_tests tests/test_additional_util.cpp main/tests.cpp ${OSQUERY_ADDITIONAL_TESTS})
|
2016-08-13 02:25:28 +00:00
|
|
|
ADD_DEFAULT_LINKS(osquery_additional_tests TRUE)
|
2016-04-01 21:59:24 +00:00
|
|
|
target_link_libraries(osquery_additional_tests gtest gmock libosquery_testing)
|
2017-10-09 07:27:28 +00:00
|
|
|
SET_OSQUERY_COMPILE(osquery_additional_tests "${GTEST_FLAGS}")
|
2017-08-13 09:01:05 +00:00
|
|
|
add_test(osquery_additional_tests osquery_additional_tests ${TEST_ARGS})
|
2015-04-27 09:12:58 +00:00
|
|
|
|
|
|
|
# osquery tables set of unit tests (extracted for organization).
|
2017-09-08 06:08:27 +00:00
|
|
|
add_executable(osquery_tables_tests tests/test_additional_util.cpp main/tests.cpp ${OSQUERY_TABLES_TESTS})
|
2016-08-13 02:25:28 +00:00
|
|
|
ADD_DEFAULT_LINKS(osquery_tables_tests TRUE)
|
2016-07-21 19:33:14 +00:00
|
|
|
target_link_libraries(osquery_tables_tests gtest gmock libosquery_testing)
|
2017-10-09 07:27:28 +00:00
|
|
|
SET_OSQUERY_COMPILE(osquery_tables_tests "${GTEST_FLAGS}")
|
2017-08-13 09:01:05 +00:00
|
|
|
add_test(osquery_tables_tests osquery_tables_tests ${TEST_ARGS})
|
2015-04-27 09:12:58 +00:00
|
|
|
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)
|
|
|
|
endif()
|