[libcxx-commits] [libcxx] [RFC][libc++] Install modules. (PR #75741)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 19 08:56:15 PST 2023


================
@@ -210,3 +210,57 @@ add_custom_target(generate-cxx-modules
   ALL DEPENDS
     ${_all_modules}
 )
+
+# Use the relative path between the installation and the module in the json
+# file. This allows moving the entire installation to a different to a
+# different location.
+file(RELATIVE_PATH LIBCXX_MODULE_RELATIVE_PATH
+	${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_LIBRARY_DIR}
+	${CMAKE_INSTALL_PREFIX}/${LIBCXX_INSTALL_MODULE_DIR})
+configure_file(
+  "modules.json.in"
+  "${LIBCXX_LIBRARY_DIR}/modules.json"
+  @ONLY
+)
+
+# Dummy library to make modules an installation component.
+add_library(cxx-modules INTERFACE)
+add_dependencies(cxx-modules generate-cxx-modules)
+
+if (LIBCXX_INSTALL_MODULES)
+  foreach(file ${LIBCXX_MODULE_STD_SOURCES} ${LIBCXX_MODULE_STD_COMPAT_SOURCES})
+    get_filename_component(dir ${file} DIRECTORY)
+    install(FILES ${file}
+      DESTINATION "${LIBCXX_INSTALL_MODULE_DIR}/${dir}"
+      COMPONENT cxx-modules
+      PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+    )
+  endforeach()
+
+  # Install the generated module files.
+  install(FILES
+      "${LIBCXX_GENERATED_MODULE_DIR}/std.cppm"
+      "${LIBCXX_GENERATED_MODULE_DIR}/std.compat.cppm"
+    DESTINATION "${LIBCXX_INSTALL_MODULE_DIR}"
+    COMPONENT cxx-modules
+    PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+  )
+
+  # Install the module manifest.
+  install(FILES
+      "${LIBCXX_LIBRARY_DIR}/modules.json"
----------------
ldionne wrote:

We should namespace this file for libc++, since it's going to be in `$prefix/usr/lib`. I don't have a strong preference what it's called, but a suggestion is `libc++.module.json`.

https://github.com/llvm/llvm-project/pull/75741


More information about the libcxx-commits mailing list