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

cleanup(build): Use a single cmake module for driver_config.h #1188

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions cmake/modules/driver_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include(compute_versions RESULT_VARIABLE RESULT)
if(RESULT STREQUAL NOTFOUND)
message(FATAL_ERROR "problem with compute_versions.cmake in ${CMAKE_MODULE_PATH}")
endif()

set(DRIVER_CONFIG_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../driver)
get_filename_component(DRIVER_CONFIG_OUTPUT_DIR ${CMAKE_BINARY_DIR}/driver_config ABSOLUTE)

compute_versions(${DRIVER_CONFIG_SOURCE_DIR}/API_VERSION ${DRIVER_CONFIG_SOURCE_DIR}/SCHEMA_VERSION)
configure_file(${DRIVER_CONFIG_SOURCE_DIR}/driver_config.h.in ${DRIVER_CONFIG_OUTPUT_DIR}/driver_config.h.tmp)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different driver_config.h.tmp driver_config.h
WORKING_DIRECTORY ${DRIVER_CONFIG_OUTPUT_DIR}
)
2 changes: 1 addition & 1 deletion cmake/modules/libscap.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ else()
endif()

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

function(set_scap_target_properties target)
set_target_properties(${target} PROPERTIES
Expand Down
10 changes: 2 additions & 8 deletions driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,9 @@ 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}.
include(compute_versions RESULT_VARIABLE RESULT)
if(RESULT STREQUAL NOTFOUND)
message(FATAL_ERROR "problem with compute_versions.cmake in ${CMAKE_MODULE_PATH}")
endif()
compute_versions(API_VERSION SCHEMA_VERSION)

configure_file(dkms.conf.in src/dkms.conf)
configure_file(Makefile.in src/Makefile)
configure_file(driver_config.h.in src/driver_config.h)
include(driver_config)

