Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake modules #23

Merged
merged 26 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4717b0a
Link with oniguruma whenever we have ONIGURUMA_LIB
gnosek Oct 5, 2020
4b1b1c0
Move b64 to a cmake module
gnosek Mar 17, 2021
b96d5f1
Move jsoncpp to a cmake module
gnosek Mar 17, 2021
7481c88
Move luajit to a cmake module
gnosek Mar 17, 2021
07aa6f8
Move zlib to a cmake module
gnosek Mar 17, 2021
734927a
Move tbb to a cmake module
gnosek Mar 17, 2021
4b7fdc6
Move jq to a cmake module
gnosek Mar 17, 2021
5b26118
Move openssl to a cmake module
gnosek Mar 17, 2021
cc40697
Move curl to a cmake module
gnosek Mar 17, 2021
883f4cd
Move c-ares to a cmake module
gnosek Mar 17, 2021
4fb9c9f
Move protobuf to a cmake module
gnosek Mar 18, 2021
b0796a4
Move grpc to a cmake module
gnosek Mar 19, 2021
be6825e
Move gtest to a cmake module
gnosek Mar 18, 2021
422a3f3
Move libsinsp tests' cmake to userspace/libsinsp/CMakeLists.txt
gnosek Mar 26, 2021
c64db35
Move USE_BUNDLED_DEPS and ExternalProject to per-lib CMakeLists
gnosek Mar 22, 2021
25b49d0
K8S_DISABLE_THREAD is not used anywhere
gnosek Mar 23, 2021
5064710
Build the driver as a part of libscap
gnosek Mar 23, 2021
d246e64
SYSDIG_FEATURE_FLAGS is not defined anywhere
gnosek Mar 23, 2021
dff451a
Move driver/scap-specific compiler flags to libscap
gnosek Mar 23, 2021
3a96ce8
PLATFORM_NAME is only used by libscap
gnosek Mar 23, 2021
ad60e2b
Minor cleanups in cmake compiler flags
gnosek Mar 23, 2021
c096818
KBUILD_FLAGS are libscap-specific
gnosek Mar 23, 2021
c247610
DIR_ETC is never used
gnosek Mar 23, 2021
ea8a77b
Move compiler flags to a cmake module
gnosek Mar 23, 2021
f67183a
Make libscap a cmake submodule
gnosek Mar 24, 2021
6bfa81f
Move libsinsp to a cmake module
gnosek Mar 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
568 changes: 3 additions & 565 deletions CMakeLists.txt

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions cmake/modules/CompilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
option(BUILD_WARNINGS_AS_ERRORS "Enable building with -Wextra -Werror flags")

if(CMAKE_SYSTEM_NAME MATCHES "SunOS")
set(CMD_MAKE gmake)
else()
set(CMD_MAKE make)
endif()

if(NOT WIN32)

set(SYSDIG_COMMON_FLAGS "-Wall -ggdb")
set(SYSDIG_DEBUG_FLAGS "-D_DEBUG")
set(SYSDIG_RELEASE_FLAGS "-O3 -fno-strict-aliasing -DNDEBUG")

if(MINIMAL_BUILD)
set(SYSDIG_COMMON_FLAGS "${SYSDIG_COMMON_FLAGS} -DMINIMAL_BUILD")
endif()

if(MUSL_OPTIMIZED_BUILD)
set(SYSDIG_COMMON_FLAGS "${SYSDIG_COMMON_FLAGS} -static -Os")
endif()

if(BUILD_WARNINGS_AS_ERRORS)
set(CMAKE_SUPPRESSED_WARNINGS "-Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-type-limits -Wno-implicit-fallthrough -Wno-format-truncation")
set(SYSDIG_COMMON_FLAGS "${SYSDIG_COMMON_FLAGS} -Wextra -Werror ${CMAKE_SUPPRESSED_WARNINGS}")
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SYSDIG_COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYSDIG_COMMON_FLAGS} -std=c++0x")

set(CMAKE_C_FLAGS_DEBUG "${SYSDIG_DEBUG_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${SYSDIG_DEBUG_FLAGS}")

set(CMAKE_C_FLAGS_RELEASE "${SYSDIG_RELEASE_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${SYSDIG_RELEASE_FLAGS}")

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_definitions(-DHAS_CAPTURE)
endif()

else()
set(MINIMAL_BUILD ON)

set(SYSDIG_COMMON_FLAGS "-D_CRT_SECURE_NO_WARNINGS -DWIN32 -DMINIMAL_BUILD /EHsc /W3 /Zi")
set(SYSDIG_DEBUG_FLAGS "/MTd /Od")
set(SYSDIG_RELEASE_FLAGS "/MT")

set(CMAKE_C_FLAGS "${SYSDIG_COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS "${SYSDIG_COMMON_FLAGS}")

set(CMAKE_C_FLAGS_DEBUG "${SYSDIG_DEBUG_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${SYSDIG_DEBUG_FLAGS}")

set(CMAKE_C_FLAGS_RELEASE "${SYSDIG_RELEASE_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${SYSDIG_RELEASE_FLAGS}")

add_definitions(-DHAS_CAPTURE)

endif()

if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000")
endif()


32 changes: 32 additions & 0 deletions cmake/modules/b64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# libb64
#
option(USE_BUNDLED_B64 "Enable building of the bundled b64" ${USE_BUNDLED_DEPS})

if(B64_INCLUDE)
# we already have b64
elseif(NOT USE_BUNDLED_B64)
find_path(B64_INCLUDE NAMES b64/encode.h)
find_library(B64_LIB NAMES b64)
if(B64_INCLUDE AND B64_LIB)
message(STATUS "Found b64: include: ${B64_INCLUDE}, lib: ${B64_LIB}")
else()
message(FATAL_ERROR "Couldn't find system b64")
endif()
else()
set(B64_SRC "${PROJECT_BINARY_DIR}/b64-prefix/src/b64")
message(STATUS "Using bundled b64 in '${B64_SRC}'")
set(B64_INCLUDE "${B64_SRC}/include")
set(B64_LIB "${B64_SRC}/src/libb64.a")
ExternalProject_Add(b64
PREFIX "${PROJECT_BINARY_DIR}/b64-prefix"
URL "https://github.com/libb64/libb64/archive/v1.2.1.tar.gz"
URL_HASH "SHA256=d620e7caf3ed5f9c28d727fa799918ad3ef69c80975905646bb549a6019cdcbd"
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMD_MAKE}
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${B64_LIB}
INSTALL_COMMAND "")
endif()

include_directories("${B64_INCLUDE}")
32 changes: 32 additions & 0 deletions cmake/modules/cares.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
option(USE_BUNDLED_CARES "Enable building of the bundled c-ares" ${USE_BUNDLED_DEPS})

if(CARES_INCLUDE)
# we already have c-ares
elseif(NOT USE_BUNDLED_CARES)
find_path(CARES_INCLUDE NAMES cares/ares.h ares.h)
find_library(CARES_LIB NAMES cares)
if(CARES_INCLUDE AND CARES_LIB)
message(STATUS "Found c-ares: include: ${CARES_INCLUDE}, lib: ${CARES_LIB}")
else()
message(FATAL_ERROR "Couldn't find system c-ares")
endif()
else()
set(CARES_SRC "${PROJECT_BINARY_DIR}/c-ares-prefix/src/c-ares")
set(CARES_INCLUDE "${CARES_SRC}/target/include")
set(CARES_LIB "${CARES_SRC}/target/lib/libcares.a")

if(NOT TARGET c-ares)
message(STATUS "Using bundled c-ares in '${CARES_SRC}'")
ExternalProject_Add(c-ares
PREFIX "${PROJECT_BINARY_DIR}/c-ares-prefix"
URL "http://download.sysdig.com/dependencies/c-ares-1.13.0.tar.gz"
URL_MD5 "d2e010b43537794d8bedfb562ae6bba2"
CONFIGURE_COMMAND ./configure --prefix=${CARES_SRC}/target
BUILD_COMMAND ${CMD_MAKE}
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${CARES_INCLUDE} ${CARES_LIB}
INSTALL_COMMAND ${CMD_MAKE} install)
endif()
endif()

include_directories("${CARES_INCLUDE}")
40 changes: 40 additions & 0 deletions cmake/modules/curl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# libcurl
#
option(USE_BUNDLED_CURL "Enable building of the bundled curl" ${USE_BUNDLED_DEPS})

include(openssl)

if(CURL_INCLUDE_DIR)
# we already have curl
elseif(NOT USE_BUNDLED_CURL)
find_package(CURL REQUIRED)
message(STATUS "Found CURL: include: ${CURL_INCLUDE_DIR}, lib: ${CURL_LIBRARIES}")
else()
set(CURL_BUNDLE_DIR "${PROJECT_BINARY_DIR}/curl-prefix/src/curl")
set(CURL_INCLUDE_DIR "${CURL_BUNDLE_DIR}/include/")
set(CURL_LIBRARIES "${CURL_BUNDLE_DIR}/lib/.libs/libcurl.a")

if(NOT USE_BUNDLED_OPENSSL)
set(CURL_SSL_OPTION "--with-ssl")
else()
set(CURL_SSL_OPTION "--with-ssl=${OPENSSL_INSTALL_DIR}")
message(STATUS "Using bundled curl in '${CURL_BUNDLE_DIR}'")
message(STATUS "Using SSL for curl in '${CURL_SSL_OPTION}'")
endif()

if(NOT TARGET curl)
ExternalProject_Add(curl
PREFIX "${PROJECT_BINARY_DIR}/curl-prefix"
DEPENDS openssl
URL "https://github.com/curl/curl/releases/download/curl-7_61_0/curl-7.61.0.tar.bz2"
URL_HASH "SHA256=5f6f336921cf5b84de56afbd08dfb70adeef2303751ffb3e570c936c6d656c9c"
CONFIGURE_COMMAND ./configure ${CURL_SSL_OPTION} --disable-threaded-resolver --disable-shared --enable-optimize --disable-curldebug --disable-rt --enable-http --disable-ftp --disable-file --disable-ldap --disable-ldaps --disable-rtsp --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --disable-sspi --disable-ntlm-wb --disable-tls-srp --without-winssl --without-darwinssl --without-polarssl --without-cyassl --without-nss --without-axtls --without-ca-path --without-ca-bundle --without-libmetalink --without-librtmp --without-winidn --without-libidn --without-libidn2 --without-nghttp2 --without-libssh2 --without-libpsl
BUILD_COMMAND ${CMD_MAKE}
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${CURL_LIBRARIES}
INSTALL_COMMAND "")
endif()
endif()

include_directories("${CURL_INCLUDE_DIR}")
60 changes: 60 additions & 0 deletions cmake/modules/grpc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
option(USE_BUNDLED_GRPC "Enable building of the bundled grpc" ${USE_BUNDLED_DEPS})

if(GRPC_INCLUDE)
# we already have grpc
elseif(NOT USE_BUNDLED_GRPC)
find_path(GRPCXX_INCLUDE NAMES grpc++/grpc++.h)
if(GRPCXX_INCLUDE)
set(GRPC_INCLUDE ${GRPCXX_INCLUDE})
else()
find_path(GRPCPP_INCLUDE NAMES grpcpp/grpcpp.h)
set(GRPC_INCLUDE ${GRPCPP_INCLUDE})
add_definitions(-DGRPC_INCLUDE_IS_GRPCPP=1)
endif()
find_library(GRPC_LIB NAMES grpc_unsecure)
find_library(GRPCPP_LIB NAMES grpc++_unsecure)
if(GRPC_INCLUDE AND GRPC_LIB AND GRPCPP_LIB)
message(STATUS "Found grpc: include: ${GRPC_INCLUDE}, C lib: ${GRPC_LIB}, C++ lib: ${GRPCPP_LIB}")
else()
message(FATAL_ERROR "Couldn't find system grpc")
endif()
find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin)
if(NOT GRPC_CPP_PLUGIN)
message(FATAL_ERROR "System grpc_cpp_plugin not found")
endif()
else()
include(cares)
include(protobuf)
find_package(PkgConfig)
if(NOT PKG_CONFIG_FOUND)
message(FATAL_ERROR "pkg-config binary not found")
endif()
set(GRPC_SRC "${PROJECT_BINARY_DIR}/grpc-prefix/src/grpc")
set(GRPC_INCLUDE "${GRPC_SRC}/include")
set(GRPC_LIB "${GRPC_SRC}/libs/opt/libgrpc_unsecure.a")
set(GRPCPP_LIB "${GRPC_SRC}/libs/opt/libgrpc++_unsecure.a")
set(GRPC_CPP_PLUGIN "${GRPC_SRC}/bins/opt/grpc_cpp_plugin")

get_filename_component(PROTOC_DIR ${PROTOC} PATH)

if(NOT TARGET grpc)
message(STATUS "Found pkg-config executable: ${PKG_CONFIG_EXECUTABLE}")
message(STATUS "Using bundled grpc in '${GRPC_SRC}'")
ExternalProject_Add(grpc
PREFIX "${PROJECT_BINARY_DIR}/grpc-prefix"
DEPENDS protobuf zlib c-ares
URL "http://download.draios.com/dependencies/grpc-1.8.1.tar.gz"
URL_MD5 "2fc42c182a0ed1b48ad77397f76bb3bc"
CONFIGURE_COMMAND ""
# TODO what if using system openssl, protobuf or cares?
BUILD_COMMAND CFLAGS=-Wno-implicit-fallthrough HAS_SYSTEM_ZLIB=false LDFLAGS=-static PATH=${PROTOC_DIR}:$ENV{PATH} PKG_CONFIG_PATH=${OPENSSL_BUNDLE_DIR}:${PROTOBUF_SRC}:${CARES_SRC} PKG_CONFIG=${PKG_CONFIG_EXECUTABLE} make grpc_cpp_plugin static_cxx static_c
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${GRPC_LIB} ${GRPCPP_LIB}
# TODO s390x support
# TODO what if using system zlib
PATCH_COMMAND rm -rf third_party/zlib && ln -s ${ZLIB_SRC} third_party/zlib && wget https://download.sysdig.com/dependencies/grpc-1.8.1-Makefile.patch && patch < grpc-1.8.1-Makefile.patch
INSTALL_COMMAND "")
endif()
endif()

include_directories("${GRPC_INCLUDE}")
41 changes: 41 additions & 0 deletions cmake/modules/gtest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
option(USE_BUNDLED_GTEST "Enable building of the bundled gtest" ${USE_BUNDLED_DEPS})

