@cryptotaxi247 / netdata-1 / commits / 8fca43731

Fix up handling of libunwind in CMake. (#19451)

* 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.

Austin S. Hemmelgarn committed Jan 22, 2025 at 07:10 UTC 8fca4373168815d56f28da32617c3982dd25a8b8
3 files changed +31 -3
CMakeLists.txt
+6 -2
@@ -12,6 +12,8 @@ project(netdata
12 HOMEPAGE_URL "https://www.netdata.cloud"
13 LANGUAGES C CXX)
14 include(CMakeDependentOption)
15 +include(NetdataUtil)
16 +netdata_fixup_system_processor()
17
18 if(DEFINED BUILD_SHARED_LIBS)
19 if(NOT BUILD_SHARED_LIBS)
@@ -2167,11 +2169,13 @@ if(ENABLE_LIBUNWIND)
2169
2170 if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(amd64)")
2171 target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-x86_64)
2170 - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
2172 + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?.86")
2173 + target_link_libraries(libnetdata PUBLIC PkgCOnfig::LIBUNWIND -lunwind-x86)
2174 + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(aarch64)")
2175 target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-aarch64)
2176 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
2177 target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-arm)
2174 - elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc|ppc")
2178 + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "p(ower)?pc64")
2179 target_link_libraries(libnetdata PUBLIC PkgConfig::LIBUNWIND -lunwind-ppc64)
2180 else()
2181 message(WARNING "Unknown architecture ${CMAKE_SYSTEM_PROCESSOR} for libunwind. Stack traces may not work.")
packaging/cmake/Modules/NetdataLibBPF.cmake
+1 -1
@@ -59,7 +59,7 @@ function(netdata_bundle_libbpf)
59
60 set(_libbpf_lib_dir lib)
61
62 - if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
62 + if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(amd64)")
63 set(_libbpf_lib_dir lib64)
64 endif()
65
packaging/cmake/Modules/NetdataUtil.cmake
+24
@@ -3,6 +3,30 @@
3
4 include_guard()
5
6 +# Fix up CMAKE_SYSTEM_PROCESSOR to actually match the build target
7 +function(netdata_fixup_system_processor)
8 + if(OS_WINDOWS)
9 + return()
10 + endif()
11 +
12 + if(CMAKE_TOOLCHAIN_FILE)
13 + return()
14 + endif()
15 +
16 + execute_process(
17 + COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -dumpmachine
18 + COMMAND cut -f 1 -d -
19 + RESULT_VARIABLE return_code
20 + OUTPUT_VARIABLE output_data
21 + )
22 +
23 + if(return_code EQUAL 0)
24 + set(CMAKE_SYSTEM_PROCESSOR "${output_data}" PARENT_SCOPE)
25 + else()
26 + message(WARNING "Failed to detect target processor architecture, using CMake default")
27 + endif()
28 +endfunction()
29 +
30 # Determine the version of the host kernel.
31 #
32 # Only works on UNIX-like systems, stores the version in the cache