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

build: reorganize driver cmake vars #423

Merged
merged 5 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ project(falcosecurity-libs)

option(MINIMAL_BUILD "Produce a minimal build with only the essential features (no eBPF probe driver, no kubernetes, no mesos, no marathon and no container metadata)" OFF)
option(MUSL_OPTIMIZED_BUILD "Enable if you want a musl optimized build" OFF)
option(USE_BUNDLED_DRIVER "Use the driver/ subdirectory in the build process (only available in Linux)" ON)

include(GNUInstallDirs)

Expand All @@ -52,12 +53,16 @@ endif()

message(STATUS "Libs version: ${FALCOSECURITY_LIBS_VERSION}")

# Driver version
if(NOT DEFINED DRIVER_VERSION)
get_drivers_version(DRIVER_VERSION)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND USE_BUNDLED_DRIVER)
# Driver version
if(NOT DEFINED DRIVER_VERSION)
get_drivers_version(DRIVER_VERSION)
endif()

message(STATUS "Driver version: ${DRIVER_VERSION}")

message(STATUS "Driver version: ${DRIVER_VERSION}")
add_subdirectory(driver ${PROJECT_BINARY_DIR}/driver)
endif()

if(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Release)
Expand Down
27 changes: 20 additions & 7 deletions driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,32 @@
# MIT.txt or GPL.txt for full copies of the license.
#

cmake_minimum_required(VERSION 2.8.5)
project(driver)

option(BUILD_DRIVER "Build the driver on Linux" ON)
option(ENABLE_DKMS "Enable DKMS on Linux" ON)

if(NOT DEFINED DRIVER_VERSION)
message(FATAL_ERROR
"No DRIVER_VERSION set.\nPlease either explicitly set it or build the root project 'falcosecurity/libs' from a git working directory."
)
endif()

if(NOT DEFINED DRIVER_COMPONENT_NAME)
set(DRIVER_COMPONENT_NAME "scap-driver")
set(DRIVER_COMPONENT_NAME "scap-driver")
endif()

if(NOT DEFINED DRIVER_PACKAGE_NAME)
set(DRIVER_PACKAGE_NAME "scap")
set(DRIVER_PACKAGE_NAME "scap")
endif()

if(NOT DEFINED DRIVER_NAME)
set(DRIVER_NAME "scap")
set(DRIVER_NAME "scap")
endif()

if(NOT DEFINED DRIVER_DEVICE_NAME)
set(DRIVER_DEVICE_NAME "${DRIVER_NAME}")
endif()

# The driver build process is somewhat involved because we use the same
Expand All @@ -31,8 +46,8 @@ endif()
# 1. The user (or some script) runs make in our driver directory
# 2. Our Makefile runs the Makefile from kernel sources/headers
# 3. The kernel Makefile calls our original Makefile again, with options that
# trigger the actual build. This step cannot know that our Makefile has
# a different name.
# trigger the actual build. This step cannot know that our Makefile has
# a different name.
#
# (DKMS needs a Makefile called Makefile as well).
#
Expand All @@ -45,7 +60,6 @@ endif()
# ${CMAKE_CURRENT_BINARY_DIR}/src. To maintain compatibility with older versions,
# after the build we copy the compiled module one directory up,
# to ${CMAKE_CURRENT_BINARY_DIR}.

file(STRINGS API_VERSION DRIVER_API_VERSION LIMIT_COUNT 1)
string(REGEX MATCHALL "[0-9]+" DRIVER_API_COMPONENTS "${DRIVER_API_VERSION}")
list(GET DRIVER_API_COMPONENTS 0 PPM_API_CURRENT_VERSION_MAJOR)
Expand Down Expand Up @@ -133,7 +147,6 @@ if(ENABLE_DKMS)
${DRIVER_SOURCES}
DESTINATION "src/${DRIVER_PACKAGE_NAME}-${DRIVER_VERSION}"
COMPONENT ${DRIVER_COMPONENT_NAME})

endif()

add_subdirectory(bpf)
19 changes: 4 additions & 15 deletions userspace/libscap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,10 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(KBUILD_FLAGS "${FALCOSECURITY_LIBS_DEBUG_FLAGS}")
endif()

if(NOT DEFINED DRIVER_VERSION)
message(ERROR
"No driver version set. Please either build the project from a git working directory or explicitly set the DRIVER_VERSION cmake cache entry."
)
endif()

if(NOT DEFINED DRIVER_NAME)
set(DRIVER_NAME "scap")
endif()

if(NOT DEFINED DRIVER_DEVICE_NAME)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be used by scap too:

snprintf(filename, sizeof(filename), "%s/dev/" DRIVER_DEVICE_NAME "%d", scap_get_host_root(), all_scanned_devs);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but it's not an issue. Since it's defined in driver_config.h which is autogenerated and included 👇

#include "driver_config.h"

All others definition in driver_config.h work in the same way.

Am I wrong?

set(DRIVER_DEVICE_NAME "${DRIVER_NAME}")
endif()
# do not remove this since when WITH_DRIVER is off
if(NOT DEFINED DRIVER_NAME)
set(DRIVER_NAME "scap")
endif()

string(REPLACE "-" "_" SCAP_KERNEL_MODULE_NAME "${DRIVER_NAME}")
add_definitions(-DSCAP_KERNEL_MODULE_NAME="${SCAP_KERNEL_MODULE_NAME}")
Expand Down Expand Up @@ -126,8 +117,6 @@ target_link_libraries(scap
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_subdirectory(../../driver ${PROJECT_BINARY_DIR}/driver)

option(BUILD_LIBSCAP_EXAMPLES "Build libscap examples" ON)

if (BUILD_LIBSCAP_EXAMPLES)
Expand Down