-
-
Notifications
You must be signed in to change notification settings - Fork 810
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
使用了C++20 module的项目生成的CMakeLists.txt不正确 #5765
Comments
Title: The CMakeLists.txt generated by projects using the C++20 module is incorrect |
你可以先自己调下 cmakelists.txt 看下哪里不对,xmake 能编译,不代表 cmake 一定也能很好支持 c++ modules。 |
You can first adjust cmakelists.txt yourself to see what is wrong. If xmake can compile, it does not mean that cmake can also support c++ modules well. |
Actually CMake support modules (with one exception, header units). But you should add sources like the following: target_sources(foo
PUBLIC
FILE_SET CXX_MODULES FILES
foo.cxx
) Note the Sources: https://www.kitware.com/import-cmake-the-experiment-is-over/ |
You can try add it in generated CMakeLists.txt manually. Does it work? I think cmake is able to automatically recognize and support .cppm files for compiling as modules. It works for me. Only non-module file suffixes (.cxx) need to be set CXX_MODULES file type explicitly. |
在我的环境下 windows + cmake 3.31.0 并使用 cppm 后缀无效,还是需要显式添加 PRIVATE FILE_SET CXX_MODULES FILES |
I can confirm that this works for me only if I add to CMakeLists.txt:
I use cmake version 3.30.3 |
Also have to mention: if you wanna use
set_project("TestModules")
set_languages("c23", "c++23")
set_version("1.0.0")
add_rules("mode.debug", "mode.release")
set_policy("compatibility.version", "3.0")
set_warnings("all", "error")
if is_mode("debug") then
set_symbols("debug")
set_optimize("none")
else
set_symbols("hidden")
set_optimize("fastest")
set_strip("all")
end
target("TestModules")
set_kind("binary")
add_files("Source.cpp", "Vec3.cppm")
Code of If you use this CMakeLists.txt, you may encounter a warning after reloading the project. However, everything should work correctly, at least with the latest version of MSVC.
|
Xmake 版本
v2.9.5+HEAD.d30de52e9
操作系统版本和架构
Windows11 version 23H2
描述问题
src/main.cpp:
src/vec3.cppm:
xmake.lua:
直接使用
xmake
进行构建是正常的,但是生成的CMakeLists.txt
无法正常使用。CMakeLists.txt:
用
CMake
构建得到的报错:期待的结果
期待生成的
CMakeLists.txt
能和用xmake
一样成功构建工程配置
附加信息和错误日志
用
CMake
构建得到的报错:The text was updated successfully, but these errors were encountered: