diff --git a/cmake/modules/BuildPkgConfigDependencies.cmake b/cmake/modules/BuildPkgConfigDependencies.cmake
new file mode 100644
index 0000000000..a597f18ac1
--- /dev/null
+++ b/cmake/modules/BuildPkgConfigDependencies.cmake
@@ -0,0 +1,104 @@
+# Get all dependencies for ${lib} and add them to ${LIBDIRS_VAR} and ${LIBS_VAR}. Ignore any
+# dependencies in the list ${ignored} to: - avoid infinite recursion - avoid libscap dependencies in
+# libsinsp.pc (which requires libscap.pc and pulls them in that way)
+function(add_pkgconfig_library LIBDIRS_VAR LIBS_VAR lib ignored)
+
+ # if it's not a target, it doesn't have dependencies we know or care about
+ if(NOT TARGET ${lib})
+ return()
+ endif()
+
+ # get the libraries that ${lib} links to
+ get_target_property(PKGCONFIG_LIBRARIES ${lib} LINK_LIBRARIES)
+ if("${PKGCONFIG_LIBRARIES}" STREQUAL "PKGCONFIG_LIBRARIES-NOTFOUND")
+ return()
+ endif()
+
+ get_property(
+ target_type
+ TARGET ${lib}
+ PROPERTY TYPE
+ )
+ foreach(dep ${PKGCONFIG_LIBRARIES})
+ # ignore dependencies in the list ${ignored}
+ if(${dep} IN_LIST "${ignored}")
+ continue()
+ endif()
+
+ if(${target_type} STREQUAL "SHARED_LIBRARY")
+ # for shared libraries, do not add static libraries as dependencies
+ if(TARGET ${dep})
+ # skip static libraries which are CMake targets
+ get_property(
+ dep_target_type
+ TARGET ${dep}
+ PROPERTY TYPE
+ )
+ if(${dep_target_type} STREQUAL "STATIC_LIBRARY")
+ continue()
+ endif()
+ else()
+ # skip static libraries which are just file paths
+ get_filename_component(ext ${dep} LAST_EXT)
+ if("${ext}" STREQUAL "${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ continue()
+ endif()
+ endif()
+ elseif(${target_type} STREQUAL "STATIC_LIBRARY")
+ # for static libraries which are not CMake targets, redirect them to
+ # ${libdir}/${LIBS_PACKAGE_NAME} note that ${libdir} is not a CMake variable, but a
+ # pkgconfig variable, so we quote it and end up with a literal ${libdir} in the
+ # pkgconfig file
+ if(NOT TARGET ${dep})
+ get_filename_component(filename ${dep} NAME)
+ set(dep "\${libdir}/${LIBS_PACKAGE_NAME}/${filename}")
+ endif()
+ endif()
+
+ add_pkgconfig_dependency(${LIBDIRS_VAR} ${LIBS_VAR} ${dep} "${ignored}")
+ endforeach()
+
+ # Remove duplicate search paths. We cannot remove duplicates from ${LIBS_VAR} because the order
+ # of libraries is important.
+ list(REMOVE_DUPLICATES ${LIBDIRS_VAR})
+
+ set(${LIBS_VAR}
+ ${${LIBS_VAR}}
+ PARENT_SCOPE
+ )
+ set(${LIBDIRS_VAR}
+ ${${LIBDIRS_VAR}}
+ PARENT_SCOPE
+ )
+endfunction()
+
+function(add_pkgconfig_dependency LIBDIRS_VAR LIBS_VAR lib ignored)
+ if(${lib} IN_LIST ignored)
+ # already processed, avoid infinite recursion
+ elseif(${lib} MATCHES "^-")
+ # We have a flag. Pass it through unchanged.
+ list(APPEND ${LIBS_VAR} ${lib})
+ elseif(${lib} MATCHES "/")
+ # We have a path. Convert it to -L
+ -l.
+ get_filename_component(lib_dir ${lib} DIRECTORY)
+ list(APPEND ${LIBDIRS_VAR} -L${lib_dir})
+ get_filename_component(lib_base ${lib} NAME_WE)
+ string(REGEX REPLACE "^lib" "" lib_base ${lib_base})
+ list(APPEND ${LIBS_VAR} -l${lib_base})
+ else()
+ # Assume we have a plain library name. Prefix it with "-l". Then recurse into its
+ # dependencies but ignore the library itself, so we don't end up in an infinite loop with
+ # cyclic dependencies
+ list(APPEND ${LIBS_VAR} -l${lib})
+ list(APPEND ignored ${lib})
+ add_pkgconfig_library(${LIBDIRS_VAR} ${LIBS_VAR} ${lib} "${ignored}")
+ endif()
+ set(${LIBS_VAR}
+ ${${LIBS_VAR}}
+ PARENT_SCOPE
+ )
+ set(${LIBDIRS_VAR}
+ ${${LIBDIRS_VAR}}
+ PARENT_SCOPE
+ )
+endfunction()
diff --git a/cmake/modules/libbpf.cmake b/cmake/modules/libbpf.cmake
index 39e1408bc3..e68b862600 100644
--- a/cmake/modules/libbpf.cmake
+++ b/cmake/modules/libbpf.cmake
@@ -55,11 +55,6 @@ else()
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${LIBS_PACKAGE_NAME}"
COMPONENT "libs-deps"
)
- install(
- DIRECTORY "${LIBBPF_INCLUDE}"
- DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIBS_PACKAGE_NAME}"
- COMPONENT "libs-deps"
- )
endif()
if(NOT TARGET libbpf)
diff --git a/cmake/modules/libelf.cmake b/cmake/modules/libelf.cmake
index c37b0c74e1..99d5e495ff 100644
--- a/cmake/modules/libelf.cmake
+++ b/cmake/modules/libelf.cmake
@@ -86,11 +86,6 @@ else()
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${LIBS_PACKAGE_NAME}"
COMPONENT "libs-deps"
)
- install(
- DIRECTORY "${LIBELF_INCLUDE}"
- DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIBS_PACKAGE_NAME}"
- COMPONENT "libs-deps"
- )
endif()
# We add a custom target, in this way we can always depend on `libelf` without distinguishing
diff --git a/cmake/modules/libscap.cmake b/cmake/modules/libscap.cmake
index b41b12ff37..346ac51b1b 100644
--- a/cmake/modules/libscap.cmake
+++ b/cmake/modules/libscap.cmake
@@ -32,6 +32,8 @@ if(NOT HAVE_LIBSCAP)
check_symbol_exists(strlcpy "string.h" HAVE_STRLCPY)
check_symbol_exists(strlcat "string.h" HAVE_STRLCAT)
+ include(BuildPkgConfigDependencies)
+
if(HAVE_STRLCPY)
message(STATUS "Existing strlcpy found, will *not* use local definition")
else()
@@ -89,33 +91,9 @@ if(NOT HAVE_LIBSCAP)
endif()
endforeach()
- # Installation targets and their dependencies
- set(libscap_link_libraries)
- set(libscap_link_libdirs)
- foreach(libscap_install_lib ${LIBSCAP_INSTALL_LIBS})
- list(APPEND libscap_link_libraries ${libscap_install_lib})
- get_target_property(install_lib_link_libraries ${libscap_install_lib} LINK_LIBRARIES)
- foreach(install_lib_link_library ${install_lib_link_libraries})
- if(NOT ${install_lib_link_library} IN_LIST libscap_subdir_targets)
- if(${install_lib_link_library} MATCHES "/")
- # We have a path. Convert it to -L + -l.
- get_filename_component(scap_lib_dir ${install_lib_link_library} DIRECTORY)
- list(APPEND libscap_link_libdirs -L${scap_lib_dir})
- get_filename_component(scap_lib_base ${install_lib_link_library} NAME_WE)
- string(REGEX REPLACE "^lib" "" scap_lib_base ${scap_lib_base})
- list(APPEND libscap_link_libraries ${scap_lib_base})
- else()
- list(APPEND libscap_link_libraries ${install_lib_link_library})
- endif()
- endif()
- endforeach()
- endforeach()
- list(REMOVE_DUPLICATES libscap_link_libraries)
-
set(libscap_link_flags)
- foreach(libscap_link_library ${libscap_link_libraries})
- list(APPEND libscap_link_flags "-l${libscap_link_library}")
- endforeach()
+ set(libscap_link_libdirs "")
+ add_pkgconfig_dependency(libscap_link_libdirs libscap_link_flags scap "")
string(REPLACE ";" " " LIBSCAP_LINK_LIBRARIES_FLAGS "${libscap_link_flags}")
string(REPLACE ";" " " LIBSCAP_LINK_LIBDIRS_FLAGS "${libscap_link_libdirs}")
diff --git a/cmake/modules/libsinsp.cmake b/cmake/modules/libsinsp.cmake
index ff336e27f2..0c55678a19 100644
--- a/cmake/modules/libsinsp.cmake
+++ b/cmake/modules/libsinsp.cmake
@@ -48,44 +48,23 @@ if(NOT HAVE_LIBSINSP)
include(bs_threadpool)
endif()
- set(LIBSINSP_INCLUDE_DIRS ${LIBS_DIR} ${LIBS_DIR}/userspace ${LIBSCAP_INCLUDE_DIRS}
- ${DRIVER_CONFIG_DIR}
- )
-
- if(NOT EMSCRIPTEN)
- get_filename_component(TBB_ABSOLUTE_INCLUDE_DIR ${TBB_INCLUDE_DIR} ABSOLUTE)
- list(APPEND LIBSINSP_INCLUDE_DIRS ${TBB_ABSOLUTE_INCLUDE_DIR})
- endif()
-
- get_filename_component(JSONCPP_ABSOLUTE_INCLUDE_DIR ${JSONCPP_INCLUDE} ABSOLUTE)
- list(APPEND LIBSINSP_INCLUDE_DIRS ${JSONCPP_ABSOLUTE_INCLUDE_DIR})
-
- get_filename_component(VALIJSON_ABSOLUTE_INCLUDE_DIR ${VALIJSON_INCLUDE} ABSOLUTE)
- list(APPEND LIBSINSP_INCLUDE_DIRS ${VALIJSON_ABSOLUTE_INCLUDE_DIR})
+ set(LIBSINSP_INCLUDE_DIRS)
- get_filename_component(RE2_ABSOLUTE_INCLUDE_DIR ${RE2_INCLUDE} ABSOLUTE)
- list(APPEND LIBSINSP_INCLUDE_DIRS ${RE2_ABSOLUTE_INCLUDE_DIR})
-
- if(ENABLE_THREAD_POOL AND NOT EMSCRIPTEN)
- get_filename_component(BS_THREADPOOL_ABSOLUTE_INCLUDE_DIR ${BS_THREADPOOL_INCLUDE} ABSOLUTE)
- list(APPEND LIBSINSP_INCLUDE_DIRS ${BS_THREADPOOL_ABSOLUTE_INCLUDE_DIR})
+ if(NOT USE_BUNDLED_TBB AND NOT EMSCRIPTEN)
+ list(APPEND LIBSINSP_INCLUDE_DIRS ${TBB_INCLUDE_DIR})
endif()
- if(NOT MINIMAL_BUILD
- AND NOT EMSCRIPTEN
- AND NOT APPLE
- )
- get_filename_component(CARES_ABSOLUTE_INCLUDE_DIR ${CARES_INCLUDE} ABSOLUTE)
- list(APPEND LIBSINSP_INCLUDE_DIRS ${CARES_ABSOLUTE_INCLUDE_DIR})
+ if(NOT USE_BUNDLED_JSONCPP)
+ list(APPEND LIBSINSP_INCLUDE_DIRS ${JSONCPP_INCLUDE})
endif()
- if(NOT WIN32
+ if(NOT USE_BUNDLED_CURL
+ AND NOT WIN32
AND NOT APPLE
AND NOT MINIMAL_BUILD
AND NOT EMSCRIPTEN
)
- get_filename_component(CURL_ABSOLUTE_INCLUDE_DIR ${CURL_INCLUDE_DIRS} ABSOLUTE)
- list(APPEND LIBSINSP_INCLUDE_DIRS ${CURL_ABSOLUTE_INCLUDE_DIR})
+ list(APPEND LIBSINSP_INCLUDE_DIRS ${CURL_INCLUDE_DIRS})
endif()
function(set_sinsp_target_properties target)
diff --git a/userspace/libpman/CMakeLists.txt b/userspace/libpman/CMakeLists.txt
index 8457571158..e1799eb302 100644
--- a/userspace/libpman/CMakeLists.txt
+++ b/userspace/libpman/CMakeLists.txt
@@ -51,3 +51,12 @@ endif()
if(USE_BUNDLED_LIBBPF)
add_dependencies(pman libbpf)
endif()
+
+install(
+ TARGETS pman
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+ COMPONENT "scap"
+ OPTIONAL
+)
diff --git a/userspace/libscap/CMakeLists.txt b/userspace/libscap/CMakeLists.txt
index a1d8b67e5f..466a24864a 100644
--- a/userspace/libscap/CMakeLists.txt
+++ b/userspace/libscap/CMakeLists.txt
@@ -185,15 +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 PRIVATE ${CMAKE_THREAD_LIBS_INIT} ${PROTOBUF_LIB} ${JSONCPP_LIB})
- else()
- target_link_libraries(scap PRIVATE scap_engine_gvisor)
- endif()
+ target_link_libraries(scap PUBLIC scap_engine_gvisor)
endif()
# ##################################################################################################
diff --git a/userspace/libscap/engine/gvisor/CMakeLists.txt b/userspace/libscap/engine/gvisor/CMakeLists.txt
index 7865656ffb..85af7e6eb0 100644
--- a/userspace/libscap/engine/gvisor/CMakeLists.txt
+++ b/userspace/libscap/engine/gvisor/CMakeLists.txt
@@ -60,32 +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)
-
- add_dependencies(scap_engine_gvisor_o uthash)
- add_dependencies(scap scap_engine_gvisor_o)
- target_sources(scap PRIVATE $)
-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 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)
diff --git a/userspace/libscap/engine/nodriver/CMakeLists.txt b/userspace/libscap/engine/nodriver/CMakeLists.txt
index 302011d08a..865a29bbdf 100644
--- a/userspace/libscap/engine/nodriver/CMakeLists.txt
+++ b/userspace/libscap/engine/nodriver/CMakeLists.txt
@@ -13,5 +13,5 @@
# the License.
#
add_library(scap_engine_nodriver nodriver.c)
-target_link_libraries(scap_engine_nodriver PRIVATE scap_engine_noop)
+target_link_libraries(scap_engine_nodriver PUBLIC scap_engine_noop)
set_scap_target_properties(scap_engine_nodriver)
diff --git a/userspace/libscap/libscap.pc.in b/userspace/libscap/libscap.pc.in
index 40b6e96ed8..520020691f 100644
--- a/userspace/libscap/libscap.pc.in
+++ b/userspace/libscap/libscap.pc.in
@@ -1,10 +1,10 @@
prefix=${pcfiledir}/../..
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
-includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@LIBS_PACKAGE_NAME@
Name: libscap
Description: lib for System CAPture
Version: @FALCOSECURITY_LIBS_VERSION@
Libs: -L${libdir} @LIBSCAP_LINK_LIBDIRS_FLAGS@ @LIBSCAP_LINK_LIBRARIES_FLAGS@
-Cflags: -I${includedir}/@LIBS_PACKAGE_NAME@/libscap
+Cflags: -I${includedir}
diff --git a/userspace/libsinsp/CMakeLists.txt b/userspace/libsinsp/CMakeLists.txt
index be4ca47090..511852d907 100644
--- a/userspace/libsinsp/CMakeLists.txt
+++ b/userspace/libsinsp/CMakeLists.txt
@@ -29,6 +29,7 @@ endif()
include(ExternalProject)
+include(BuildPkgConfigDependencies)
include(jsoncpp)
include(zlib)
@@ -165,15 +166,12 @@ target_link_libraries(
PRIVATE "${CURL_LIBRARIES}" "${JSONCPP_LIB}" "${RE2_LIB}"
)
-set(SINSP_PKGCONFIG_LIBRARIES scap "${ZLIB_LIB}" "${CURL_LIBRARIES}" "${JSONCPP_LIB}" "${RE2_LIB}")
-
if(NOT EMSCRIPTEN)
target_link_libraries(
sinsp
INTERFACE "${CARES_LIB}"
PRIVATE "${TBB_LIB}"
)
- list(APPEND SINSP_PKGCONFIG_LIBRARIES "${CARES_LIB}")
endif()
if(USE_BUNDLED_VALIJSON)
@@ -219,7 +217,33 @@ function(prepare_cri_grpc api_version)
target_include_directories(
cri_${api_version} PUBLIC $
)
+ target_link_libraries(
+ cri_${api_version}
+ PUBLIC "${GRPCPP_LIB}"
+ "${GRPC_LIB}"
+ "${GPR_LIB}"
+ "${GRPC_LIBRARIES}"
+ "${PROTOBUF_LIB}"
+ "${CARES_LIB}"
+ "${OPENSSL_LIBRARIES}"
+ )
add_dependencies(cri_${api_version} grpc)
+ install(
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/cri-${api_version}.grpc.pb.h
+ ${CMAKE_CURRENT_BINARY_DIR}/cri-${api_version}.pb.h
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIBS_PACKAGE_NAME}/libsinsp"
+ COMPONENT "scap"
+ )
+ if(NOT BUILD_SHARED_LIBS)
+ install(
+ TARGETS cri_${api_version}
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
+ COMPONENT "scap"
+ OPTIONAL
+ )
+ endif()
endfunction()
if(NOT EMSCRIPTEN)
@@ -240,50 +264,27 @@ if(NOT WIN32)
prepare_cri_grpc(v1alpha2)
prepare_cri_grpc(v1)
- target_link_libraries(
- sinsp
- PRIVATE cri_v1alpha2 cri_v1
- INTERFACE "${GRPC_LIBRARIES}" "${GRPCPP_LIB}" "${GRPC_LIB}" "${GPR_LIB}"
- "${PROTOBUF_LIB}" "${CARES_LIB}"
- )
- list(
- APPEND
- SINSP_PKGCONFIG_LIBRARIES
- "${GRPC_LIBRARIES}"
- "${GRPCPP_LIB}"
- "${GRPC_LIB}"
- "${GPR_LIB}"
- "${PROTOBUF_LIB}"
- "${CARES_LIB}"
- )
+ target_link_libraries(sinsp PUBLIC cri_v1alpha2 cri_v1)
if(NOT MUSL_OPTIMIZED_BUILD)
find_library(LIB_ANL anl)
if(LIB_ANL)
target_link_libraries(sinsp INTERFACE rt anl)
- list(APPEND SINSP_PKGCONFIG_LIBRARIES rt anl)
else()
target_link_libraries(sinsp INTERFACE rt)
- list(APPEND SINSP_PKGCONFIG_LIBRARIES rt)
endif()
endif()
else()
target_link_libraries(sinsp INTERFACE rt)
- list(APPEND SINSP_PKGCONFIG_LIBRARIES rt)
endif() # NOT MINIMAL_BUILD
endif() # NOT APPLE
- target_link_libraries(sinsp INTERFACE "${OPENSSL_LIBRARIES}")
- list(APPEND SINSP_PKGCONFIG_LIBRARIES "${OPENSSL_LIBRARIES}")
-
target_link_libraries(sinsp INTERFACE dl pthread)
- list(APPEND SINSP_PKGCONFIG_LIBRARIES dl pthread)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
target_link_libraries(sinsp INTERFACE stdc++fs)
- list(APPEND SINSP_PKGCONFIG_LIBRARIES stdc++fs)
endif()
endif()
endif() # NOT WIN32
@@ -318,24 +319,7 @@ add_definitions(-DSINSP_AGENT_CGROUP_MEM_PATH_ENV_VAR="${SINSP_AGENT_CGROUP_MEM_
# https://github.com/curl/curl/blob/curl-7_84_0/CMakeLists.txt#L1539
set(SINSP_PKG_CONFIG_LIBS)
set(SINSP_PKG_CONFIG_LIBDIRS "")
-foreach(sinsp_lib ${SINSP_PKGCONFIG_LIBRARIES})
- if(${sinsp_lib} MATCHES "^-")
- # We have a flag. Pass it through unchanged.
- list(APPEND SINSP_PKG_CONFIG_LIBS ${sinsp_lib})
- elseif(${sinsp_lib} MATCHES "/")
- # We have a path. Convert it to -L + -l.
- get_filename_component(sinsp_lib_dir ${sinsp_lib} DIRECTORY)
- list(APPEND SINSP_PKG_CONFIG_LIBDIRS -L${sinsp_lib_dir})
- get_filename_component(sinsp_lib_base ${sinsp_lib} NAME_WE)
- string(REGEX REPLACE "^lib" "" sinsp_lib_base ${sinsp_lib_base})
- list(APPEND SINSP_PKG_CONFIG_LIBS -l${sinsp_lib_base})
- elseif(${sinsp_lib} STREQUAL "scap")
- # We require libscap.pc, so skip it.
- else()
- # Assume we have a plain library name. Prefix it with "-l".
- list(APPEND SINSP_PKG_CONFIG_LIBS -l${sinsp_lib})
- endif()
-endforeach()
+add_pkgconfig_dependency(SINSP_PKG_CONFIG_LIBDIRS SINSP_PKG_CONFIG_LIBS sinsp scap)
# Build our pkg-config "Cflags:" flags.
set(SINSP_PKG_CONFIG_INCLUDES "")
diff --git a/userspace/libsinsp/libsinsp.pc.in b/userspace/libsinsp/libsinsp.pc.in
index c1cc4a1e2a..38e8e4e0d8 100644
--- a/userspace/libsinsp/libsinsp.pc.in
+++ b/userspace/libsinsp/libsinsp.pc.in
@@ -1,6 +1,6 @@
prefix=${pcfiledir}/../..
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
-includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@LIBS_PACKAGE_NAME@
Name: libsinsp
Description: lib for System INSPection
@@ -8,4 +8,4 @@ Version: @FALCOSECURITY_LIBS_VERSION@
Requires: libscap
Libs: -L${libdir} -lsinsp @SINSP_PKG_CONFIG_LIBDIRS@ @SINSP_PKG_CONFIG_LIBS@
-Cflags: -I${includedir}/@LIBS_PACKAGE_NAME@/libsinsp @SINSP_PKG_CONFIG_INCLUDES@
+Cflags: -I${includedir} @SINSP_PKG_CONFIG_INCLUDES@