mirror of
https://github.com/varun-r-mallya/pylibbpf.git
synced 2026-02-12 16:11:00 +00:00
update CMakeLists.txt
This commit is contained in:
@ -4,10 +4,9 @@ project(pylibbpf)
|
|||||||
add_subdirectory(pybind11)
|
add_subdirectory(pybind11)
|
||||||
pybind11_add_module(pylibbpf src/main.cpp)
|
pybind11_add_module(pylibbpf src/main.cpp)
|
||||||
|
|
||||||
# Build vendored libbpf
|
|
||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
ExternalProject_Add(
|
ExternalProject_Add(
|
||||||
libbpf
|
libbpf_build
|
||||||
PREFIX libbpf
|
PREFIX libbpf
|
||||||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libbpf/src
|
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libbpf/src
|
||||||
CONFIGURE_COMMAND ""
|
CONFIGURE_COMMAND ""
|
||||||
@ -19,36 +18,22 @@ ExternalProject_Add(
|
|||||||
INSTALL_COMMAND ""
|
INSTALL_COMMAND ""
|
||||||
STEP_TARGETS build)
|
STEP_TARGETS build)
|
||||||
|
|
||||||
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
|
# Define a static library target pointing to the built libbpf.a
|
||||||
set(ARCH "x86")
|
add_library(libbpf_static STATIC IMPORTED GLOBAL)
|
||||||
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
|
|
||||||
set(ARCH "arm")
|
|
||||||
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
|
|
||||||
set(ARCH "arm64")
|
|
||||||
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64le")
|
|
||||||
set(ARCH "powerpc")
|
|
||||||
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips")
|
|
||||||
set(ARCH "mips")
|
|
||||||
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "riscv64")
|
|
||||||
set(ARCH "riscv")
|
|
||||||
elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64")
|
|
||||||
set(ARCH "loongarch")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(LIBBPF_INCLUDE_DIRS
|
set(LIBBPF_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include)
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/libbpf
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/libbpf/usr/include)
|
|
||||||
set(LIBBPF_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/libbpf/libbpf.a)
|
|
||||||
|
|
||||||
# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
|
set_target_properties(
|
||||||
# define (VERSION_INFO) here.
|
libbpf_static
|
||||||
|
PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/libbpf/libbpf.a"
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${LIBBPF_INCLUDE_DIRS}")
|
||||||
|
# Ensure build order: external project builds before linking
|
||||||
|
add_dependencies(libbpf_static libbpf_build)
|
||||||
|
add_dependencies(pylibbpf libbpf_static)
|
||||||
|
|
||||||
|
# Version info
|
||||||
target_compile_definitions(pylibbpf
|
target_compile_definitions(pylibbpf
|
||||||
PRIVATE VERSION_INFO=${PYLIBBPF_VERSION_INFO})
|
PRIVATE VERSION_INFO=${PYLIBBPF_VERSION_INFO})
|
||||||
|
|
||||||
# ensure build order
|
# Link the actual library target
|
||||||
add_dependencies(pylibbpf libbpf)
|
target_link_libraries(pylibbpf PRIVATE libbpf_static)
|
||||||
|
|
||||||
# headers + linking
|
|
||||||
target_include_directories(pylibbpf PRIVATE ${LIBBPF_INCLUDE_DIRS})
|
|
||||||
target_link_libraries(pylibbpf PRIVATE ${LIBBPF_LIBRARIES})
|
|
||||||
|
|||||||
Reference in New Issue
Block a user