diff --git a/cmake/setup.cmake b/cmake/setup.cmake index 4008030..0a710b6 100644 --- a/cmake/setup.cmake +++ b/cmake/setup.cmake @@ -48,6 +48,35 @@ if(NOT HAVE_STDINT_H) add_compile_definitions(NO_STDINT_H) 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) # The main function called from the top-level CMakeLists.txt to define