diff --git a/CMake/MiscFunctions.cmake b/CMake/MiscFunctions.cmake index 1f0ed865..5fb3c4f7 100644 --- a/CMake/MiscFunctions.cmake +++ b/CMake/MiscFunctions.cmake @@ -77,3 +77,13 @@ function(add_warnings_to_targets targets) endif() endif() endfunction() + +# Adds flags required for reproducible build to the target +# Currently only supports GCC and Clang +function(add_build_reproducibility_settings target) +# Make the build reproducible on versions of g++ and clang that supports -ffile-prefix-map + if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 8) OR + ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 10)) + target_compile_options(${target} PRIVATE "-ffile-prefix-map=${CATCH_DIR}=.") + endif() +endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f3dd4ab..3dd11578 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -240,6 +240,7 @@ add_library(Catch2 STATIC ${BENCHMARK_HEADERS} ${BENCHMARK_SOURCES} ) +add_build_reproducibility_settings(Catch2) add_library(Catch2::Catch2 ALIAS Catch2) if (ANDROID) @@ -281,6 +282,7 @@ target_include_directories(Catch2 add_library(Catch2WithMain STATIC ${SOURCES_DIR}/internal/catch_main.cpp ) +add_build_reproducibility_settings(Catch2WithMain) add_library(Catch2::Catch2WithMain ALIAS Catch2WithMain) target_link_libraries(Catch2WithMain PUBLIC Catch2) set_target_properties(Catch2WithMain