Skip to content

Commit

Permalink
[CMake] Enable the use of -ffile-prefix-map
Browse files Browse the repository at this point in the history
This handles not paths embedded in debug info, but also in sources.
Since the use of this flag is controlled by an option, rather than
replacing the new option, we add a new option.

Differential Revision: https://reviews.llvm.org/D76018
  • Loading branch information
petrhosek committed Mar 19, 2020
1 parent 95b6f62 commit 8a8778f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
18 changes: 17 additions & 1 deletion llvm/cmake/modules/HandleLLVMOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,9 @@ if(macos_signposts_available)
endif()
endif()

set(LLVM_SOURCE_PREFIX "" CACHE STRING "Use prefix for sources")

option(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO "Use relative paths in debug info" OFF)
set(LLVM_SOURCE_PREFIX "" CACHE STRING "Use prefix for sources in debug info")

if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO)
check_c_compiler_flag("-fdebug-prefix-map=foo=bar" SUPPORTS_FDEBUG_PREFIX_MAP)
Expand All @@ -1034,3 +1035,18 @@ if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO)
append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)
endif()

option(LLVM_USE_RELATIVE_PATHS_IN_FILES "Use relative paths in sources and debug info" OFF)

if(LLVM_USE_RELATIVE_PATHS_IN_FILES)
check_c_compiler_flag("-ffile-prefix-map=foo=bar" SUPPORTS_FFILE_PREFIX_MAP)
if(LLVM_ENABLE_PROJECTS_USED)
get_filename_component(source_root "${LLVM_MAIN_SRC_DIR}/.." ABSOLUTE)
else()
set(source_root "${LLVM_MAIN_SRC_DIR}")
endif()
file(RELATIVE_PATH relative_root "${source_root}" "${CMAKE_BINARY_DIR}")
append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)
endif()
1 change: 1 addition & 0 deletions llvm/cmake/modules/LLVMExternalProjectUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ function(llvm_ExternalProject_Add name source_dir)
-DLLVM_HOST_TRIPLE=${LLVM_HOST_TRIPLE}
-DLLVM_HAVE_LINK_VERSION_SCRIPT=${LLVM_HAVE_LINK_VERSION_SCRIPT}
-DLLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO=${LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO}
-DLLVM_USE_RELATIVE_PATHS_IN_FILES=${LLVM_USE_RELATIVE_PATHS_IN_FILES}
-DLLVM_SOURCE_PREFIX=${LLVM_SOURCE_PREFIX}
-DPACKAGE_VERSION=${PACKAGE_VERSION}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
Expand Down
8 changes: 8 additions & 0 deletions llvm/docs/CMake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,14 @@ LLVM-specific variables
If enabled, the Z3 constraint solver is activated for the Clang static analyzer.
A recent version of the z3 library needs to be available on the system.

**LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO**:BOOL
Rewrite absolute source paths in debug info to relative ones. The source prefix
can be adjusted via the LLVM_SOURCE_PREFIX variable.

**LLVM_USE_RELATIVE_PATHS_IN_FILES**:BOOL
Rewrite absolute source paths in sources and debug info to relative ones. The
source prefix can be adjusted via the LLVM_SOURCE_PREFIX variable.

CMake Caches
============

Expand Down

0 comments on commit 8a8778f

Please sign in to comment.