2014-12-23 22:35:48 +00:00
|
|
|
# -*- mode: cmake; -*-
|
|
|
|
# - osquery table plugin generation
|
|
|
|
#
|
|
|
|
# Generate table plugin code from .table syntax.
|
|
|
|
# Compile and link the core set of osquery tables/streams.
|
|
|
|
|
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 "")
|
|
|
|
file(GLOB TABLE_FILES_TEMPLATES "${BASE_PATH}/osquery/tables/templates/*.in")
|
|
|
|
set(GENERATION_DEPENDENCIES
|
|
|
|
"${BASE_PATH}/tools/codegen/*.py"
|
|
|
|
"${BASE_PATH}/osquery/tables/specs/blacklist"
|
|
|
|
)
|
|
|
|
list(APPEND GENERATION_DEPENDENCIES ${TABLE_FILES_TEMPLATES})
|
|
|
|
endmacro()
|
|
|
|
|
2014-12-23 22:35:48 +00:00
|
|
|
# Find and generate table plugins from .table syntax
|
2014-12-24 04:07:12 +00:00
|
|
|
macro(GENERATE_TABLES TABLES_PATH BASE_PATH)
|
|
|
|
set(TABLE_FILES_PLATFORM "")
|
2014-12-23 22:35:48 +00:00
|
|
|
file(GLOB TABLE_FILES "${TABLES_PATH}/specs/x/*.table")
|
2014-12-24 04:07:12 +00:00
|
|
|
|
2014-12-23 22:35:48 +00:00
|
|
|
if(APPLE)
|
2014-12-24 04:07:12 +00:00
|
|
|
file(GLOB TABLE_FILES_PLATFORM "${TABLES_PATH}/specs/darwin/*.table")
|
2014-12-23 22:35:48 +00:00
|
|
|
elseif(FREEBSD)
|
2014-12-24 04:07:12 +00:00
|
|
|
file(GLOB TABLE_FILES_PLATFORM "${TABLES_PATH}/specs/freebsd/*.table")
|
2014-12-23 22:35:48 +00:00
|
|
|
else()
|
2014-12-24 04:07:12 +00:00
|
|
|
file(GLOB TABLE_FILES_PLATFORM "${TABLES_PATH}/specs/linux/*.table")
|
2014-12-23 22:35:48 +00:00
|
|
|
endif()
|
|
|
|
|
2014-12-24 04:07:12 +00:00
|
|
|
list(APPEND TABLE_FILES ${TABLE_FILES_PLATFORM})
|
2014-12-23 22:35:48 +00:00
|
|
|
set_directory_properties(PROPERTY
|
2014-12-24 04:07:12 +00:00
|
|
|
ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_BINARY_DIR}/generated")
|
|
|
|
GET_GENERATION_DEPS("${BASE_PATH}")
|
2014-12-23 22:35:48 +00:00
|
|
|
|
2014-12-24 04:07:12 +00:00
|
|
|
foreach(TABLE_FILE ${TABLE_FILES})
|
|
|
|
set_property(GLOBAL APPEND PROPERTY AMALGAMATE_TARGETS "${TABLE_FILE}")
|
|
|
|
endforeach()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(GENERATE_UTILITY TABLE_NAME)
|
|
|
|
set(TABLE_SPEC "${CMAKE_SOURCE_DIR}/osquery/tables/specs/x/${TABLE_NAME}.table")
|
|
|
|
set_property(GLOBAL APPEND PROPERTY AMALGAMATE_TARGETS "${TABLE_SPEC}")
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(GENERATE_TABLE TABLE_FILE BASE_PATH OUTPUT)
|
|
|
|
SET(TABLE_FILE_GEN ${TABLE_FILE})
|
|
|
|
STRING(REPLACE ".table" ".cpp" TABLE_FILE_GEN ${TABLE_FILE_GEN})
|
|
|
|
STRING(REPLACE "linux/" "" TABLE_FILE_GEN ${TABLE_FILE_GEN})
|
|
|
|
STRING(REPLACE "darwin/" "" TABLE_FILE_GEN ${TABLE_FILE_GEN})
|
|
|
|
STRING(REPLACE "freebsd/" "" TABLE_FILE_GEN ${TABLE_FILE_GEN})
|
|
|
|
STRING(REPLACE "x/" "" TABLE_FILE_GEN ${TABLE_FILE_GEN})
|
|
|
|
STRING(REGEX REPLACE
|
|
|
|
".*/specs"
|
|
|
|
"${CMAKE_BINARY_DIR}/generated/tables"
|
|
|
|
TABLE_FILE_GEN
|
|
|
|
${TABLE_FILE_GEN}
|
2014-12-23 22:35:48 +00:00
|
|
|
)
|
|
|
|
|
2014-12-24 04:07:12 +00:00
|
|
|
GET_GENERATION_DEPS(${BASE_PATH})
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${TABLE_FILE_GEN}"
|
|
|
|
COMMAND python "${BASE_PATH}/tools/codegen/gentable.py"
|
|
|
|
"${TABLE_FILE}" "${TABLE_FILE_GEN}" "$ENV{DISABLE_BLACKLIST}"
|
|
|
|
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}")
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
macro(AMALGAMATE BASE_PATH OUTPUT)
|
|
|
|
GET_GENERATION_DEPS(${BASE_PATH})
|
|
|
|
get_property(TARGETS GLOBAL PROPERTY AMALGAMATE_TARGETS)
|
|
|
|
|
|
|
|
set(GENERATED_TARGETS "")
|
|
|
|
foreach(TARGET ${TARGETS})
|
|
|
|
GENERATE_TABLE(${TARGET} ${BASE_PATH} GENERATED_TARGETS)
|
2014-12-23 22:35:48 +00:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Append all of the code to a single amalgamation.
|
2014-12-24 04:07:12 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${CMAKE_BINARY_DIR}/generated/amalgamation.cpp"
|
|
|
|
COMMAND python "${BASE_PATH}/tools/codegen/amalgamate.py"
|
|
|
|
"${BASE_PATH}/osquery/tables/" "${CMAKE_BINARY_DIR}/generated"
|
|
|
|
DEPENDS ${GENERATED_TARGETS} ${GENERATION_DEPENDENCIES}
|
2014-12-23 22:35:48 +00:00
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
)
|
|
|
|
|
2014-12-24 04:07:12 +00:00
|
|
|
SET(${OUTPUT} "${CMAKE_BINARY_DIR}/generated/amalgamation.cpp")
|
|
|
|
endmacro()
|