Skip to content

Commit

Permalink
On GNU-compatible compilers, avoid embedding paths into binaries.
Browse files Browse the repository at this point in the history
This is helpful for reproducible builds, and also makes it easier
to debug binaries built on another system.
  • Loading branch information
whitequark committed Nov 23, 2019
1 parent 14e095c commit 690f87c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Expand Up @@ -66,6 +66,14 @@ endif()

# common compiler flags

if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)) OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(DEBUG_FLAGS "-fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.")
set(DEBUG_FLAGS "${DEBUG_FLAGS} -ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEBUG_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEBUG_FLAGS}")
endif()

if(MINGW)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
Expand Down

4 comments on commit 690f87c

@vespakoen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broke my build on macOS Catalina:

koen@maccie ~/Projects/solvespace/build [master *]
$ make                                                                                                                                                                                                          
[  0%] Building CXX object extlib/libdxfrw/CMakeFiles/dxfrw.dir/intern/drw_dbg.cpp.o
clang: error: unknown argument: '-ffile-prefix-map=/Users/koen/Projects/solvespace=.'
make[2]: *** [extlib/libdxfrw/CMakeFiles/dxfrw.dir/intern/drw_dbg.cpp.o] Error 1
make[1]: *** [extlib/libdxfrw/CMakeFiles/dxfrw.dir/all] Error 2
make: *** [all] Error 2

@vespakoen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case it helps:

$ clang --version
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@whitequark
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this is pretty annoying. This is the changeset that added -ffile-prefix-map support to Clang. It got released either in Clang 8 or Clang 9. Unfortunately... Apple uses a totally different versioning scheme for Clang, and "Apple clang 11" could be basically anything. So I'm not sure how exactly to detect this.

@whitequark
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit fb536a1 should fix this.

Please sign in to comment.