Skip to content

Commit

Permalink
cleanup(build): gvisor no longer has a circular dependency on scap
Browse files Browse the repository at this point in the history
Signed-off-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
  • Loading branch information
gnosek authored and poiana committed Oct 2, 2024
1 parent 6b72ea2 commit 85713d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 52 deletions.
21 changes: 1 addition & 20 deletions userspace/libscap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,26 +185,7 @@ endif()

if(HAS_ENGINE_GVISOR)
add_subdirectory(engine/gvisor)
# The static and shared build differs here because a shared scap_engine_gvisor will result in
# circular dependencies.
if(BUILD_SHARED_LIBS)
# We can move this to the gvisor CMakeFile when we use CMake 3.13 or later.
# https://cmake.org/cmake/help/latest/policy/CMP0079.html
target_link_libraries(
scap
PUBLIC ${CMAKE_THREAD_LIBS_INIT}
${GRPCPP_LIB}
${GRPC_LIB}
${GPR_LIB}
${GRPC_LIBRARIES}
${PROTOBUF_LIB}
${CARES_LIB}
${OPENSSL_LIBRARIES}
${JSONCPP_LIB}
)
else()
target_link_libraries(scap PRIVATE scap_engine_gvisor)
endif()
target_link_libraries(scap PUBLIC scap_engine_gvisor)
endif()

# ##################################################################################################
Expand Down
42 changes: 10 additions & 32 deletions userspace/libscap/engine/gvisor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,16 @@ if(USE_BUNDLED_JSONCPP)
add_dependencies(scap jsoncpp)
endif()

if(BUILD_SHARED_LIBS)
# Trying to build a shared scap_engine_gvisor will result in circular dependencies, so just add
# our sources to scap. Additionally, the GENERATED property doesn't propogate across
# directories, so enforce our dependency chain using an object library.
# https://gitlab.kitware.com/cmake/cmake/-/issues/18399
add_library(
scap_engine_gvisor_o OBJECT ${scap_engine_gvisor_sources}
${scap_engine_gvisor_generated_sources}
)
set_property(TARGET scap_engine_gvisor_o PROPERTY POSITION_INDEPENDENT_CODE ON)

target_include_directories(scap_engine_gvisor_o PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(scap_engine_gvisor_o PRIVATE scap_platform_util)

add_dependencies(scap_engine_gvisor_o uthash)
add_dependencies(scap scap_engine_gvisor_o)
target_sources(scap PRIVATE $<TARGET_OBJECTS:scap_engine_gvisor_o>)
else()
add_library(
scap_engine_gvisor ${scap_engine_gvisor_sources} ${scap_engine_gvisor_generated_sources}
)
add_library(
scap_engine_gvisor ${scap_engine_gvisor_sources} ${scap_engine_gvisor_generated_sources}
)

add_dependencies(scap_engine_gvisor uthash)
target_link_libraries(
scap_engine_gvisor
PRIVATE scap
PUBLIC scap_platform_util scap_error ${CMAKE_THREAD_LIBS_INIT} ${PROTOBUF_LIB}
${JSONCPP_LIB}
)
add_dependencies(scap_engine_gvisor uthash)
target_link_libraries(
scap_engine_gvisor PUBLIC scap_platform_util scap_error ${CMAKE_THREAD_LIBS_INIT}
${PROTOBUF_LIB} ${JSONCPP_LIB}
)

target_include_directories(scap_engine_gvisor PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(scap_engine_gvisor PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

set_scap_target_properties(scap_engine_gvisor)
endif()
set_scap_target_properties(scap_engine_gvisor)

0 comments on commit 85713d3

Please sign in to comment.