[llvm] 8a8778f - [CMake] Enable the use of -ffile-prefix-map

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 19 15:14:27 PDT 2020


Author: Petr Hosek
Date: 2020-03-19T15:14:15-07:00
New Revision: 8a8778f25f1052343d23e38a2583fe023a162e12

URL: https://github.com/llvm/llvm-project/commit/8a8778f25f1052343d23e38a2583fe023a162e12
DIFF: https://github.com/llvm/llvm-project/commit/8a8778f25f1052343d23e38a2583fe023a162e12.diff

LOG: [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

Added: 
    

Modified: 
    llvm/cmake/modules/HandleLLVMOptions.cmake
    llvm/cmake/modules/LLVMExternalProjectUtils.cmake
    llvm/docs/CMake.rst

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 2563ee430174..0c5f4e08aaba 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -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)
@@ -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()

diff  --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
index a69a4720b8b0..29f4fcbf8aba 100644
--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -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}

diff  --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst
index 70c81adfee3a..d0a8854c575a 100644
--- a/llvm/docs/CMake.rst
+++ b/llvm/docs/CMake.rst
@@ -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
 ============
 


        


More information about the llvm-commits mailing list