Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support CMake 3.27 and up for building C++20 module #356

Merged
merged 1 commit into from
Jan 1, 2024

Conversation

tchaikov
Copy link
Contributor

@tchaikov tchaikov commented Jan 1, 2024

CMake 3.27 changed the CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API for enabling the experimental C++ module support back then. and CMake 3.28 officially support C++20 modules. so let's set the CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API and set the policy accordingly.

without this change, following steps fail the build

$ CC=clang CXX=clang++ cmake -Bbuild_modules -DCMAKE_BUILD_TYPE=Release -DASYNC_SIMPLE_BUILD_MODULES=ON -GNinja
$ ninja -C build_modules/
ninja: Entering directory `build_modules/'
[29/73] Building CXX object demo_example/CMakeFiles/CountCharUsingModules.dir/CountChar.cpp.o
FAILED: demo_example/CMakeFiles/CountCharUsingModules.dir/CountChar.cpp.o
/home/kefu/.local/bin/clang++ -DUSE_MODULES -I/tmp/async_simple/demo_example/asio -I/tmp/async_simple/modules/.. -std=c++20 -D_GLIBCXX_USE_CXX11_ABI=1 -Wno-deprecated-register -Wno-mismatched-new-delete -Wno-deprecated-declarations -D_FILE_OFFSET_BITS=64 -fPIC -Wall -Werror -D__STDC_LIMIT_MACROS -g -Wno-uninitialized -m64 -DTARGET_64 -O2 -DNDEBUG -std=c++20 -MD -MT demo_example/CMakeFiles/CountCharUsingModules.dir/CountChar.cpp.o -MF demo_example/CMakeFiles/CountCharUsingModules.dir/CountChar.cpp.o.d -o demo_example/CMakeFiles/CountCharUsingModules.dir/CountChar.cpp.o -c /tmp/async_simple/demo_example/CountChar.cpp
/tmp/async_simple/demo_example/CountChar.cpp:22:8: fatal error: module 'async_simple' not found
   22 | import async_simple;
      | ~~~~~~~^~~~~~~~~~~~
1 error generated.

with CMake 3.28.20231228-g158ecdc and Clang 18 (64e63888dd8beae7272c0526e4770e31857dd0e7).

see also https://cmake.org/cmake/help/latest/policy/CMP0155.html

Why

What is changing

Example

@CLAassistant
Copy link

CLAassistant commented Jan 1, 2024

CLA assistant check
All committers have signed the CLA.

@tchaikov
Copy link
Contributor Author

tchaikov commented Jan 1, 2024

@ChuanqiXu9 hi Chuanqi, could you please help review this change?

CMake 3.27 changed the `CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API`
for enabling the experimental C++ module support back then. and
CMake 3.28 officially support C++20 modules. so let's set
the `CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API` and set the policy
accordingly.

without this change, following steps fail the build

```console
$ CC=clang CXX=clang++ cmake -Bbuild_modules -DCMAKE_BUILD_TYPE=Release -DASYNC_SIMPLE_BUILD_MODULES=ON -GNinja
$ ninja -C build_modules/
ninja: Entering directory `build_modules/'
[29/73] Building CXX object demo_example/CMakeFiles/CountCharUsingModules.dir/CountChar.cpp.o
FAILED: demo_example/CMakeFiles/CountCharUsingModules.dir/CountChar.cpp.o
/home/kefu/.local/bin/clang++ -DUSE_MODULES -I/tmp/async_simple/demo_example/asio -I/tmp/async_simple/modules/.. -std=c++20 -D_GLIBCXX_USE_CXX11_ABI=1 -Wno-deprecated-register -Wno-mismatched-new-delete -Wno-deprecated-declarations -D_FILE_OFFSET_BITS=64 -fPIC -Wall -Werror -D__STDC_LIMIT_MACROS -g -Wno-uninitialized -m64 -DTARGET_64 -O2 -DNDEBUG -std=c++20 -MD -MT demo_example/CMakeFiles/CountCharUsingModules.dir/CountChar.cpp.o -MF demo_example/CMakeFiles/CountCharUsingModules.dir/CountChar.cpp.o.d -o demo_example/CMakeFiles/CountCharUsingModules.dir/CountChar.cpp.o -c /tmp/async_simple/demo_example/CountChar.cpp
/tmp/async_simple/demo_example/CountChar.cpp:22:8: fatal error: module 'async_simple' not found
   22 | import async_simple;
      | ~~~~~~~^~~~~~~~~~~~
1 error generated.
```

with CMake 3.28.20231228-g158ecdc and Clang 18 (64e63888dd8beae7272c0526e4770e31857dd0e7).

see also https://cmake.org/cmake/help/latest/policy/CMP0155.html

Signed-off-by: Kefu Chai <[email protected]>
@tchaikov tchaikov force-pushed the cxx-module-cmake-3.28 branch from 307f701 to 638b62f Compare January 1, 2024 03:19
Copy link
Collaborator

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@ChuanqiXu9 ChuanqiXu9 merged commit d97b636 into alibaba:main Jan 1, 2024
14 checks passed
@tchaikov tchaikov deleted the cxx-module-cmake-3.28 branch January 1, 2024 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants