mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 16:05:44 -07:00
Normalise pathnames in assert statements where possible.
After commit 1470c9530b1cff3 enabled assertions, I found that my build scripts were complaining that the Windows binaries built from the same source twice were not generating the same output, and it turned out to be because the use of __FILE__ in every assert was baking in a pathname from my build setup containing a mkstemp()-randomised path component. I've found the '-fmacro-prefix-map' option, available in both gcc and clang (except the archaic gcc used by my NestedVM build, alas), which lets you remap pathnames for purpose of what __FILE__ expands to. So now our assertion statements should look as if the puzzle source just lived in /puzzles, and (just in case a pathname in a generated header ever becomes relevant) the cmake build directory is /build.
This commit is contained in:
@ -48,6 +48,35 @@ if(NOT HAVE_STDINT_H)
|
|||||||
add_compile_definitions(NO_STDINT_H)
|
add_compile_definitions(NO_STDINT_H)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Try to normalise source file pathnames as seen in __FILE__ (e.g.
|
||||||
|
# assertion failure messages). Partly to avoid bloating the binaries
|
||||||
|
# with file prefixes like /home/simon/stuff/things/tmp-7x6c5d54/, but
|
||||||
|
# also to make the builds more deterministic - building from the same
|
||||||
|
# source should give the same binary even if you do it in a
|
||||||
|
# differently named temp directory.
|
||||||
|
function(map_pathname src dst)
|
||||||
|
if(CMAKE_SYSTEM_NAME MATCHES "NestedVM")
|
||||||
|
# Do nothing: the NestedVM gcc is unfortunately too old to support
|
||||||
|
# this option.
|
||||||
|
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang" AND
|
||||||
|
CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
|
||||||
|
# -fmacro-prefix-map isn't available as a clang-cl option, so we
|
||||||
|
# prefix it with -Xclang to pass it straight through to the
|
||||||
|
# underlying clang -cc1 invocation, which spells the option the
|
||||||
|
# same way.
|
||||||
|
set(CMAKE_C_FLAGS
|
||||||
|
"${CMAKE_C_FLAGS} -Xclang -fmacro-prefix-map=${src}=${dst}"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU" OR
|
||||||
|
CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||||
|
set(CMAKE_C_FLAGS
|
||||||
|
"${CMAKE_C_FLAGS} -fmacro-prefix-map=${src}=${dst}"
|
||||||
|
PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
map_pathname(${CMAKE_SOURCE_DIR} /puzzles)
|
||||||
|
map_pathname(${CMAKE_BINARY_DIR} /build)
|
||||||
|
|
||||||
include(icons/icons.cmake)
|
include(icons/icons.cmake)
|
||||||
|
|
||||||
# The main function called from the top-level CMakeLists.txt to define
|
# The main function called from the top-level CMakeLists.txt to define
|
||||||
|
Reference in New Issue
Block a user