if(GTEST_INCLUDE_DIR)
# we already have gtest
elseif(NOT USE_BUNDLED_GTEST)
find_path(GTEST_INCLUDE_DIR PATH_SUFFIXES gtest NAMES gtest.h)
find_library(GTEST_LIB NAMES gtest)
find_library(GTEST_MAIN_LIB NAMES gtest_main)
if(GTEST_INCLUDE_DIR AND GTEST_LIB AND GTEST_MAIN_LIB)
message(STATUS "Found gtest: include: ${GTEST_INCLUDE_DIR}, lib: ${GTEST_LIB}, main lib: ${GTEST_MAIN_LIB}")
else()
message(FATAL_ERROR "Couldn't find system gtest")
endif()
else()
# https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project
# Download and unpack googletest at configure time
configure_file(CMakeListsGtestInclude.cmake ${PROJECT_BINARY_DIR}/googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${PROJECT_BINARY_DIR}/googletest-src
${PROJECT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)

set(GTEST_INCLUDE_DIR "${gtest_SOURCE_DIR}/include/gtest")
set(GTEST_MAIN_LIB "gtest_main")
endif()

include_directories("${GTEST_INCLUDE_DIR}")
55 changes: 55 additions & 0 deletions cmake/modules/jq.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# jq
#
option(USE_BUNDLED_JQ "Enable building of the bundled jq" ${USE_BUNDLED_DEPS})

if(JQ_INCLUDE)
# we already have jq
elseif(NOT USE_BUNDLED_JQ)
find_path(JQ_INCLUDE jq.h PATH_SUFFIXES jq)
find_library(JQ_LIB NAMES jq)
if(JQ_INCLUDE AND JQ_LIB)
message(STATUS "Found jq: include: ${JQ_INCLUDE}, lib: ${JQ_LIB}")
else()
message(FATAL_ERROR "Couldn't find system jq")
endif()
else()
set(JQ_SRC "${PROJECT_BINARY_DIR}/jq-prefix/src/jq")
message(STATUS "Using bundled jq in '${JQ_SRC}'")
set(JQ_INCLUDE "${JQ_SRC}/target/include")
set(JQ_INSTALL_DIR "${JQ_SRC}/target")
set(JQ_LIB "${JQ_INSTALL_DIR}/lib/libjq.a")
set(ONIGURUMA_LIB "${JQ_INSTALL_DIR}/lib/libonig.a")

if(NOT TARGET jq)
message(STATUS "Bundled jq: include: ${JQ_INCLUDE}, lib: ${JQ_LIB}")

# Why we mirror jq here?
#
# In their readme, jq claims that you don't have
# to do autoreconf -fi when downloading a released tarball.
#
# However, they forgot to push the released makefiles
# into their release tarbal.
#
# For this reason, we have to mirror their release after
# doing the configuration ourselves.
#
# This is needed because many distros do not ship the right
# version of autoreconf, making virtually impossible to build libs on them.
# Read more about it here:
# https://github.com/stedolan/jq/issues/2061#issuecomment-593445920
ExternalProject_Add(
jq
PREFIX "${PROJECT_BINARY_DIR}/jq-prefix"
URL "https://download.falco.org/dependencies/jq-1.6.tar.gz"
URL_HASH "SHA256=787518068c35e244334cc79b8e56b60dbab352dff175b7f04a94f662b540bfd9"
CONFIGURE_COMMAND ./configure --disable-maintainer-mode --enable-all-static --disable-dependency-tracking --with-oniguruma=builtin --prefix=${JQ_INSTALL_DIR}
BUILD_COMMAND ${CMD_MAKE} LDFLAGS=-all-static
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${JQ_LIB} ${ONIGURUMA_LIB}
INSTALL_COMMAND ${CMD_MAKE} install)
endif()
endif()

include_directories("${JQ_INCLUDE}")
23 changes: 23 additions & 0 deletions cmake/modules/jsoncpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# JsonCpp
#
option(USE_BUNDLED_JSONCPP "Enable building of the bundled jsoncpp" ${USE_BUNDLED_DEPS})

if(JSONCPP_INCLUDE AND JSONCPP_LIB)
message(STATUS "Using jsoncpp: include: ${JSONCPP_INCLUDE}, lib: ${JSONCPP_LIB}")
elseif(NOT USE_BUNDLED_JSONCPP)
find_path(JSONCPP_INCLUDE json/json.h PATH_SUFFIXES jsoncpp)
find_library(JSONCPP_LIB NAMES jsoncpp)
if(JSONCPP_INCLUDE AND JSONCPP_LIB)
message(STATUS "Found jsoncpp: include: ${JSONCPP_INCLUDE}, lib: ${JSONCPP_LIB}")
else()
message(FATAL_ERROR "Couldn't find system jsoncpp")
endif()
else()
set(JSONCPP_SRC "${CMAKE_CURRENT_LIST_DIR}/../../userspace/libsinsp/third-party/jsoncpp")
set(JSONCPP_INCLUDE "${JSONCPP_SRC}")
set(JSONCPP_LIB_SRC "${JSONCPP_SRC}/jsoncpp.cpp")
message(STATUS "Using bundled jsoncpp in '${JSONCPP_SRC}'")
endif()

include_directories("${JSONCPP_INCLUDE}")
20 changes: 20 additions & 0 deletions cmake/modules/libscap.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if(NOT HAVE_LIBSCAP)
set(HAVE_LIBSCAP On)

if(NOT LIBSCAP_DIR)
get_filename_component(LIBSCAP_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. ABSOLUTE)
endif()

option(USE_BUNDLED_DEPS "Enable bundled dependencies instead of using the system ones" ON)

include(ExternalProject)

add_definitions(-DPLATFORM_NAME="${CMAKE_SYSTEM_NAME}")

get_filename_component(DRIVER_CONFIG_DIR ${CMAKE_BINARY_DIR}/driver/src ABSOLUTE)
get_filename_component(LIBSCAP_INCLUDE_DIR ${LIBSCAP_DIR}/userspace/libscap ABSOLUTE)
set(LIBSCAP_INCLUDE_DIRS ${LIBSCAP_INCLUDE_DIR} ${DRIVER_CONFIG_DIR})

add_subdirectory(${LIBSCAP_DIR}/userspace/libscap ${PROJECT_BINARY_DIR}/libscap)

endif()
Loading