diff options
author | Peter Wu <peter@lekensteyn.nl> | 2019-01-21 12:08:34 +0100 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2019-01-21 13:29:41 +0000 |
commit | 6a7865e969e9c8e57b5ae0332930456a4cf6b705 (patch) | |
tree | 15abe3a9fb9ef82b16cc993caa9d222f3c386f2d /CMakeLists.txt | |
parent | 19630453bfc6873c3b320f369fd2c811ee9d5176 (diff) |
CMake: strip directory prefixes from __FILE__ macros
Depending on the build location, the full source and/or build directory
is currently visible in error messages (for example, DISSECTOR_ASSERT).
Remove these to help with reproducible builds and have shorter messages.
A similar option (-fdebug-prefix-map) is also needed, but it affects
external debugging tools and is therefore better left to distributors
(Debian and Arch Linux do this for example).
Bug: 15163
Change-Id: Icd8559bef2035f295aefbfc57ba6a342bfe76a41
Reviewed-on: https://code.wireshark.org/review/31645
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 99fb4f3e5b..a208ef0398 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -738,6 +738,29 @@ foreach(THIS_FLAG ${WIRESHARK_COMMON_FLAGS} ${WIRESHARK_CXX_ONLY_FLAGS}) endforeach() set(CMAKE_CXX_FLAGS "${ADDED_CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS}") +# Strips the source and build directory prefix from the __FILE__ macro to ensure +# reproducible builds. Supported since GCC 8, Clang support is pending. +if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") + # If the build dir is within the source dir, CMake will use something + # like ../epan/dfilter/semcheck.c. Map these relative paths in addition + # to CMAKE_BINARY_DIR since compile_commands.json uses absolute paths. + file(RELATIVE_PATH _relative_source_dir "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}") + string(REGEX REPLACE "/$" "" _relative_source_dir "${_relative_source_dir}") + + check_c_compiler_flag(-fmacro-prefix-map=old=new C_fmacro_prefix_map_old_new_VALID) + check_cxx_compiler_flag(-fmacro-prefix-map=old=new CXX_fmacro_prefix_map_old_new_VALID) + foreach(_lang C CXX) + if(${_lang}_fmacro_prefix_map_old_new_VALID) + set(_flags CMAKE_${_lang}_FLAGS) + set(${_flags} "${${_flags}} -fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=") + set(${_flags} "${${_flags}} -fmacro-prefix-map=${CMAKE_BINARY_DIR}/=") + if(_relative_source_dir MATCHES "\\.\\.$") + set(${_flags} "${${_flags}} -fmacro-prefix-map=${_relative_source_dir}/=") + endif() + endif() + endforeach() +endif() + include(CMakePushCheckState) if(ENABLE_ASAN) |