aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark de Wever <koraq@xs4all.nl>2024-02-13 20:04:34 +0100
committerGitHub <noreply@github.com>2024-02-13 20:04:34 +0100
commitfc0e9c8315564288f9079a633892abadace534cf (patch)
tree7c4ec7cfe8dabb85176a07181c6abdb649ef14e8
parent9dd2c59312bfae3526cee5e836a6b67b2e9b4989 (diff)
downloadllvm-fc0e9c8315564288f9079a633892abadace534cf.zip
llvm-fc0e9c8315564288f9079a633892abadace534cf.tar.gz
llvm-fc0e9c8315564288f9079a633892abadace534cf.tar.bz2
[libc++][modules] Re-add build dir CMakeLists.txt. (#81370)
This CMakeLists.txt is used to build modules without build system support. This was removed in d06ae33ec32122bb526fb35025c1f0cf979f1090. This is used in the documentation how to use modules. Made some minor changes to make it work with the std.compat module using the std module. Note the CMakeLists.txt in the build dir should be removed once build system support is generally available.
-rw-r--r--libcxx/docs/Modules.rst4
-rw-r--r--libcxx/modules/CMakeLists.txt20
-rw-r--r--libcxx/modules/CMakeLists.txt.in88
3 files changed, 112 insertions, 0 deletions
diff --git a/libcxx/docs/Modules.rst b/libcxx/docs/Modules.rst
index 533c3fb..ee2b81d 100644
--- a/libcxx/docs/Modules.rst
+++ b/libcxx/docs/Modules.rst
@@ -218,9 +218,13 @@ Building this project is done with the following steps, assuming the files
$ mkdir build
$ cmake -G Ninja -S . -B build -DCMAKE_CXX_COMPILER=<path-to-compiler> -DLIBCXX_BUILD=<build>
+ $ ninja -j1 std -C build
$ ninja -C build
$ build/main
+.. note:: The ``std`` dependencies of ``std.compat`` is not always resolved when
+ building the ``std`` target using multiple jobs.
+
.. warning:: ``<path-to-compiler>`` should point point to the real binary and
not to a symlink.
diff --git a/libcxx/modules/CMakeLists.txt b/libcxx/modules/CMakeLists.txt
index 0388c04..0dea8cf 100644
--- a/libcxx/modules/CMakeLists.txt
+++ b/libcxx/modules/CMakeLists.txt
@@ -137,6 +137,25 @@ set(LIBCXX_MODULE_STD_COMPAT_SOURCES
std.compat/cwctype.inc
)
+# TODO MODULES the CMakeLists.txt in the build directory is only temporary.
+# This allows using as available in the build directory. Once build systems
+# have proper support for the installed files this will be removed.
+if ("${LIBCXX_GENERATED_INCLUDE_DIR}" STREQUAL "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}")
+ # This typically happens when the target is not installed.
+ set(LIBCXX_CONFIGURED_INCLUDE_DIRS "${LIBCXX_GENERATED_INCLUDE_DIR}")
+else()
+ # It's important that the arch directory be included first so that its header files
+ # which interpose on the default include dir be included instead of the default ones.
+ set(LIBCXX_CONFIGURED_INCLUDE_DIRS
+ "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR};${LIBCXX_GENERATED_INCLUDE_DIR}"
+ )
+endif()
+configure_file(
+ "CMakeLists.txt.in"
+ "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt"
+ @ONLY
+)
+
set(LIBCXX_MODULE_STD_INCLUDE_SOURCES)
foreach(file ${LIBCXX_MODULE_STD_SOURCES})
set(
@@ -166,6 +185,7 @@ configure_file(
)
set(_all_modules)
+list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt")
list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.cppm")
list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.compat.cppm")
foreach(file ${LIBCXX_MODULE_STD_SOURCES} ${LIBCXX_MODULE_STD_COMPAT_SOURCES})
diff --git a/libcxx/modules/CMakeLists.txt.in b/libcxx/modules/CMakeLists.txt.in
new file mode 100644
index 0000000..e332d70
--- /dev/null
+++ b/libcxx/modules/CMakeLists.txt.in
@@ -0,0 +1,88 @@
+cmake_minimum_required(VERSION 3.26)
+
+project(libc++-modules LANGUAGES CXX)
+
+# Enable CMake's module support
+if(CMAKE_VERSION VERSION_LESS "3.28.0")
+ if(CMAKE_VERSION VERSION_LESS "3.27.0")
+ set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
+ else()
+ set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
+ endif()
+ set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
+else()
+ cmake_policy(VERSION 3.28)
+endif()
+
+# Default to C++ extensions being off. Libc++'s modules support have trouble
+# with extensions right now.
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+# Propagates the CMake options to the modules.
+#
+# This uses the std module hard-coded since the std.compat module does not
+# depend on these flags.
+macro(compile_define_if_not condition def)
+ if (NOT ${condition})
+ target_compile_definitions(std PRIVATE ${def})
+ endif()
+endmacro()
+macro(compile_define_if condition def)
+ if (${condition})
+ target_compile_definitions(std PRIVATE ${def})
+ endif()
+endmacro()
+
+### STD
+
+add_library(std)
+target_sources(std
+ PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
+ std.cppm
+)
+
+target_include_directories(std SYSTEM PRIVATE @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
+
+if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
+ target_compile_options(std PUBLIC -fno-exceptions)
+endif()
+
+target_compile_options(std
+ PUBLIC
+ -nostdinc++
+ -Wno-reserved-module-identifier
+ -Wno-reserved-user-defined-literal
+ @LIBCXX_COMPILE_FLAGS@
+)
+set_target_properties(std
+ PROPERTIES
+ OUTPUT_NAME "c++std"
+)
+
+### STD.COMPAT
+
+add_library(std.compat)
+target_sources(std.compat
+ PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
+ std.compat.cppm
+)
+
+target_include_directories(std.compat SYSTEM PRIVATE @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
+
+if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
+ target_compile_options(std.compat PUBLIC -fno-exceptions)
+endif()
+
+target_compile_options(std.compat
+ PUBLIC
+ -nostdinc++
+ -Wno-reserved-module-identifier
+ -Wno-reserved-user-defined-literal
+ -fmodule-file=std=${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/std.dir/std.pcm
+ @LIBCXX_COMPILE_FLAGS@
+)
+set_target_properties(std.compat
+ PROPERTIES
+ OUTPUT_NAME "c++std.compat"
+)
+add_dependencies(std.compat std)