llvm.org GIT mirror llvm / 6a3f589
[CMake] Provide an option to use relative paths in debug info CMake always uses absolute file paths in the generated compiler invocation which results in absolute file paths being embedded in debug info. This is undesirable when building a toolchain e.g. on bots as the debug info may embed the bot source checkout path which is meaningless anywhere else. This change introduces the LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO which uses -fdebug-prefix-map (where supported) options to rewrite paths embedded into debug info with relative ones. Additionally, LLVM_SOURCE_PREFIX can be used to override the path to source directory with a different one. Differential Revision: https://reviews.llvm.org/D62622 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362185 91177308-0d34-0410-b5e6-96231b3b80d8 Petr Hosek a month ago
3 changed file(s) with 20 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
976976 endif()
977977 endif()
978978 endif()
979
980 option(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO "Use relative paths in debug info" OFF)
981 set(LLVM_SOURCE_PREFIX "" CACHE STRING "Use prefix for sources in debug info")
982
983 if(LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO)
984 check_c_compiler_flag("-fdebug-prefix-map=foo=bar" SUPPORTS_FDEBUG_PREFIX_MAP)
985 if(LLVM_ENABLE_PROJECTS_USED)
986 get_filename_component(source_root "${LLVM_MAIN_SRC_DIR}/.." ABSOLUTE)
987 else()
988 set(source_root "${LLVM_MAIN_SRC_DIR}")
989 endif()
990 file(RELATIVE_PATH relative_root "${source_root}" "${CMAKE_BINARY_DIR}")
991 append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${CMAKE_BINARY_DIR}=${relative_root}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
992 append_if(SUPPORTS_FDEBUG_PREFIX_MAP "-fdebug-prefix-map=${source_root}/=${LLVM_SOURCE_PREFIX}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
993 add_flag_if_supported("-no-canonical-prefixes" NO_CANONICAL_PREFIXES)
994 endif()
230230 -DLLVM_ENABLE_WERROR=${LLVM_ENABLE_WERROR}
231231 -DLLVM_HOST_TRIPLE=${LLVM_HOST_TRIPLE}
232232 -DLLVM_HAVE_LINK_VERSION_SCRIPT=${LLVM_HAVE_LINK_VERSION_SCRIPT}
233 -DLLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO=${LLVM_USE_RELATIVE_PATHS_IN_DEBUG_INFO}
234 -DLLVM_SOURCE_PREFIX=${LLVM_SOURCE_PREFIX}
233235 -DPACKAGE_VERSION=${PACKAGE_VERSION}
234236 -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
235237 -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
374374 CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
375375 -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
376376 -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE}
377 -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
377378 -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
378379 -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE}
379380 -DCMAKE_CXX_COMPILER_TARGET=${TARGET_TRIPLE}
463464 CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
464465 -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
465466 -DLLVM_DEFAULT_TARGET_TRIPLE=${target}
467 -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
466468 -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
467469 -DCMAKE_C_COMPILER_TARGET=${target}
468470 -DCMAKE_CXX_COMPILER_TARGET=${target}