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++.
This commit is contained in:
Danny Robson 2024-05-14 09:04:42 +10:00
parent 4aa60cc306
commit f269ef3f4f
3 changed files with 12 additions and 6 deletions

View File

@ -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")

View File

@ -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

View File

@ -192,8 +192,10 @@ if (CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DENABLE_DEBUGGING)
if (RUNTIME_DEBUGGING)
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
# argument that allows one to choose, or temporarily switch the lines