mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-08 02:18:53 +00:00
e973c856c6
I used CPack to generate deb package files from the CMake "install" target. What this means is, whatever would get installed my "make install" will get installed by the deb. "make package" on ubuntu will generate a file named: `osquery-$VERSION-$DISTRO.$ARCH.deb` Consider the following example: ``` root@vagrant-ubuntu-trusty-64:/vagrant/build# dpkg --info osquery-0.0.1-trusty.amd64.deb new debian package, version 2.0. size 11311330 bytes: control archive=350 bytes. 207 bytes, 9 lines control 102 bytes, 2 lines md5sums Package: osquery Version: 0.0.1 Section: devel Priority: optional Architecture: amd64 Installed-Size: 43369 Maintainer: marpaia@fb.com Description: osquery is an operating system instrumentation toolchain. ```
177 lines
5.3 KiB
CMake
177 lines
5.3 KiB
CMake
SET(OSQUERY_LIBS
|
|
# general
|
|
readline
|
|
|
|
# sqlite
|
|
pthread
|
|
dl
|
|
|
|
# gflags
|
|
libgflags.a
|
|
|
|
# glog
|
|
libglog.a
|
|
|
|
# gtest
|
|
gtest
|
|
|
|
# rocksdb
|
|
librocksdb.a
|
|
libsnappy.a
|
|
bz2
|
|
z
|
|
|
|
# thrift
|
|
libthrift.a
|
|
crypto
|
|
ssl
|
|
|
|
# boost
|
|
libboost_system.a
|
|
libboost_filesystem.a
|
|
libboost_program_options.a
|
|
)
|
|
|
|
# Handle naming differences in MT threading
|
|
if(APPLE)
|
|
list(APPEND OSQUERY_LIBS "libboost_thread-mt.a")
|
|
else()
|
|
list(APPEND OSQUERY_LIBS "libboost_thread.a")
|
|
list(APPEND OSQUERY_LIBS "libunwind.a")
|
|
list(APPEND OSQUERY_LIBS "liblzma.a")
|
|
list(APPEND OSQUERY_LIBS "libprocps.a")
|
|
endif()
|
|
|
|
# Fill this in with objects for libosquery
|
|
set(OSQUERY_SOURCES "")
|
|
set(OSQUERY_ADDITIONAL_LINKS "")
|
|
|
|
MACRO(ADD_OSQUERY_LINK LINK)
|
|
list(APPEND OSQUERY_ADDITIONAL_LINKS ${LINK})
|
|
set(OSQUERY_ADDITIONAL_LINKS ${OSQUERY_ADDITIONAL_LINKS} PARENT_SCOPE)
|
|
ENDMACRO(ADD_OSQUERY_LINK)
|
|
|
|
MACRO(SET_OSQUERY_COMPILE TARGET)
|
|
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS ${OS_COMPILE_FLAGS})
|
|
SET(OPTIONAL_FLAGS ${ARGN})
|
|
LIST(LENGTH OPTIONAL_FLAGS NUM_OPTIONAL_FLAGS)
|
|
if(${NUM_OPTIONAL_FLAGS} GREATER 0)
|
|
MESSAGE("Notice: Adding compile flags ${OPTIONAL_FLAGS} to ${TARGET}")
|
|
SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS ${OPTIONAL_FLAGS})
|
|
ENDIF()
|
|
ENDMACRO(SET_OSQUERY_COMPILE)
|
|
|
|
MACRO(ADD_OSQUERY_LIBRARY TARGET)
|
|
ADD_LIBRARY(${TARGET} OBJECT ${ARGN})
|
|
SET_OSQUERY_COMPILE(${TARGET})
|
|
list(APPEND OSQUERY_SOURCES $<TARGET_OBJECTS:${TARGET}>)
|
|
set(OSQUERY_SOURCES ${OSQUERY_SOURCES} PARENT_SCOPE)
|
|
ENDMACRO(ADD_OSQUERY_LIBRARY TARGET)
|
|
|
|
MACRO(ADD_OSQUERY_OBJCXX_LIBRARY TARGET)
|
|
ADD_LIBRARY(${TARGET} OBJECT ${ARGN})
|
|
SET_OSQUERY_COMPILE(${TARGET} "-x objective-c++ -fobjc-arc")
|
|
list(APPEND OSQUERY_SOURCES $<TARGET_OBJECTS:${TARGET}>)
|
|
set(OSQUERY_SOURCES ${OSQUERY_SOURCES} PARENT_SCOPE)
|
|
ENDMACRO(ADD_OSQUERY_OBJCXX_LIBRARY TARGET)
|
|
|
|
MACRO(ADD_OSQUERY_TEST TEST_NAME SOURCE)
|
|
ADD_EXECUTABLE(${TEST_NAME} ${SOURCE})
|
|
TARGET_LINK_LIBRARIES(${TEST_NAME} ${OSQUERY_ADDITIONAL_LINKS})
|
|
TARGET_LINK_LIBRARIES(${TEST_NAME} osquery_shared)
|
|
SET(OPTIONAL_FLAGS ${ARGN})
|
|
SET_OSQUERY_COMPILE(${TEST_NAME} ${OPTIONAL_FLAGS})
|
|
ADD_TEST(${TEST_NAME} ${TEST_NAME})
|
|
ENDMACRO(ADD_OSQUERY_TEST)
|
|
|
|
MACRO(ADD_OSQUERY_EXECUTABLE NAME SOURCE)
|
|
ADD_OSQUERY_TEST(${NAME} ${SOURCE})
|
|
TARGET_LINK_LIBRARIES(${NAME} osquery_shared)
|
|
ENDMACRO(ADD_OSQUERY_EXECUTABLE)
|
|
|
|
MACRO(TARGET_OSQUERY_LINK_WHOLE TARGET OSQUERY_LIB)
|
|
TARGET_LINK_LIBRARIES(${TARGET} "${OS_WHOLELINK_PRE}")
|
|
TARGET_LINK_LIBRARIES(${TARGET} ${OSQUERY_LIB})
|
|
TARGET_LINK_LIBRARIES(${TARGET} "${OS_WHOLELINK_POST}")
|
|
ENDMACRO(TARGET_OSQUERY_LINK_WHOLE)
|
|
|
|
ADD_SUBDIRECTORY(config)
|
|
ADD_SUBDIRECTORY(core)
|
|
ADD_SUBDIRECTORY(database)
|
|
ADD_SUBDIRECTORY(devtools)
|
|
ADD_SUBDIRECTORY(events)
|
|
ADD_SUBDIRECTORY(examples)
|
|
ADD_SUBDIRECTORY(filesystem)
|
|
ADD_SUBDIRECTORY(logger)
|
|
ADD_SUBDIRECTORY(dispatcher)
|
|
ADD_SUBDIRECTORY(registry)
|
|
ADD_SUBDIRECTORY(scheduler)
|
|
ADD_SUBDIRECTORY(tables)
|
|
|
|
SET(OSQUERY_LIB_OBJECTS
|
|
# Third-party objects
|
|
$<TARGET_OBJECTS:osquery_sqlite>
|
|
|
|
# Build additional os-dependent libraries (may include tables)
|
|
${OSQUERY_SOURCES}
|
|
)
|
|
|
|
if(BUILD_SHARED)
|
|
ADD_LIBRARY(osquery_shared SHARED main/lib.cpp ${OSQUERY_LIB_OBJECTS})
|
|
else()
|
|
ADD_LIBRARY(osquery_static STATIC ${OSQUERY_LIB_OBJECTS})
|
|
SET_TARGET_PROPERTIES(osquery_static PROPERTIES OUTPUT_NAME osquery_static)
|
|
|
|
ADD_LIBRARY(osquery_shared STATIC main/lib.cpp)
|
|
TARGET_OSQUERY_LINK_WHOLE(osquery_shared osquery_static)
|
|
endif()
|
|
ADD_DEPENDENCIES(osquery_shared librocksdb)
|
|
TARGET_LINK_LIBRARIES(osquery_shared ${OSQUERY_ADDITIONAL_LINKS})
|
|
TARGET_LINK_LIBRARIES(osquery_shared ${OSQUERY_LIBS})
|
|
SET_TARGET_PROPERTIES(osquery_shared PROPERTIES OUTPUT_NAME osquery)
|
|
|
|
ADD_EXECUTABLE(shell main/shell.cpp)
|
|
TARGET_LINK_LIBRARIES(shell osquery_shared)
|
|
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME osqueryi)
|
|
SET_TARGET_PROPERTIES(shell PROPERTIES COMPILE_FLAGS ${OS_COMPILE_FLAGS})
|
|
INSTALL(TARGETS shell DESTINATION bin)
|
|
|
|
ADD_EXECUTABLE(daemon main/daemon.cpp)
|
|
TARGET_LINK_LIBRARIES(daemon osquery_shared)
|
|
SET_TARGET_PROPERTIES(daemon PROPERTIES OUTPUT_NAME osqueryd)
|
|
SET_TARGET_PROPERTIES(daemon PROPERTIES COMPILE_FLAGS ${OS_COMPILE_FLAGS})
|
|
INSTALL(TARGETS daemon DESTINATION bin)
|
|
|
|
if(NOT APPLE)
|
|
SET(CPACK_PACKAGE_NAME "osquery")
|
|
SET(CPACK_PACKAGE_VENDOR "facebook")
|
|
|
|
SET(CPACK_PACKAGE_VERSION "0.0.1")
|
|
SET(CPACK_PACKAGE_VERSION_MAJOR 0)
|
|
SET(CPACK_PACKAGE_VERSION_MINOR 0)
|
|
SET(CPACK_PACKAGE_VERSION_PATCH 1)
|
|
|
|
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})
|
|
|
|
if(EXISTS /etc/apt/sources.list)
|
|
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()
|