From cab2e3c486e8bcaf14dc27e63e6bc9df28f3c5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danie=CC=88l=20de=20Kok?= Date: Thu, 17 Jun 2021 17:13:53 +0200 Subject: [PATCH] Strip build directory prefix in the __FILE__ macro Various macros use __FILE__ to embed the source file name in errors/logs. However, the full path is encoder, making reproducible builds harder. This change uses the -fmacro-prefix-map of GCC >= 8.0 and clang >= 10.0 to remove the source directory prefix. Since only the prefix is removed, the relevant source file names are still included. Background: https://reproducible-builds.org/docs/build-path/ --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bced901..a3870cb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,13 @@ option(SPM_USE_EXTERNAL_ABSL "Use external protobuf" OFF) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND + CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 10.0) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND + CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)) + string(APPEND CMAKE_CXX_FLAGS " -fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=''") +endif() + if (UNIX) include(GNUInstallDirs) set(prefix ${CMAKE_INSTALL_PREFIX})