1 cmake_minimum_required(VERSION 3.26)
3 project(libc++-modules LANGUAGES CXX)
5 # Enable CMake's module support
6 if(CMAKE_VERSION VERSION_LESS "3.28.0")
7 if(CMAKE_VERSION VERSION_LESS "3.27.0")
8 set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
10 set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
12 set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
14 cmake_policy(VERSION 3.28)
17 # Default to C++ extensions being off. Libc++'s modules support have trouble
18 # with extensions right now.
19 set(CMAKE_CXX_EXTENSIONS OFF)
21 # Propagates the CMake options to the modules.
23 # This uses the std module hard-coded since the std.compat module does not
24 # depend on these flags.
25 macro(compile_define_if_not condition def)
27 target_compile_definitions(std PRIVATE ${def})
30 macro(compile_define_if condition def)
32 target_compile_definitions(std PRIVATE ${def})
40 PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
44 target_include_directories(std SYSTEM PUBLIC @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
46 if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
47 target_compile_options(std PUBLIC -fno-exceptions)
50 target_compile_options(std
53 @LIBCXX_COMPILE_FLAGS@
55 target_compile_options(std
57 -Wno-reserved-module-identifier
58 -Wno-reserved-user-defined-literal
60 target_link_options(std PUBLIC -nostdlib++ -Wl,-rpath,@LIBCXX_LIBRARY_DIR@ -L@LIBCXX_LIBRARY_DIR@)
61 target_link_libraries(std c++)
62 set_target_properties(std
69 add_library(std.compat)
70 target_sources(std.compat
71 PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
75 target_include_directories(std.compat SYSTEM PUBLIC @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
77 if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
78 target_compile_options(std.compat PUBLIC -fno-exceptions)
81 target_compile_options(std.compat
84 @LIBCXX_COMPILE_FLAGS@
86 target_compile_options(std.compat
88 -Wno-reserved-module-identifier
89 -Wno-reserved-user-defined-literal
91 set_target_properties(std.compat
93 OUTPUT_NAME "c++std.compat"
95 add_dependencies(std.compat std)
96 target_link_libraries(std.compat PUBLIC std c++)