Skip to content

Commit 728de35

Browse files
improve -ffile-prefix-map detection (catchorg#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ý <[email protected]>
1 parent 0e139b7 commit 728de35

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

CMake/CatchMiscFunctions.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
include(CheckCXXCompilerFlag)
1010
function(add_cxx_flag_if_supported_to_targets flagname targets)
11-
check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flagname})
11+
string(MAKE_C_IDENTIFIER ${flagname} flag_identifier )
12+
check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flag_identifier})
1213

13-
if (HAVE_FLAG_${flagname})
14+
if (HAVE_FLAG_${flag_identifier})
1415
foreach(target ${targets})
1516
target_compile_options(${target} PUBLIC ${flagname})
1617
endforeach()
@@ -112,9 +113,8 @@ endfunction()
112113
# Adds flags required for reproducible build to the target
113114
# Currently only supports GCC and Clang
114115
function(add_build_reproducibility_settings target)
115-
# Make the build reproducible on versions of g++ and clang that supports -ffile-prefix-map
116-
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 8) OR
117-
("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 10))
118-
target_compile_options(${target} PRIVATE "-ffile-prefix-map=${CATCH_DIR}=.")
116+
# Make the build reproducible on versions of g++ and clang that supports -ffile-prefix-map
117+
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
118+
add_cxx_flag_if_supported_to_targets("-ffile-prefix-map=${CATCH_DIR}/=" "${target}")
119119
endif()
120120
endfunction()

0 commit comments

Comments
 (0)