diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt index 43cefd5600646..52611e43968bc 100644 --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -1706,6 +1706,11 @@ add_dependencies(cxx-headers generate-cxx-headers) target_include_directories(cxx-headers INTERFACE ${LIBCXX_GENERATED_INCLUDE_TARGET_DIR} ${LIBCXX_GENERATED_INCLUDE_DIR}) +# Make sure to map the generated include directory back to libc++'s actual source directory when generating +# debug information. Otherwise, the debug information will refer to generated headers which are created during +# the build and generally not persistent. +target_add_compile_flags_if_supported(cxx-headers INTERFACE "-fdebug-prefix-map=${LIBCXX_GENERATED_INCLUDE_DIR}=${LIBCXX_SOURCE_DIR}/include") + if (LIBCXX_INSTALL_HEADERS) foreach(file ${files}) get_filename_component(dir ${file} DIRECTORY)