CMake: Set -fmacro-prefix-map and -ffile-prefix-map

pull/3562/head
Stenzek 2 months ago
parent 843234f817
commit ca504bd0ed
No known key found for this signature in database

@ -92,6 +92,16 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
endif()
# Rewrite paths in macros to be relative to the source directory.
# Helpful for reproducible builds.
if(COMPILER_CLANG OR COMPILER_CLANG_CL OR COMPILER_GCC)
file(RELATIVE_PATH source_dir_remap "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}")
string(REGEX REPLACE "\/+$" "" source_dir_remap "${source_dir_remap}")
set(source_dir_remap_str "\"${CMAKE_SOURCE_DIR}\"=\"${source_dir_remap}\"")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmacro-prefix-map=${source_dir_remap_str} -ffile-prefix-map=${source_dir_remap_str}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmacro-prefix-map=${source_dir_remap_str} -ffile-prefix-map=${source_dir_remap_str}")
endif()
# Write binaries to a seperate directory.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")

Loading…
Cancel
Save