Skip to content

Commit 0cd4bab

Browse files
mstorsjotstellar
authored andcommitted
Reapply [libcxx] [modules] Fix relative paths with absolute LIBCXX_INSTALL_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)
1 parent cfaeee6 commit 0cd4bab

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

libcxx/modules/CMakeLists.txt

+13-2
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,20 @@ add_custom_target(generate-cxx-modules
206206
# Configure the modules manifest.
207207
# Use the relative path between the installation and the module in the json
208208
# file. This allows moving the entire installation to a different location.
209+
if("${CMAKE_INSTALL_PREFIX}" STREQUAL "")
210+
set(BASE_DIRECTORY "/")
211+
else()
212+
set(BASE_DIRECTORY ${CMAKE_INSTALL_PREFIX})
213+
endif()
214+
cmake_path(ABSOLUTE_PATH LIBCXX_INSTALL_LIBRARY_DIR
215+
BASE_DIRECTORY ${BASE_DIRECTORY}
216+
OUTPUT_VARIABLE ABS_LIBRARY_DIR)
217+
cmake_path(ABSOLUTE_PATH LIBCXX_INSTALL_MODULES_DIR
218+
BASE_DIRECTORY ${BASE_DIRECTORY}
219+
OUTPUT_VARIABLE ABS_MODULES_DIR)
209220
file(RELATIVE_PATH LIBCXX_MODULE_RELATIVE_PATH
210-
${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_LIBRARY_DIR}
211-
${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_MODULES_DIR})
221+
${ABS_LIBRARY_DIR}
222+
${ABS_MODULES_DIR})
212223
configure_file(
213224
"modules.json.in"
214225
"${LIBCXX_LIBRARY_DIR}/libc++.modules.json"

0 commit comments

Comments
 (0)