[libcxx-commits] [libcxx] [libcxx] [modules] Fix relative paths with absolute LIBCXX_INSTALL_MODULES_DIR (PR #85756)

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 19 01:56:05 PDT 2024


https://github.com/mstorsjo created https://github.com/llvm/llvm-project/pull/85756

In other contexts, install directories such as
LIBCXX_INSTALL_LIBRARY_DIR and LIBCXX_INSTALL_MODULES_DIR can be specified either as a relative path, relative to CMAKE_INSTALL_PREFIX, or as an absolute path.

When calculating the relative path between the two, account for the fact that LIBCXX_INSTALL_MODULES_DIR and LIBCXX_INSTALL_LIBRARY_DIR can be absolute paths too.

>From eb5a9e97d77f2a6b47a4dee425f35a2dd3cbd493 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Tue, 19 Mar 2024 10:52:46 +0200
Subject: [PATCH] [libcxx] [modules] Fix relative paths with absolute
 LIBCXX_INSTALL_MODULES_DIR

In other contexts, install directories such as
LIBCXX_INSTALL_LIBRARY_DIR and LIBCXX_INSTALL_MODULES_DIR can be
specified either as a relative path, relative to CMAKE_INSTALL_PREFIX,
or as an absolute path.

When calculating the relative path between the two, account for the
fact that LIBCXX_INSTALL_MODULES_DIR and LIBCXX_INSTALL_LIBRARY_DIR
can be absolute paths too.
---
 libcxx/modules/CMakeLists.txt | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/libcxx/modules/CMakeLists.txt b/libcxx/modules/CMakeLists.txt
index 0dea8cfca94ac3..08deb452f5579a 100644
--- a/libcxx/modules/CMakeLists.txt
+++ b/libcxx/modules/CMakeLists.txt
@@ -203,12 +203,23 @@ add_custom_target(generate-cxx-modules
     ${_all_modules}
 )
 
+
+function(make_absolute OUT_VAR INPUT BASE)
+  if (IS_ABSOLUTE ${INPUT})
+    set(${OUT_VAR} "${INPUT}" PARENT_SCOPE)
+  else()
+    set(${OUT_VAR} "${BASE}/${INPUT}" PARENT_SCOPE)
+  endif()
+endfunction()
+
 # 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.
+make_absolute(ABS_LIBRARY_DIR "${LIBCXX_INSTALL_LIBRARY_DIR}" "${CMAKE_INSTALL_PREFIX}")
+make_absolute(ABS_MODULES_DIR "${LIBCXX_INSTALL_MODULES_DIR}" "${CMAKE_INSTALL_PREFIX}")
 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"



More information about the libcxx-commits mailing list