mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-19 00:56:41 +00:00
[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.
This commit is contained in:
parent
9dd2c59312
commit
fc0e9c8315
@ -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.
|
||||
|
||||
|
@ -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})
|
||||
|
88
libcxx/modules/CMakeLists.txt.in
Normal file
88
libcxx/modules/CMakeLists.txt.in
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user