0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-13 17:19:11 +00:00

Fix up handling of libunwind in CMake. ()

* Fix up handling of libunwind in CMake.

- Fix the questionable default handling of CMAKE_SYSTEM_PROCESSOR so
  that it reliably reflects the target architecture.
- Add a case for handling 32-bit x86 builds with libunwind.
- Tweak the match cases for the various architectures to be more
  reliable.

* Fix libbpf usage of CMAKE_SYSTEM_PROCESSOR.
This commit is contained in:
Austin S. Hemmelgarn 2025-01-22 07:10:22 -05:00 committed by GitHub
parent 2133107a15
commit 8fca437316
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 3 deletions

View file

@ -12,6 +12,8 @@ project(netdata
HOMEPAGE_URL "https://www.netdata.cloud"
LANGUAGES C CXX)
include(CMakeDependentOption)
include(NetdataUtil)
netdata_fixup_system_processor()
if(DEFINED BUILD_SHARED_LIBS)
if(NOT BUILD_SHARED_LIBS)
@ -2167,11 +2169,13 @@ if(ENABLE_LIBUNWIND)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(amd64)")
target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-x86_64)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?.86")
target_link_libraries(libnetdata PUBLIC PkgCOnfig::LIBUNWIND -lunwind-x86)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(aarch64)")
target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-aarch64)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-arm)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc|ppc")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "p(ower)?pc64")
target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-ppc64)
else()
message(WARNING "Unknown architecture ${CMAKE_SYSTEM_PROCESSOR} for libunwind. Stack traces may not work.")

View file

@ -59,7 +59,7 @@ function(netdata_bundle_libbpf)
set(_libbpf_lib_dir lib)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(amd64)")
set(_libbpf_lib_dir lib64)
endif()

View file

@ -3,6 +3,30 @@
include_guard()
# Fix up CMAKE_SYSTEM_PROCESSOR to actually match the build target
function(netdata_fixup_system_processor)
if(OS_WINDOWS)
return()
endif()
if(CMAKE_TOOLCHAIN_FILE)
return()
endif()
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -dumpmachine
COMMAND cut -f 1 -d -
RESULT_VARIABLE return_code
OUTPUT_VARIABLE output_data
)
if(return_code EQUAL 0)
set(CMAKE_SYSTEM_PROCESSOR "${output_data}" PARENT_SCOPE)
else()
message(WARNING "Failed to detect target processor architecture, using CMake default")
endif()
endfunction()
# Determine the version of the host kernel.
#
# Only works on UNIX-like systems, stores the version in the cache