diff options
| author | Tim Blechmann | 2022-10-04 21:55:50 +0800 |
|---|---|---|
| committer | GitHub | 2022-10-04 15:55:50 +0200 |
| commit | 728de353be6a6d3658932bfc8e1ea5c7742a61c6 (patch) | |
| tree | 7b7219f19086de94e5ed57ecab1b1f6a919b52b1 | |
| parent | 0e139b73e4a462f0ea23e22c3182a3d1f91b719d (diff) | |
| download | catch3-728de353be6a6d3658932bfc8e1ea5c7742a61c6.tar.gz | |
improve `-ffile-prefix-map` detection (#2517)
the current implementation has two problems:
* `clang-cl` does not know `-ffile-prefix-map`, but in CMake it is
reported as "Clang", so the compiler will warn about an unknown
compiler option.
* XCode's clang in CMake is reported as "AppleClang", so it is not picked
up as "Clang", so it is not passed `-ffile-prefix-map`, even though
it supports it.
Also changed the map so that the normalized `__FILE__` paths are the same
as what the approval tests normalize paths into.
Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
| -rw-r--r-- | CMake/CatchMiscFunctions.cmake | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/CMake/CatchMiscFunctions.cmake b/CMake/CatchMiscFunctions.cmake index 73c8b4dd..be76d838 100644 --- a/CMake/CatchMiscFunctions.cmake +++ b/CMake/CatchMiscFunctions.cmake @@ -8,9 +8,10 @@ include(CheckCXXCompilerFlag) function(add_cxx_flag_if_supported_to_targets flagname targets) - check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flagname}) + string(MAKE_C_IDENTIFIER ${flagname} flag_identifier ) + check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flag_identifier}) - if (HAVE_FLAG_${flagname}) + if (HAVE_FLAG_${flag_identifier}) foreach(target ${targets}) target_compile_options(${target} PUBLIC ${flagname}) endforeach() @@ -112,9 +113,8 @@ 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}=.") + # Make the build reproducible on versions of g++ and clang that supports -ffile-prefix-map + if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + add_cxx_flag_if_supported_to_targets("-ffile-prefix-map=${CATCH_DIR}/=" "${target}") endif() endfunction() |