From af7849b5797fcd39c3e3537d4ad07f4f28d32e27 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 14 Nov 2024 12:40:12 +0100 Subject: [PATCH] [cmake] use relative paths for debug symbols When not building a Debug configuration use relative paths for __FILE__ et al in the debug symbol entries --- cmake/CXXCompilerFlags.cmake | 12 ++++++++---- cmake/CompilerFlags.cmake | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cmake/CXXCompilerFlags.cmake b/cmake/CXXCompilerFlags.cmake index b288f8450..124b0ffdb 100644 --- a/cmake/CXXCompilerFlags.cmake +++ b/cmake/CXXCompilerFlags.cmake @@ -64,10 +64,14 @@ endif() CheckCXXFlag(-fno-omit-frame-pointer) -CheckCXXFlag(-fmacro-prefix-map="${CMAKE_SOURCE_DIR}"="./") -CheckCXXFlag(-fmacro-prefix-map="${CMAKE_BINARY_DIR}"="./build/") -CheckCXXFlag(-ffile-prefix-map="${CMAKE_SOURCE_DIR}"="./") -CheckCXXFlag(-ffile-prefix-map="${CMAKE_BINARY_DIR}"="./build") +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") + add_compile_options($<$>:-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.>) + add_compile_options($<$>:-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=.>) + add_compile_options($<$>:-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.>) + add_compile_options($<$>:-fdebug-prefix-map=${CMAKE_BINARY_DIR}=./build>) + add_compile_options($<$>:-fmacro-prefix-map=${CMAKE_BINARY_DIR}=./build>) + add_compile_options($<$>:-ffile-prefix-map=${CMAKE_BINARY_DIR}=./build>) +endif() # https://stackoverflow.com/questions/4913922/possible-problems-with-nominmax-on-visual-c if (WIN32) diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index f48beb50b..c9190e3e3 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -64,10 +64,14 @@ endif() CheckCFlag(-fno-omit-frame-pointer) -CheckCFlag(-fmacro-prefix-map="${CMAKE_SOURCE_DIR}"="./") -CheckCFlag(-fmacro-prefix-map="${CMAKE_BINARY_DIR}"="./build/") -CheckCFlag(-ffile-prefix-map="${CMAKE_SOURCE_DIR}"="./") -CheckCFlag(-ffile-prefix-map="${CMAKE_BINARY_DIR}"="./build") +if (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") + add_compile_options($<$>:-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.>) + add_compile_options($<$>:-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=.>) + add_compile_options($<$>:-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.>) + add_compile_options($<$>:-fdebug-prefix-map=${CMAKE_BINARY_DIR}=./build>) + add_compile_options($<$>:-fmacro-prefix-map=${CMAKE_BINARY_DIR}=./build>) + add_compile_options($<$>:-ffile-prefix-map=${CMAKE_BINARY_DIR}=./build>) +endif() set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} CACHE STRING "default CFLAGS") message("Using CFLAGS ${CMAKE_C_FLAGS}")