1cmake_minimum_required(VERSION 3.26) 2 3project(libc++-modules LANGUAGES CXX) 4 5# Enable CMake's module support 6if(CMAKE_VERSION VERSION_LESS "3.27.0") 7 set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a") 8else() 9 set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7") 10endif() 11set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1) 12 13# Default to C++ extensions being off. Libc++'s modules support have trouble 14# with extensions right now. 15set(CMAKE_CXX_EXTENSIONS OFF) 16 17# Propagates the CMake options to the modules. 18# 19# This uses the std module hard-coded since the std.compat module does not 20# depend on these flags. 21macro(compile_define_if_not condition def) 22 if (NOT ${condition}) 23 target_compile_definitions(std PRIVATE ${def}) 24 endif() 25endmacro() 26macro(compile_define_if condition def) 27 if (${condition}) 28 target_compile_definitions(std PRIVATE ${def}) 29 endif() 30endmacro() 31 32add_library(std) 33target_sources(std 34 PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES 35 std.cppm 36) 37 38target_include_directories(std SYSTEM PRIVATE @LIBCXX_CONFIGURED_INCLUDE_DIRS@) 39 40if (NOT @LIBCXX_ENABLE_EXCEPTIONS@) 41 target_compile_options(std PUBLIC -fno-exceptions) 42endif() 43 44target_compile_options(std 45 PUBLIC 46 -nostdinc++ 47 -Wno-reserved-module-identifier 48 -Wno-reserved-user-defined-literal 49 @LIBCXX_COMPILE_FLAGS@ 50) 51set_target_properties(std 52 PROPERTIES 53 OUTPUT_NAME "c++std" 54) 55