alibaba / async_simple

Simple, light-weight and easy-to-use asynchronous components
Apache License 2.0
1.69k stars 251 forks source link

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

Closed tchaikov closed 10 months ago

tchaikov commented 10 months ago

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 commented 10 months ago

CLA assistant check
All committers have signed the CLA.

tchaikov commented 10 months ago

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