Skip to content

Commit

Permalink
Reapply [libcxx] [modules] Fix relative paths with absolute LIBCXX_IN…
Browse files Browse the repository at this point in the history
…STALL_MODULES_DIR (#86020)

This reapplies 272d1b4 (from #85756),
which was reverted in
4079370.

In the previous attempt, empty CMAKE_INSTALL_PREFIX was handled by
quoting them, in d209d13. That made the
calls to cmake_path(ABSOLUTE_PATH) succeed, but the output paths of that
weren't actually absolute, which was required by file(RELATIVE_PATH).

Avoid this issue by constructing a non-empty base directory variable
to use for calculating the relative path.

(cherry picked from commit 50801f1)
  • Loading branch information
mstorsjo authored and tstellar committed Mar 28, 2024
1 parent cfaeee6 commit 0cd4bab
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions libcxx/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,20 @@ add_custom_target(generate-cxx-modules
# Configure the modules manifest.
# Use the relative path between the installation and the module in the json
# file. This allows moving the entire installation to a different location.
if("${CMAKE_INSTALL_PREFIX}" STREQUAL "")
set(BASE_DIRECTORY "/")
else()
set(BASE_DIRECTORY ${CMAKE_INSTALL_PREFIX})
endif()
cmake_path(ABSOLUTE_PATH LIBCXX_INSTALL_LIBRARY_DIR
BASE_DIRECTORY ${BASE_DIRECTORY}
OUTPUT_VARIABLE ABS_LIBRARY_DIR)
cmake_path(ABSOLUTE_PATH LIBCXX_INSTALL_MODULES_DIR
BASE_DIRECTORY ${BASE_DIRECTORY}
OUTPUT_VARIABLE ABS_MODULES_DIR)
file(RELATIVE_PATH LIBCXX_MODULE_RELATIVE_PATH
${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_LIBRARY_DIR}
${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_MODULES_DIR})
${ABS_LIBRARY_DIR}
${ABS_MODULES_DIR})
configure_file(
"modules.json.in"
"${LIBCXX_LIBRARY_DIR}/libc++.modules.json"
Expand Down

0 comments on commit 0cd4bab

Please sign in to comment.