@@ -38,8 +38,8 @@ What works
38
38
~~~~~~~~~~
39
39
40
40
* Building BMIs
41
- * Running tests using the ``std `` module
42
- * Using the ``std `` module in external projects
41
+ * Running tests using the ``std `` and `` std.compat `` module
42
+ * Using the ``std `` and `` std.compat `` module in external projects
43
43
* The following "parts disabled" configuration options are supported
44
44
45
45
* ``LIBCXX_ENABLE_LOCALIZATION ``
@@ -65,10 +65,9 @@ Some of the current limitations
65
65
* Requires CMake 3.26 for C++23 support
66
66
* Requires CMake 3.27 for C++26 support
67
67
* Requires Ninja 1.11
68
- * Requires a recent Clang 17
68
+ * Requires Clang 17
69
69
* The path to the compiler may not be a symlink, ``clang-scan-deps `` does
70
70
not handle that case properly
71
- * Only C++23 and C++26 are tested
72
71
* Libc++ is not tested with modules instead of headers
73
72
* The module ``.cppm `` files are not installed
74
73
* Clang supports modules using GNU extensions, but libc++ does not work using
@@ -127,9 +126,13 @@ This is a small sample program that uses the module ``std``. It consists of a
127
126
128
127
.. code-block :: cpp
129
128
130
- import std;
129
+ import std; // When importing std.compat it's not needed to import std.
130
+ import std.compat;
131
131
132
- int main() { std::cout << "Hello modular world\n"; }
132
+ int main() {
133
+ std::cout << "Hello modular world\n";
134
+ ::printf("Hello compat modular world\n");
135
+ }
133
136
134
137
.. code-block :: cmake
135
138
@@ -142,7 +145,6 @@ This is a small sample program that uses the module ``std``. It consists of a
142
145
# Set language version used
143
146
#
144
147
145
- # At the moment only C++23 is tested.
146
148
set(CMAKE_CXX_STANDARD 23)
147
149
set(CMAKE_CXX_STANDARD_REQUIRED YES)
148
150
# Libc++ doesn't support compiler extensions for modules.
@@ -153,12 +155,16 @@ This is a small sample program that uses the module ``std``. It consists of a
153
155
#
154
156
155
157
# This is required to write your own modules in your project.
156
- if(CMAKE_VERSION VERSION_LESS "3.27.0")
157
- set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
158
+ if(CMAKE_VERSION VERSION_LESS "3.28.0")
159
+ if(CMAKE_VERSION VERSION_LESS "3.27.0")
160
+ set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
161
+ else()
162
+ set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
163
+ endif()
164
+ set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
158
165
else()
159
- set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "aa1f7df0-828a-4fcd-9afc-2dc80491aca7" )
166
+ cmake_policy(VERSION 3.28 )
160
167
endif()
161
- set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
162
168
163
169
#
164
170
# Import the modules from libc++
@@ -169,18 +175,16 @@ This is a small sample program that uses the module ``std``. It consists of a
169
175
std
170
176
URL "file://${LIBCXX_BUILD}/modules/c++/v1/"
171
177
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
178
+ SYSTEM
172
179
)
173
- FetchContent_GetProperties(std)
174
- if(NOT std_POPULATED)
175
- FetchContent_Populate(std)
176
- add_subdirectory(${std_SOURCE_DIR} ${std_BINARY_DIR} EXCLUDE_FROM_ALL)
177
- endif()
180
+ FetchContent_MakeAvailable(std)
178
181
179
182
#
180
183
# Adjust project compiler flags
181
184
#
182
185
183
186
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fprebuilt-module-path=${CMAKE_BINARY_DIR}/_deps/std-build/CMakeFiles/std.dir/>)
187
+ add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fprebuilt-module-path=${CMAKE_BINARY_DIR}/_deps/std-build/CMakeFiles/std.compat.dir/>)
184
188
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-nostdinc++>)
185
189
# The include path needs to be set to be able to use macros from headers.
186
190
# For example from, the headers <cassert> and <version>.
@@ -194,8 +198,9 @@ This is a small sample program that uses the module ``std``. It consists of a
194
198
add_link_options($<$<COMPILE_LANGUAGE:CXX>:-nostdlib++>)
195
199
add_link_options($<$<COMPILE_LANGUAGE:CXX>:-L${LIBCXX_BUILD}/lib>)
196
200
add_link_options($<$<COMPILE_LANGUAGE:CXX>:-Wl,-rpath,${LIBCXX_BUILD}/lib>)
197
- # Linking against std is required for CMake to get the proper dependencies
201
+ # Linking against the standard c++ library is required for CMake to get the proper dependencies.
198
202
link_libraries(std c++)
203
+ link_libraries(std.compat c++)
199
204
200
205
#
201
206
# Add the project
0 commit comments