From 690f87cf4a908d89238dccb3165059b913f8dd63 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 23 Nov 2019 16:33:47 +0000 Subject: [PATCH] On GNU-compatible compilers, avoid embedding paths into binaries. This is helpful for reproducible builds, and also makes it easier to debug binaries built on another system. --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8e5b9b..5b24ffc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,14 @@ endif() # common compiler flags +if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)) OR + CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(DEBUG_FLAGS "-fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.") + set(DEBUG_FLAGS "${DEBUG_FLAGS} -ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEBUG_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEBUG_FLAGS}") +endif() + if(MINGW) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")