2017-04-28 20:45:41 +00:00
|
|
|
# Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
# All rights reserved.
|
2014-12-23 22:35:48 +00:00
|
|
|
#
|
2017-04-28 20:45:41 +00:00
|
|
|
# This source code is licensed under the BSD-style license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
2014-12-31 16:28:08 +00:00
|
|
|
|
|
|
|
# osquery-specific helper macros
|
2015-05-23 22:43:54 +00:00
|
|
|
macro(LOG_PLATFORM NAME)
|
2016-11-10 16:14:26 +00:00
|
|
|
set(LINK "http://osquery.readthedocs.io/en/stable/development/building/")
|
|
|
|
LOG("Welcome to osquery's build-- thank you for your patience! :)")
|
|
|
|
LOG("For a brief tutorial see: ${ESC}[1m${LINK}${ESC}[m")
|
2017-02-07 20:43:00 +00:00
|
|
|
if(NOT WINDOWS)
|
|
|
|
LOG("If at first you dont succeed, perhaps: make distclean; make depsclean")
|
|
|
|
endif()
|
2015-05-23 22:43:54 +00:00
|
|
|
LOG("Building for platform ${ESC}[36;1m${NAME} (${OSQUERY_BUILD_PLATFORM}, ${OSQUERY_BUILD_DISTRO})${ESC}[m")
|
|
|
|
LOG("Building osquery version ${ESC}[36;1m ${OSQUERY_BUILD_VERSION} sdk ${OSQUERY_BUILD_SDK_VERSION}${ESC}[m")
|
|
|
|
endmacro(LOG_PLATFORM)
|
|
|
|
|
|
|
|
macro(LOG_LIBRARY NAME PATH)
|
2015-07-16 22:23:29 +00:00
|
|
|
set(CACHE_NAME "LOG_LIBRARY_${NAME}")
|
|
|
|
if(NOT DEFINED ${CACHE_NAME} OR NOT ${${CACHE_NAME}})
|
|
|
|
set(${CACHE_NAME} TRUE CACHE BOOL "Write log line for ${NAME} library.")
|
|
|
|
set(BUILD_POSITION -1)
|
|
|
|
string(FIND "${PATH}" "${CMAKE_BINARY_DIR}" BUILD_POSITION)
|
|
|
|
string(FIND "${PATH}" "NOTFOUND" NOTFOUND_POSITION)
|
|
|
|
if(${NOTFOUND_POSITION} GREATER 0)
|
|
|
|
WARNING_LOG("Could not find library: ${NAME}")
|
2015-06-12 01:13:37 +00:00
|
|
|
else()
|
2015-07-16 22:23:29 +00:00
|
|
|
if(${BUILD_POSITION} EQUAL 0)
|
|
|
|
string(LENGTH "${CMAKE_BINARY_DIR}" BUILD_DIR_LENGTH)
|
|
|
|
string(SUBSTRING "${PATH}" ${BUILD_DIR_LENGTH} -1 LIB_PATH)
|
|
|
|
LOG("Found osquery-built library ${ESC}[32m${LIB_PATH}${ESC}[m")
|
|
|
|
else()
|
|
|
|
LOG("Found library ${ESC}[32m${PATH}${ESC}[m")
|
|
|
|
endif()
|
2015-06-12 01:13:37 +00:00
|
|
|
endif()
|
2015-05-23 22:43:54 +00:00
|
|
|
endif()
|
|
|
|
endmacro(LOG_LIBRARY)
|
|
|
|
|
2016-08-13 02:25:28 +00:00
|
|
|
macro(SET_OSQUERY_COMPILE TARGET)
|
|
|
|
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}")
|
2017-10-09 07:27:28 +00:00
|
|
|
endif()
|
|
|
|
if(DO_CLANG_TIDY AND NOT "${TARGET}" STREQUAL "osquery_extensions")
|
|
|
|
set_target_properties(${TARGET} PROPERTIES CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
|
2016-08-13 02:25:28 +00:00
|
|
|
endif()
|
|
|
|
endmacro(SET_OSQUERY_COMPILE)
|
|
|
|
|
|
|
|
macro(ADD_DEFAULT_LINKS TARGET ADDITIONAL)
|
|
|
|
if(DEFINED ENV{OSQUERY_BUILD_SHARED})
|
|
|
|
target_link_libraries(${TARGET} libosquery_shared)
|
|
|
|
if(${ADDITIONAL})
|
|
|
|
target_link_libraries(${TARGET} libosquery_additional_shared)
|
|
|
|
endif()
|
2017-09-10 00:08:46 +00:00
|
|
|
target_link_libraries(${TARGET} "-Wl,-rpath,${CMAKE_BINARY_DIR}/osquery")
|
|
|
|
target_link_libraries(${TARGET} ${OSQUERY_LINKS})
|
|
|
|
if(${ADDITIONAL})
|
|
|
|
target_link_libraries(${TARGET} ${OSQUERY_ADDITIONAL_LINKS})
|
2016-08-13 02:25:28 +00:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(${TARGET} libosquery)
|
|
|
|
if(${ADDITIONAL})
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(${TARGET} libosquery_additional)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2015-02-26 19:35:54 +00:00
|
|
|
macro(ADD_OSQUERY_PYTHON_TEST TEST_NAME SOURCE)
|
2017-07-21 18:20:56 +00:00
|
|
|
if(NOT DEFINED ENV{SKIP_INTEGRATION_TESTS})
|
2016-09-14 03:37:31 +00:00
|
|
|
add_test(NAME python_${TEST_NAME}
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_SOURCE_DIR}/tools/tests/${SOURCE}"
|
|
|
|
--build "${CMAKE_BINARY_DIR}"
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/tools/tests/")
|
|
|
|
endif()
|
2015-02-26 19:35:54 +00:00
|
|
|
endmacro(ADD_OSQUERY_PYTHON_TEST)
|
|
|
|
|
2015-05-20 20:27:53 +00:00
|
|
|
# Add a static or dynamic link to libosquery.a (the core library)
|
|
|
|
macro(ADD_OSQUERY_LINK_CORE LINK)
|
|
|
|
ADD_OSQUERY_LINK(TRUE ${LINK} ${ARGN})
|
|
|
|
endmacro(ADD_OSQUERY_LINK_CORE)
|
|
|
|
|
|
|
|
# Add a static or dynamic link to libosquery_additional.a (the non-sdk library)
|
|
|
|
macro(ADD_OSQUERY_LINK_ADDITIONAL LINK)
|
|
|
|
ADD_OSQUERY_LINK(FALSE ${LINK} ${ARGN})
|
|
|
|
endmacro(ADD_OSQUERY_LINK_ADDITIONAL)
|
|
|
|
|
2014-12-31 16:28:08 +00:00
|
|
|
# Core/non core link helping macros (tell the build to link ALL).
|
2015-02-03 05:21:36 +00:00
|
|
|
macro(ADD_OSQUERY_LINK IS_CORE LINK)
|
|
|
|
if(${IS_CORE})
|
|
|
|
ADD_OSQUERY_LINK_INTERNAL("${LINK}" "${ARGN}" OSQUERY_LINKS)
|
|
|
|
elseif(NOT OSQUERY_BUILD_SDK_ONLY)
|
|
|
|
ADD_OSQUERY_LINK_INTERNAL("${LINK}" "${ARGN}" OSQUERY_ADDITIONAL_LINKS)
|
|
|
|
endif()
|
2014-12-31 16:28:08 +00:00
|
|
|
endmacro(ADD_OSQUERY_LINK)
|
|
|
|
|
2015-01-05 16:05:41 +00:00
|
|
|
macro(ADD_OSQUERY_LINK_INTERNAL LINK LINK_PATHS LINK_SET)
|
2016-09-23 23:20:03 +00:00
|
|
|
# The relative linking set is used for static libraries.
|
2016-07-31 18:32:31 +00:00
|
|
|
set(LINK_PATHS_RELATIVE
|
|
|
|
"${BUILD_DEPS}/lib"
|
|
|
|
${LINK_PATHS}
|
2016-08-10 21:06:47 +00:00
|
|
|
${OS_LIB_DIRS}
|
2016-07-31 18:32:31 +00:00
|
|
|
"$ENV{HOME}"
|
|
|
|
)
|
2016-09-23 23:20:03 +00:00
|
|
|
|
|
|
|
# The system linking set is for legacy ABI compatibility links and libraries
|
|
|
|
# known to exist on the system.
|
2016-07-31 18:32:31 +00:00
|
|
|
set(LINK_PATHS_SYSTEM
|
|
|
|
${LINK_PATHS}
|
|
|
|
"${BUILD_DEPS}/legacy/lib"
|
|
|
|
)
|
2016-09-23 23:20:03 +00:00
|
|
|
if(LINUX)
|
|
|
|
# Allow the build to search the 'default' dependency home for libgcc_s.
|
|
|
|
list(APPEND LINK_PATHS_SYSTEM "${BUILD_DEPS}/lib")
|
|
|
|
endif()
|
|
|
|
# The OS library paths are very important for system linking.
|
|
|
|
list(APPEND LINK_PATHS_SYSTEM ${OS_LIB_DIRS})
|
2016-07-31 18:32:31 +00:00
|
|
|
|
2015-05-04 03:02:01 +00:00
|
|
|
if(NOT "${LINK}" MATCHES "(^[-/].*)")
|
2015-05-13 07:31:02 +00:00
|
|
|
string(REPLACE " " ";" ITEMS "${LINK}")
|
|
|
|
foreach(ITEM ${ITEMS})
|
2015-07-28 09:02:31 +00:00
|
|
|
if(NOT DEFINED ${${ITEM}_library})
|
2016-08-10 21:06:47 +00:00
|
|
|
if("${ITEM}" MATCHES "(^lib.*)" OR "${ITEM}" MATCHES "(.*lib$)" OR DEFINED ENV{BUILD_LINK_SHARED})
|
2016-07-31 18:32:31 +00:00
|
|
|
# Use a system-provided library
|
|
|
|
set(ITEM_SYSTEM TRUE)
|
|
|
|
else()
|
|
|
|
set(ITEM_SYSTEM FALSE)
|
|
|
|
endif()
|
|
|
|
if(NOT ${ITEM_SYSTEM})
|
2015-07-28 09:02:31 +00:00
|
|
|
find_library("${ITEM}_library"
|
2017-06-16 03:59:53 +00:00
|
|
|
NAMES
|
|
|
|
"${ITEM}.lib"
|
|
|
|
"lib${ITEM}.lib"
|
|
|
|
"lib${ITEM}-mt.a"
|
|
|
|
"lib${ITEM}.a"
|
|
|
|
"${ITEM}"
|
|
|
|
HINTS ${LINK_PATHS_RELATIVE})
|
2015-07-28 09:02:31 +00:00
|
|
|
else()
|
|
|
|
find_library("${ITEM}_library"
|
2017-06-16 03:59:53 +00:00
|
|
|
NAMES
|
|
|
|
"${ITEM}.lib"
|
|
|
|
"lib${ITEM}.lib"
|
|
|
|
"lib${ITEM}-mt.so"
|
|
|
|
"lib${ITEM}.so"
|
|
|
|
"lib${ITEM}-mt.dylib"
|
|
|
|
"lib${ITEM}.dylib"
|
|
|
|
"${ITEM}-mt.so"
|
|
|
|
"${ITEM}.so"
|
|
|
|
"${ITEM}-mt.dylib"
|
|
|
|
"${ITEM}.dylib"
|
|
|
|
"${ITEM}"
|
2016-07-31 18:32:31 +00:00
|
|
|
HINTS ${LINK_PATHS_SYSTEM})
|
2015-07-28 09:02:31 +00:00
|
|
|
endif()
|
|
|
|
LOG_LIBRARY(${ITEM} "${${ITEM}_library}")
|
2016-08-10 21:06:47 +00:00
|
|
|
if("${${ITEM}_library}" STREQUAL "${ITEM}_library-NOTFOUND")
|
2015-07-28 09:02:31 +00:00
|
|
|
WARNING_LOG("Dependent library '${ITEM}' not found")
|
|
|
|
list(APPEND ${LINK_SET} ${ITEM})
|
|
|
|
else()
|
|
|
|
list(APPEND ${LINK_SET} "${${ITEM}_library}")
|
|
|
|
endif()
|
2015-05-13 07:31:02 +00:00
|
|
|
endif()
|
2016-08-17 02:12:55 +00:00
|
|
|
if("${${ITEM}_library}" MATCHES "/usr/local/lib.*")
|
2017-03-27 06:53:06 +00:00
|
|
|
if(NOT FREEBSD)
|
|
|
|
WARNING_LOG("Dependent library '${ITEM}' installed locally (beware!)")
|
|
|
|
endif()
|
2016-08-17 02:12:55 +00:00
|
|
|
endif()
|
2015-05-13 07:31:02 +00:00
|
|
|
endforeach()
|
2015-01-05 16:05:41 +00:00
|
|
|
else()
|
|
|
|
list(APPEND ${LINK_SET} ${LINK})
|
|
|
|
endif()
|
|
|
|
set(${LINK_SET} "${${LINK_SET}}" PARENT_SCOPE)
|
|
|
|
endmacro(ADD_OSQUERY_LINK_INTERNAL)
|
|
|
|
|
2015-05-20 20:27:53 +00:00
|
|
|
# Add a test and sources for components in libosquery.a (the core library)
|
|
|
|
macro(ADD_OSQUERY_TEST_CORE)
|
|
|
|
ADD_OSQUERY_TEST(TRUE ${ARGN})
|
|
|
|
endmacro(ADD_OSQUERY_TEST_CORE)
|
|
|
|
|
|
|
|
# Add a test and sources for components in libosquery_additional.a (the non-sdk library)
|
|
|
|
macro(ADD_OSQUERY_TEST_ADDITIONAL)
|
|
|
|
ADD_OSQUERY_TEST(FALSE ${ARGN})
|
|
|
|
endmacro(ADD_OSQUERY_TEST_ADDITIONAL)
|
|
|
|
|
|
|
|
# Core/non core test names and sources macros.
|
2015-04-27 09:12:58 +00:00
|
|
|
macro(ADD_OSQUERY_TEST IS_CORE)
|
2017-04-28 20:45:41 +00:00
|
|
|
if(NOT SKIP_TESTS AND (${IS_CORE} OR NOT OSQUERY_BUILD_SDK_ONLY))
|
2015-04-27 09:12:58 +00:00
|
|
|
if(${IS_CORE})
|
|
|
|
list(APPEND OSQUERY_TESTS ${ARGN})
|
|
|
|
set(OSQUERY_TESTS ${OSQUERY_TESTS} PARENT_SCOPE)
|
|
|
|
else()
|
|
|
|
list(APPEND OSQUERY_ADDITIONAL_TESTS ${ARGN})
|
|
|
|
set(OSQUERY_ADDITIONAL_TESTS ${OSQUERY_ADDITIONAL_TESTS} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endmacro(ADD_OSQUERY_TEST)
|
|
|
|
|
|
|
|
macro(ADD_OSQUERY_TABLE_TEST)
|
2017-04-28 20:45:41 +00:00
|
|
|
if(NOT SKIP_TESTS AND NOT OSQUERY_BUILD_SDK_ONLY)
|
2015-04-27 09:12:58 +00:00
|
|
|
list(APPEND OSQUERY_TABLES_TESTS ${ARGN})
|
|
|
|
set(OSQUERY_TABLES_TESTS ${OSQUERY_TABLES_TESTS} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endmacro(ADD_OSQUERY_TABLE_TEST)
|
|
|
|
|
2015-06-30 21:20:04 +00:00
|
|
|
# Add kernel test macro.
|
|
|
|
macro(ADD_OSQUERY_KERNEL_TEST)
|
2017-04-28 20:45:41 +00:00
|
|
|
if(NOT SKIP_TESTS)
|
2015-06-30 21:20:04 +00:00
|
|
|
list(APPEND OSQUERY_KERNEL_TESTS ${ARGN})
|
|
|
|
set(OSQUERY_KERNEL_TESTS ${OSQUERY_KERNEL_TESTS} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endmacro(ADD_OSQUERY_KERNEL_TEST)
|
|
|
|
|
2015-07-23 23:42:46 +00:00
|
|
|
# Add benchmark macro.
|
|
|
|
macro(ADD_OSQUERY_BENCHMARK)
|
2017-04-28 20:45:41 +00:00
|
|
|
if(NOT SKIP_TESTS)
|
2015-07-23 23:42:46 +00:00
|
|
|
list(APPEND OSQUERY_BENCHMARKS ${ARGN})
|
|
|
|
set(OSQUERY_BENCHMARKS ${OSQUERY_BENCHMARKS} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endmacro(ADD_OSQUERY_BENCHMARK)
|
|
|
|
|
|
|
|
# Add kernel benchmark macro.
|
|
|
|
macro(ADD_OSQUERY_KERNEL_BENCHMARK)
|
2017-04-28 20:45:41 +00:00
|
|
|
if(NOT SKIP_TESTS)
|
2015-07-23 23:42:46 +00:00
|
|
|
list(APPEND OSQUERY_KERNEL_BENCHMARKS ${ARGN})
|
|
|
|
set(OSQUERY_KERNEL_BENCHMARKS ${OSQUERY_KERNEL_BENCHMARKS} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endmacro(ADD_OSQUERY_KERNEL_BENCHMARK)
|
|
|
|
|
2015-05-20 20:27:53 +00:00
|
|
|
# Add sources to libosquery.a (the core library)
|
|
|
|
macro(ADD_OSQUERY_LIBRARY_CORE TARGET)
|
|
|
|
ADD_OSQUERY_LIBRARY(TRUE ${TARGET} ${ARGN})
|
|
|
|
endmacro(ADD_OSQUERY_LIBRARY_CORE)
|
|
|
|
|
|
|
|
# Add sources to libosquery_additional.a (the non-sdk library)
|
|
|
|
macro(ADD_OSQUERY_LIBRARY_ADDITIONAL TARGET)
|
|
|
|
ADD_OSQUERY_LIBRARY(FALSE ${TARGET} ${ARGN})
|
|
|
|
endmacro(ADD_OSQUERY_LIBRARY_ADDITIONAL)
|
|
|
|
|
2014-12-31 16:28:08 +00:00
|
|
|
# Core/non core lists of target source files.
|
2015-02-03 05:21:36 +00:00
|
|
|
macro(ADD_OSQUERY_LIBRARY IS_CORE TARGET)
|
|
|
|
if(${IS_CORE} OR NOT OSQUERY_BUILD_SDK_ONLY)
|
2017-04-28 20:45:41 +00:00
|
|
|
foreach(SOURCE_FILE ${ARGN})
|
|
|
|
set(EXT_POSITION -1)
|
|
|
|
string(FIND "${SOURCE_FILE}" ".mm" EXT_POSITION)
|
|
|
|
if(EXT_POSITION GREATER 0)
|
|
|
|
SET_SOURCE_FILES_PROPERTIES("${SOURCE_FILE}"
|
|
|
|
PROPERTIES COMPILE_FLAGS ${OBJCXX_COMPILE_FLAGS})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2015-02-03 05:21:36 +00:00
|
|
|
add_library(${TARGET} OBJECT ${ARGN})
|
2016-03-07 09:06:02 +00:00
|
|
|
add_dependencies(${TARGET} osquery_extensions)
|
2015-02-03 05:21:36 +00:00
|
|
|
if(${IS_CORE})
|
|
|
|
list(APPEND OSQUERY_SOURCES $<TARGET_OBJECTS:${TARGET}>)
|
|
|
|
set(OSQUERY_SOURCES ${OSQUERY_SOURCES} PARENT_SCOPE)
|
|
|
|
else()
|
|
|
|
list(APPEND OSQUERY_ADDITIONAL_SOURCES $<TARGET_OBJECTS:${TARGET}>)
|
|
|
|
set(OSQUERY_ADDITIONAL_SOURCES ${OSQUERY_ADDITIONAL_SOURCES} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endif()
|
2014-12-31 16:28:08 +00:00
|
|
|
endmacro(ADD_OSQUERY_LIBRARY TARGET)
|
|
|
|
|
2015-03-04 02:40:24 +00:00
|
|
|
macro(ADD_OSQUERY_EXTENSION TARGET)
|
|
|
|
add_executable(${TARGET} ${ARGN})
|
|
|
|
TARGET_OSQUERY_LINK_WHOLE(${TARGET} libosquery)
|
2015-03-13 15:11:08 +00:00
|
|
|
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME "${TARGET}.ext")
|
2015-03-04 02:40:24 +00:00
|
|
|
endmacro(ADD_OSQUERY_EXTENSION)
|
|
|
|
|
2014-12-31 16:28:08 +00:00
|
|
|
# Helper to abstract OS/Compiler whole linking.
|
2017-09-10 00:08:46 +00:00
|
|
|
macro(TARGET_OSQUERY_LINK_WHOLE TARGET OSQUERY_LIB)
|
|
|
|
if(WINDOWS)
|
|
|
|
target_link_libraries(${TARGET} "${OS_WHOLELINK_PRE}$<TARGET_FILE_NAME:${OSQUERY_LIB}>")
|
|
|
|
target_link_libraries(${TARGET} ${OSQUERY_LIB})
|
|
|
|
else()
|
|
|
|
target_link_libraries(${TARGET} "${OS_WHOLELINK_PRE}")
|
|
|
|
target_link_libraries(${TARGET} ${OSQUERY_LIB})
|
|
|
|
target_link_libraries(${TARGET} "${OS_WHOLELINK_POST}")
|
|
|
|
endif()
|
|
|
|
endmacro(TARGET_OSQUERY_LINK_WHOLE)
|
2014-12-23 22:35:48 +00:00
|
|
|
|
2014-12-24 04:07:12 +00:00
|
|
|
set(GLOBAL PROPERTY AMALGAMATE_TARGETS "")
|
|
|
|
macro(GET_GENERATION_DEPS BASE_PATH)
|
|
|
|
# Depend on the generation code.
|
|
|
|
set(GENERATION_DEPENDENCIES "")
|
2017-01-07 20:21:35 +00:00
|
|
|
file(GLOB TABLE_FILES_TEMPLATES "${BASE_PATH}/tools/codegen/templates/*.in")
|
2016-05-11 21:16:32 +00:00
|
|
|
file(GLOB CODEGEN_PYTHON_FILES "${BASE_PATH}/tools/codegen/*.py")
|
2014-12-24 04:07:12 +00:00
|
|
|
set(GENERATION_DEPENDENCIES
|
2015-06-01 22:53:52 +00:00
|
|
|
"${BASE_PATH}/specs/blacklist"
|
2014-12-24 04:07:12 +00:00
|
|
|
)
|
2017-01-07 20:21:35 +00:00
|
|
|
list(APPEND GENERATION_DEPENDENCIES ${CODEGEN_PYTHON_FILES})
|
2014-12-24 04:07:12 +00:00
|
|
|
list(APPEND GENERATION_DEPENDENCIES ${TABLE_FILES_TEMPLATES})
|
|
|
|
endmacro()
|
|
|
|
|
2014-12-23 22:35:48 +00:00
|
|
|
# Find and generate table plugins from .table syntax
|
2015-03-04 16:45:21 +00:00
|
|
|
macro(GENERATE_TABLES TABLES_PATH)
|
2014-12-25 20:46:59 +00:00
|
|
|
# Get all matching files for all platforms.
|
2016-04-11 16:33:45 +00:00
|
|
|
set(TABLES_SPECS "${TABLES_PATH}/specs")
|
|
|
|
set(TABLE_CATEGORIES "")
|
2014-12-23 22:35:48 +00:00
|
|
|
if(APPLE)
|
2017-08-07 16:08:53 +00:00
|
|
|
list(APPEND TABLE_CATEGORIES "darwin" "posix" "macwin")
|
2014-12-23 22:35:48 +00:00
|
|
|
elseif(FREEBSD)
|
2016-06-23 23:04:11 +00:00
|
|
|
list(APPEND TABLE_CATEGORIES "freebsd" "posix")
|
|
|
|
elseif(LINUX)
|
|
|
|
list(APPEND TABLE_CATEGORIES "linux" "posix")
|
2016-08-10 21:06:47 +00:00
|
|
|
elseif(WINDOWS)
|
2017-08-07 16:08:53 +00:00
|
|
|
list(APPEND TABLE_CATEGORIES "windows" "macwin")
|
2016-06-23 23:04:11 +00:00
|
|
|
else()
|
|
|
|
message( FATAL_ERROR "Unknown platform detected, cannot generate tables")
|
2014-12-23 22:35:48 +00:00
|
|
|
endif()
|
|
|
|
|
2017-04-28 20:45:41 +00:00
|
|
|
# Features optionally disabled.
|
|
|
|
if(NOT SKIP_LLDPD AND NOT WINDOWS)
|
|
|
|
list(APPEND TABLE_CATEGORIES "lldpd")
|
|
|
|
endif()
|
|
|
|
if(NOT SKIP_YARA AND NOT WINDOWS)
|
|
|
|
list(APPEND TABLE_CATEGORIES "yara")
|
|
|
|
endif()
|
|
|
|
if(NOT SKIP_TSK AND NOT WINDOWS)
|
|
|
|
list(APPEND TABLE_CATEGORIES "sleuthkit")
|
|
|
|
endif()
|
|
|
|
|
2016-04-11 16:33:45 +00:00
|
|
|
file(GLOB TABLE_FILES "${TABLES_SPECS}/*.table")
|
|
|
|
set(TABLE_FILES_FOREIGN "")
|
|
|
|
file(GLOB ALL_CATEGORIES RELATIVE "${TABLES_SPECS}" "${TABLES_SPECS}/*")
|
|
|
|
foreach(CATEGORY ${ALL_CATEGORIES})
|
|
|
|
if(IS_DIRECTORY "${TABLES_SPECS}/${CATEGORY}" AND NOT "${CATEGORY}" STREQUAL "utility")
|
|
|
|
file(GLOB TABLE_FILES_PLATFORM "${TABLES_SPECS}/${CATEGORY}/*.table")
|
|
|
|
list(FIND TABLE_CATEGORIES "${CATEGORY}" INDEX)
|
|
|
|
if(${INDEX} EQUAL -1)
|
|
|
|
# Append inner tables to foreign
|
|
|
|
list(APPEND TABLE_FILES_FOREIGN ${TABLE_FILES_PLATFORM})
|
|
|
|
else()
|
|
|
|
# Append inner tables to TABLE_FILES.
|
|
|
|
list(APPEND TABLE_FILES ${TABLE_FILES_PLATFORM})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Generate a set of targets, comprised of table spec file.
|
2014-12-25 20:46:59 +00:00
|
|
|
get_property(TARGETS GLOBAL PROPERTY AMALGAMATE_TARGETS)
|
|
|
|
set(NEW_TARGETS "")
|
2014-12-24 04:07:12 +00:00
|
|
|
foreach(TABLE_FILE ${TABLE_FILES})
|
2014-12-25 20:46:59 +00:00
|
|
|
list(FIND TARGETS "${TABLE_FILE}" INDEX)
|
|
|
|
if (${INDEX} EQUAL -1)
|
|
|
|
# Do not set duplicate targets.
|
|
|
|
list(APPEND NEW_TARGETS "${TABLE_FILE}")
|
|
|
|
endif()
|
2014-12-24 04:07:12 +00:00
|
|
|
endforeach()
|
2014-12-25 20:46:59 +00:00
|
|
|
set_property(GLOBAL PROPERTY AMALGAMATE_TARGETS "${NEW_TARGETS}")
|
2016-04-11 16:33:45 +00:00
|
|
|
set_property(GLOBAL PROPERTY AMALGAMATE_FOREIGN_TARGETS "${TABLE_FILES_FOREIGN}")
|
2014-12-24 04:07:12 +00:00
|
|
|
endmacro()
|
|
|
|
|
2015-03-04 16:45:21 +00:00
|
|
|
macro(GENERATE_UTILITIES TABLES_PATH)
|
2015-03-04 02:40:24 +00:00
|
|
|
file(GLOB TABLE_FILES_UTILITY "${TABLES_PATH}/specs/utility/*.table")
|
|
|
|
set_property(GLOBAL APPEND PROPERTY AMALGAMATE_TARGETS "${TABLE_FILES_UTILITY}")
|
2015-03-04 16:45:21 +00:00
|
|
|
endmacro(GENERATE_UTILITIES)
|
2014-12-24 04:07:12 +00:00
|
|
|
|
2016-04-11 16:33:45 +00:00
|
|
|
macro(GENERATE_TABLE TABLE_FILE FOREIGN NAME BASE_PATH OUTPUT)
|
|
|
|
GET_GENERATION_DEPS(${BASE_PATH})
|
|
|
|
set(TABLE_FILE_GEN "${TABLE_FILE}")
|
2015-01-07 19:02:40 +00:00
|
|
|
string(REGEX REPLACE
|
2015-04-16 00:30:16 +00:00
|
|
|
".*/specs.*/(.*)\\.table"
|
2014-12-31 17:33:19 +00:00
|
|
|
"${CMAKE_BINARY_DIR}/generated/tables_${NAME}/\\1.cpp"
|
2014-12-24 04:07:12 +00:00
|
|
|
TABLE_FILE_GEN
|
|
|
|
${TABLE_FILE_GEN}
|
2014-12-23 22:35:48 +00:00
|
|
|
)
|
|
|
|
|
2014-12-24 04:07:12 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${TABLE_FILE_GEN}"
|
2016-04-11 16:33:45 +00:00
|
|
|
COMMAND "${PYTHON_EXECUTABLE}"
|
|
|
|
"${BASE_PATH}/tools/codegen/gentable.py"
|
|
|
|
"${FOREIGN}"
|
|
|
|
"${TABLE_FILE}"
|
|
|
|
"${TABLE_FILE_GEN}"
|
2014-12-24 04:07:12 +00:00
|
|
|
DEPENDS ${TABLE_FILE} ${GENERATION_DEPENDENCIES}
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
)
|
2014-12-23 22:35:48 +00:00
|
|
|
|
2014-12-24 04:07:12 +00:00
|
|
|
list(APPEND ${OUTPUT} "${TABLE_FILE_GEN}")
|
2015-03-04 16:45:21 +00:00
|
|
|
endmacro(GENERATE_TABLE)
|
2014-12-24 04:07:12 +00:00
|
|
|
|
2014-12-24 04:53:59 +00:00
|
|
|
macro(AMALGAMATE BASE_PATH NAME OUTPUT)
|
2014-12-24 04:07:12 +00:00
|
|
|
GET_GENERATION_DEPS(${BASE_PATH})
|
2016-04-11 16:33:45 +00:00
|
|
|
if("${NAME}" STREQUAL "foreign")
|
|
|
|
get_property(TARGETS GLOBAL PROPERTY AMALGAMATE_FOREIGN_TARGETS)
|
|
|
|
set(FOREIGN "--foreign")
|
|
|
|
else()
|
|
|
|
get_property(TARGETS GLOBAL PROPERTY AMALGAMATE_TARGETS)
|
|
|
|
endif()
|
2014-12-24 04:07:12 +00:00
|
|
|
|
|
|
|
set(GENERATED_TARGETS "")
|
2016-09-29 00:15:24 +00:00
|
|
|
|
2014-12-24 04:07:12 +00:00
|
|
|
foreach(TARGET ${TARGETS})
|
2016-04-11 16:33:45 +00:00
|
|
|
GENERATE_TABLE("${TARGET}" "${FOREIGN}" "${NAME}" "${BASE_PATH}" GENERATED_TARGETS)
|
2014-12-23 22:35:48 +00:00
|
|
|
endforeach()
|
|
|
|
|
2014-12-25 20:46:59 +00:00
|
|
|
# Include the generated folder in make clean.
|
|
|
|
set_directory_properties(PROPERTY
|
|
|
|
ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_BINARY_DIR}/generated")
|
|
|
|
|
2014-12-23 22:35:48 +00:00
|
|
|
# Append all of the code to a single amalgamation.
|
2016-08-13 02:25:28 +00:00
|
|
|
set(AMALGAMATION_FILE_GEN "${CMAKE_BINARY_DIR}/generated/${NAME}_amalgamation.cpp")
|
2014-12-24 04:07:12 +00:00
|
|
|
add_custom_command(
|
2016-08-13 02:25:28 +00:00
|
|
|
OUTPUT ${AMALGAMATION_FILE_GEN}
|
2016-04-11 16:33:45 +00:00
|
|
|
COMMAND "${PYTHON_EXECUTABLE}"
|
|
|
|
"${BASE_PATH}/tools/codegen/amalgamate.py"
|
|
|
|
"${FOREIGN}"
|
|
|
|
"${BASE_PATH}/tools/codegen/"
|
|
|
|
"${CMAKE_BINARY_DIR}/generated"
|
|
|
|
"${NAME}"
|
2014-12-24 04:07:12 +00:00
|
|
|
DEPENDS ${GENERATED_TARGETS} ${GENERATION_DEPENDENCIES}
|
2014-12-23 22:35:48 +00:00
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
)
|
|
|
|
|
2016-08-13 02:25:28 +00:00
|
|
|
set(${OUTPUT} ${AMALGAMATION_FILE_GEN})
|
2017-05-11 06:31:44 +00:00
|
|
|
set_property(GLOBAL PROPERTY AMALGAMATE_TARGETS "")
|
2015-03-04 16:45:21 +00:00
|
|
|
endmacro(AMALGAMATE)
|
2015-01-08 23:53:51 +00:00
|
|
|
|
|
|
|
function(JOIN VALUES GLUE OUTPUT)
|
2015-02-04 03:55:16 +00:00
|
|
|
string(REPLACE ";" "${GLUE}" _TMP_STR "${VALUES}")
|
|
|
|
set(${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
|
2015-01-08 23:53:51 +00:00
|
|
|
endfunction(JOIN)
|