From 537bd14cff5437d1b39ab7de012264f43670321a Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Sat, 26 Jul 2025 18:28:37 +0200 Subject: [PATCH] build: Use stacktrace flags by default only in module libraries Previously it was being linked to executables and libraries, which caused symbol redefinitions when building statically. --- .../custom-modules/ns3-compiler-workarounds.cmake | 12 +++++++----- build-support/custom-modules/ns3-module-macros.cmake | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/build-support/custom-modules/ns3-compiler-workarounds.cmake b/build-support/custom-modules/ns3-compiler-workarounds.cmake index 8bbe15035..6624b787d 100644 --- a/build-support/custom-modules/ns3-compiler-workarounds.cmake +++ b/build-support/custom-modules/ns3-compiler-workarounds.cmake @@ -63,18 +63,19 @@ check_cxx_source_compiles( " STACKTRACE_LIBRARY_ENABLED ) +mark_as_advanced(stacktrace_flags) +set(stacktrace_flags "" CACHE INTERNAL "") if(STACKTRACE_LIBRARY_ENABLED) - set(stacktrace_flags) if(GCC) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "12.0.0") # GCC does not support stacktracing elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14.0.0") - set(stacktrace_flags -lstdc++_libbacktrace) + set(stacktrace_flags -lstdc++_libbacktrace CACHE INTERNAL "") else() - set(stacktrace_flags -lstdc++exp) + set(stacktrace_flags -lstdc++exp CACHE INTERNAL "") endif() elseif(CLANG) - set(stacktrace_flags -lstdc++_libbacktrace) + set(stacktrace_flags -lstdc++_libbacktrace CACHE INTERNAL "") else() # Most likely MSVC, which does not need custom flags for this endif() @@ -96,6 +97,7 @@ if(STACKTRACE_LIBRARY_ENABLED) if(STACKTRACE_LIBRARY_IS_LINKED) add_definitions(-DSTACKTRACE_LIBRARY_IS_LINKED=1) - link_libraries(${stacktrace_flags}) + else() + set(stacktrace_flags "" CACHE INTERNAL "") endif() endif() diff --git a/build-support/custom-modules/ns3-module-macros.cmake b/build-support/custom-modules/ns3-module-macros.cmake index 70f2e1ee9..742bc8521 100644 --- a/build-support/custom-modules/ns3-module-macros.cmake +++ b/build-support/custom-modules/ns3-module-macros.cmake @@ -288,8 +288,8 @@ endfunction() function(build_lib_reexport_third_party_libraries libname libraries_to_link) # Separate ns-3 and non-ns-3 libraries to manage their propagation properly separate_ns3_from_non_ns3_libs( - "${libname}" "${libraries_to_link}" ns_libraries_to_link - non_ns_libraries_to_link + "${libname}" "${libraries_to_link};${stacktrace_flags}" + ns_libraries_to_link non_ns_libraries_to_link ) set(ns3-external-libs "${non_ns_libraries_to_link};${ns3-external-libs}"