1if (CMAKE_VERSION VERSION_LESS 3.26) 2 message(WARNING "The libc++ modules won't be available because the CMake version is too old. Update to CMake 3.26 or later.") 3 return() 4endif() 5 6# The headers of Table 24: C++ library headers [tab:headers.cpp] 7# and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c] 8set(LIBCXX_MODULE_STD_SOURCES 9 std/algorithm.inc 10 std/any.inc 11 std/array.inc 12 std/atomic.inc 13 std/barrier.inc 14 std/bit.inc 15 std/bitset.inc 16 std/cassert.inc 17 std/cctype.inc 18 std/cerrno.inc 19 std/cfenv.inc 20 std/cfloat.inc 21 std/charconv.inc 22 std/chrono.inc 23 std/cinttypes.inc 24 std/climits.inc 25 std/clocale.inc 26 std/cmath.inc 27 std/codecvt.inc 28 std/compare.inc 29 std/complex.inc 30 std/concepts.inc 31 std/condition_variable.inc 32 std/coroutine.inc 33 std/csetjmp.inc 34 std/csignal.inc 35 std/cstdarg.inc 36 std/cstddef.inc 37 std/cstdint.inc 38 std/cstdio.inc 39 std/cstdlib.inc 40 std/cstring.inc 41 std/ctime.inc 42 std/cuchar.inc 43 std/cwchar.inc 44 std/cwctype.inc 45 std/deque.inc 46 std/exception.inc 47 std/execution.inc 48 std/expected.inc 49 std/filesystem.inc 50 std/flat_map.inc 51 std/flat_set.inc 52 std/format.inc 53 std/forward_list.inc 54 std/fstream.inc 55 std/functional.inc 56 std/future.inc 57 std/generator.inc 58 std/hazard_pointer.inc 59 std/initializer_list.inc 60 std/iomanip.inc 61 std/ios.inc 62 std/iosfwd.inc 63 std/iostream.inc 64 std/istream.inc 65 std/iterator.inc 66 std/latch.inc 67 std/limits.inc 68 std/list.inc 69 std/locale.inc 70 std/map.inc 71 std/mdspan.inc 72 std/memory.inc 73 std/memory_resource.inc 74 std/mutex.inc 75 std/new.inc 76 std/numbers.inc 77 std/numeric.inc 78 std/optional.inc 79 std/ostream.inc 80 std/print.inc 81 std/queue.inc 82 std/random.inc 83 std/ranges.inc 84 std/ratio.inc 85 std/rcu.inc 86 std/regex.inc 87 std/scoped_allocator.inc 88 std/semaphore.inc 89 std/set.inc 90 std/shared_mutex.inc 91 std/source_location.inc 92 std/span.inc 93 std/spanstream.inc 94 std/sstream.inc 95 std/stack.inc 96 std/stacktrace.inc 97 std/stdexcept.inc 98 std/stdfloat.inc 99 std/stop_token.inc 100 std/streambuf.inc 101 std/string.inc 102 std/string_view.inc 103 std/strstream.inc 104 std/syncstream.inc 105 std/system_error.inc 106 std/text_encoding.inc 107 std/thread.inc 108 std/tuple.inc 109 std/type_traits.inc 110 std/typeindex.inc 111 std/typeinfo.inc 112 std/unordered_map.inc 113 std/unordered_set.inc 114 std/utility.inc 115 std/valarray.inc 116 std/variant.inc 117 std/vector.inc 118 std/version.inc 119) 120 121# TODO MODULES the CMakeLists.txt in the install directory is only temporary 122# When that is removed the configured file can use the substitution 123# LIBCXX_GENERATED_INCLUDE_TARGET_DIR avoiding this set. 124# Also clean up the parts needed to generate the install version. 125# - LIBCXX_GENERATED_INCLUDE_DIR contains the libc++ headers 126# - LIBCXX_GENERATED_INCLUDE_TARGET_DIR contains the libc++ site config 127if ("${LIBCXX_GENERATED_INCLUDE_DIR}" STREQUAL "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}") 128 # This typically happens when the target is not installed. 129 set(LIBCXX_CONFIGURED_INCLUDE_DIRS "${LIBCXX_GENERATED_INCLUDE_DIR}") 130else() 131 # It's important that the arch directory be included first so that its header files 132 # which interpose on the default include dir be included instead of the default ones. 133 set(LIBCXX_CONFIGURED_INCLUDE_DIRS 134 "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR};${LIBCXX_GENERATED_INCLUDE_DIR}" 135 ) 136endif() 137configure_file( 138 "CMakeLists.txt.in" 139 "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt" 140 @ONLY 141) 142 143set(LIBCXX_MODULE_STD_INCLUDE_SOURCES) 144foreach(file ${LIBCXX_MODULE_STD_SOURCES}) 145 set( 146 LIBCXX_MODULE_STD_INCLUDE_SOURCES 147 "${LIBCXX_MODULE_STD_INCLUDE_SOURCES}#include \"${file}\"\n" 148 ) 149endforeach() 150 151configure_file( 152 "std.cppm.in" 153 "${LIBCXX_GENERATED_MODULE_DIR}/std.cppm" 154 @ONLY 155) 156 157set(_all_modules) 158list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt") 159list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.cppm") 160foreach(file ${LIBCXX_MODULE_STD_SOURCES}) 161 set(src "${CMAKE_CURRENT_SOURCE_DIR}/${file}") 162 set(dst "${LIBCXX_GENERATED_MODULE_DIR}/${file}") 163 add_custom_command(OUTPUT ${dst} 164 DEPENDS ${src} 165 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} 166 COMMENT "Copying CXX module ${file}") 167 list(APPEND _all_modules "${dst}") 168endforeach() 169 170add_custom_target(generate-cxx-modules 171 ALL DEPENDS 172 ${_all_modules} 173) 174