From f269ef3f4fb17b008910246513f779799f38ebfd Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 14 May 2024 09:04:42 +1000 Subject: [PATCH] cxx: only set GLIBCXX_DEBUG if using libstdc++ Some libraries detect the debug mode of the stdlib and try to integrate with the system headers (eg, range-v3) which obviously doesn't work well if we're using an alternative stdlib like clang's libc++. --- nc.cmake | 1 + nc_cxx.cmake | 13 ++++++++----- nc_optimisation.cmake | 4 +++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/nc.cmake b/nc.cmake index 4408613..93e929b 100644 --- a/nc.cmake +++ b/nc.cmake @@ -13,6 +13,7 @@ set (THREADS_PREFER_PTHREAD_FLAG ON) find_package (Threads REQUIRED) link_libraries (Threads::Threads) +# cxx.cmake must be imported first include ("${CMAKE_CURRENT_LIST_DIR}/nc_cxx.cmake") include ("${CMAKE_CURRENT_LIST_DIR}/nc_sanitizer.cmake") include ("${CMAKE_CURRENT_LIST_DIR}/nc_platform.cmake") diff --git a/nc_cxx.cmake b/nc_cxx.cmake index 40b5667..7478835 100644 --- a/nc_cxx.cmake +++ b/nc_cxx.cmake @@ -32,16 +32,19 @@ append_compile_flag ("/std:c++latest") ############################################################################### -set(STDLIB "libc++" CACHE STRING "Which stdlib to specify for Clang") +# STDLIB must be set after this block. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(STDLIB "libc++") append_compile_flag ("-stdlib=${STDLIB}") append_link_flag ("-fuse-ld=lld") -endif () - -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(STDLIB "libstdc++") append_link_flag ("-fuse-ld=gold") -endif () +else() + message(FATAL_ERROR "Unknown CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}") +endif() + ############################################################################### # find the gcc or clang filesystem library and append to libs if needed diff --git a/nc_optimisation.cmake b/nc_optimisation.cmake index 95a589a..d65ffe7 100644 --- a/nc_optimisation.cmake +++ b/nc_optimisation.cmake @@ -192,7 +192,9 @@ if (CMAKE_BUILD_TYPE MATCHES Debug) add_definitions(-DENABLE_DEBUGGING) if (RUNTIME_DEBUGGING) - add_definitions(-D_GLIBCXX_DEBUG) + if ("${STDLIB}" STREQUAL "libstdc++") + add_definitions(-D_GLIBCXX_DEBUG) + endif() endif() # Don't make any commits that use -O0 by default. Instead, either add an