Skip to content

Commit 8a8778f

Browse files
committed
[CMake] Enable the use of -ffile-prefix-map
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
1 parent 95b6f62 commit 8a8778f

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,8 +1019,9 @@ if(macos_signposts_available)
10191019
endif()
10201020
endif()
10211021

1022+
set(LLVM_SOURCE_PREFIX "" CACHE STRING "Use prefix for sources")
1023+
10221024
option(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO "Use relative paths in debug info" OFF)
1023-
set(LLVM_SOURCE_PREFIX "" CACHE STRING "Use prefix for sources in debug info")
10241025

10251026
if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO)
10261027
check_c_compiler_flag("-fdebug-prefix-map=foo=bar" SUPPORTS_FDEBUG_PREFIX_MAP)
@@ -1034,3 +1035,18 @@ if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO)
10341035
append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
10351036
add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)
10361037
endif()
1038+
1039+
option(LLVM_USE_RELATIVE_PATHS_IN_FILES "Use relative paths in sources and debug info" OFF)
1040+
1041+
if(LLVM_USE_RELATIVE_PATHS_IN_FILES)
1042+
check_c_compiler_flag("-ffile-prefix-map=foo=bar" SUPPORTS_FFILE_PREFIX_MAP)
1043+
if(LLVM_ENABLE_PROJECTS_USED)
1044+
get_filename_component(source_root "${LLVM_MAIN_SRC_DIR}/.." ABSOLUTE)
1045+
else()
1046+
set(source_root "${LLVM_MAIN_SRC_DIR}")
1047+
endif()
1048+
file(RELATIVE_PATH relative_root "${source_root}" "${CMAKE_BINARY_DIR}")
1049+
append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1050+
append_if(SUPPORTS_FFILE_PREFIX_MAP "-ffile-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1051+
add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)
1052+
endif()

llvm/cmake/modules/LLVMExternalProjectUtils.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ function(llvm_ExternalProject_Add name source_dir)
239239
-DLLVM_HOST_TRIPLE=${LLVM_HOST_TRIPLE}
240240
-DLLVM_HAVE_LINK_VERSION_SCRIPT=${LLVM_HAVE_LINK_VERSION_SCRIPT}
241241
-DLLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO=${LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO}
242+
-DLLVM_USE_RELATIVE_PATHS_IN_FILES=${LLVM_USE_RELATIVE_PATHS_IN_FILES}
242243
-DLLVM_SOURCE_PREFIX=${LLVM_SOURCE_PREFIX}
243244
-DPACKAGE_VERSION=${PACKAGE_VERSION}
244245
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}

llvm/docs/CMake.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,14 @@ LLVM-specific variables
631631
If enabled, the Z3 constraint solver is activated for the Clang static analyzer.
632632
A recent version of the z3 library needs to be available on the system.
633633

634+
**LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO**:BOOL
635+
Rewrite absolute source paths in debug info to relative ones. The source prefix
636+
can be adjusted via the LLVM_SOURCE_PREFIX variable.
637+
638+
**LLVM_USE_RELATIVE_PATHS_IN_FILES**:BOOL
639+
Rewrite absolute source paths in sources and debug info to relative ones. The
640+
source prefix can be adjusted via the LLVM_SOURCE_PREFIX variable.
641+
634642
CMake Caches
635643
============
636644

0 commit comments

Comments
 (0)