set(DRIVER_SOURCES
dynamic_params_table.c
Expand Down Expand Up @@ -160,7 +154,7 @@ add_custom_target(install_driver
if(ENABLE_DKMS)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/Makefile
${CMAKE_CURRENT_BINARY_DIR}/src/dkms.conf
${CMAKE_CURRENT_BINARY_DIR}/src/driver_config.h
${CMAKE_BINARY_DIR}/driver_config/driver_config.h
${DRIVER_SOURCES}
DESTINATION "src/${DRIVER_PACKAGE_NAME}-${DRIVER_VERSION}"
COMPONENT ${DRIVER_COMPONENT_NAME})
Expand Down
48 changes: 35 additions & 13 deletions driver/bpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,36 @@
# MIT.txt or GPL.txt for full copies of the license.
#

configure_file(../driver_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/../driver_config.h)
include(driver_config)

option(BUILD_BPF "Build the BPF driver on Linux" OFF)

# Note: probe.c *must* be the first entry to generate a proper Makefile
set(BPF_SOURCES
probe.c
bpf_helpers.h
builtins.h
filler_helpers.h
fillers.h
maps.h
missing_definitions.h
plumbing_helpers.h
quirks.h
ring_helpers.h
types.h
${DRIVER_CONFIG_OUTPUT_DIR}/driver_config.h
../ppm_api_version.h
../ppm_events_public.h
../feature_gates.h
../ppm_version.h
../ppm_fillers.h
../ppm_flag_helpers.h
../ppm.h
../ppm_consumer.h
../capture_macro.h
../systype_compat.h
)

if(BUILD_BPF)
# Check minimum kernel version
set(bpf_min_kver_map_x86_64 4.14)
Expand All @@ -18,25 +44,21 @@ if(BUILD_BPF)
message(WARNING "[BPF] To run this driver you need a Linux kernel version >= ${bpf_min_kver_map_${TARGET_ARCH}} but actual kernel version is: ${UNAME_RESULT}")
endif()

foreach(FILENAME IN LISTS BPF_SOURCES)
get_filename_component(BASENAME ${FILENAME} NAME)
configure_file(${FILENAME} src/${BASENAME} COPYONLY)
string(APPEND BPF_DEPENDENCIES "$(src)/${BASENAME} ")
endforeach()

add_custom_target(bpf ALL
COMMAND make
COMMAND "${CMAKE_COMMAND}" -E copy_if_different probe.o "${CMAKE_CURRENT_BINARY_DIR}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/src"
VERBATIM)
endif()

install(FILES
bpf_helpers.h
builtins.h
filler_helpers.h
fillers.h
${BPF_SOURCES}
Makefile
maps.h
plumbing_helpers.h
probe.c
quirks.h
ring_helpers.h
missing_definitions.h
types.h
DESTINATION "src/${DRIVER_PACKAGE_NAME}-${DRIVER_VERSION}/bpf"
COMPONENT ${DRIVER_COMPONENT_NAME})
11 changes: 1 addition & 10 deletions driver/bpf/Makefile → driver/bpf/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,7 @@ clean:
$(MAKE) -C $(KERNELDIR) M=$$PWD clean
@rm -f *~

$(obj)/probe.o: $(src)/probe.c \
$(src)/bpf_helpers.h \
$(src)/filler_helpers.h \
$(src)/fillers.h \
$(src)/maps.h \
$(src)/plumbing_helpers.h \
$(src)/quirks.h \
$(src)/ring_helpers.h \
$(src)/missing_definitions.h \
$(src)/types.h
$(obj)/probe.o: @BPF_DEPENDENCIES@
$(CLANG) $(LINUXINCLUDE) \
$(KBUILD_CPPFLAGS) \
$(KBUILD_EXTRA_CPPFLAGS) \
Expand Down
2 changes: 1 addition & 1 deletion driver/bpf/filler_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ or GPL2.txt for full copies of the license.
#include <linux/fdtable.h>
#include <linux/net.h>

#include "../ppm_flag_helpers.h"
#include "ppm_flag_helpers.h"
#include "builtins.h"
#include "missing_definitions.h"

Expand Down
6 changes: 3 additions & 3 deletions driver/bpf/fillers.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ or GPL2.txt for full copies of the license.
#ifndef __FILLERS_H
#define __FILLERS_H

#include "../systype_compat.h"
#include "../ppm_flag_helpers.h"
#include "../ppm_version.h"
#include "systype_compat.h"
#include "ppm_flag_helpers.h"
#include "ppm_version.h"
#include "bpf_helpers.h"

#include <linux/tty.h>
Expand Down
4 changes: 2 additions & 2 deletions driver/bpf/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ or GPL2.txt for full copies of the license.
#endif
#include <linux/sched.h>

#include "../driver_config.h"
#include "../ppm_events_public.h"
#include "driver_config.h"
#include "ppm_events_public.h"
#include "bpf_helpers.h"
#include "types.h"
#include "maps.h"
Expand Down
1 change: 0 additions & 1 deletion driver/modern_bpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ if(RESULT STREQUAL NOTFOUND)
message(FATAL_ERROR "${MODERN_BPF_LOG_PREFIX} problem with compute_versions.cmake in ${CMAKE_MODULE_PATH}")
endif()
compute_versions(../API_VERSION ../SCHEMA_VERSION)
configure_file(../driver_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/../driver_config.h)

########################
# Check clang version.
Expand Down
3 changes: 2 additions & 1 deletion userspace/libscap/engine/bpf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_directories(${LIBSCAP_INCLUDE_DIRS} ../noop)
include(driver_config)
include_directories(${LIBSCAP_INCLUDE_DIRS} ${DRIVER_CONFIG_OUTPUT_DIR} ../noop)
add_library(scap_engine_bpf scap_bpf.c attached_prog.c)
add_dependencies(scap_engine_bpf libelf scap_platform)
target_link_libraries(scap_engine_bpf scap_event_schema scap_platform scap_engine_util scap_error ${LIBELF_LIB})
Expand Down
3 changes: 2 additions & 1 deletion userspace/libscap/engine/kmod/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_directories(${LIBSCAP_INCLUDE_DIRS})
include(driver_config)
include_directories(${LIBSCAP_INCLUDE_DIRS} ${DRIVER_CONFIG_OUTPUT_DIR})
add_library(scap_engine_kmod scap_kmod.c)
target_link_libraries(scap_engine_kmod scap_event_schema scap_platform scap_engine_util scap_error)
add_dependencies(scap_engine_kmod scap_event_schema scap_platform scap_engine_util scap_error)
Expand Down
3 changes: 2 additions & 1 deletion userspace/libscap/engine/modern_bpf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_directories(${LIBSCAP_INCLUDE_DIRS} ../noop)
include(driver_config)
include_directories(${LIBSCAP_INCLUDE_DIRS} ${DRIVER_CONFIG_OUTPUT_DIR} ../noop)

message(STATUS "Build modern BPF engine")
option(USE_BUNDLED_MODERN_BPF "use bundled modern BPF" ON)
Expand Down
Loading