xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.23k stars 793 forks source link

Cannot generate correct cmakelists.txt with c++20 modules. #3642

Open masx200 opened 1 year ago

masx200 commented 1 year ago

Xmake Version

v2.7.8+dev.f11dad73c

Operating System Version and Architecture

Microsoft Windows [版本 10.0.22621.1555] amd64

Describe Bug

https://github.com/masx200/leetcode-treenode-cpp/blob/3e7a8646da1471b7ccd17018bbe317210b7bdd99/CMakeLists.txt#L11

CMake Error at CMakeLists.txt:11 (add_library):
  No SOURCES given to target: leetcode-treenode-cpp

Expected Behavior

clion应该正常识别文件

Project Configuration

set_version("1.1.4")
add_rules("mode.debug", "mode.release")
add_requires("vcpkg::cppunit")
set_languages("c17", "cxx20")
set_project("leetcode-treenode-cpp")
target("leetcode-treenode-cpp")
-- set_toolchains("msvc","clang")
set_kind("static")
-- add_files("*.cpp")
add_files("*.ixx","*.mpp")
-- add_packages("vcpkg::cppunit")
target_end()
target("test")
-- set_toolchains("msvc","clang")
set_kind("binary")
add_files("*.cpp")
-- add_files("*.ixx")
add_packages("vcpkg::cppunit")
add_deps("leetcode-treenode-cpp")
target_end()
--
-- If you want to known more usage about xmake, please see https://xmake.io
--
-- ## FAQ
--
-- You can enter the project directory firstly before building project.
--
--   $ cd projectdir
--
-- 1. How to build project?
--
--   $ xmake
--
-- 2. How to configure project?
--
--   $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
--
-- 3. Where is the build output directory?
--
--   The default output directory is `./build` and you can configure the output directory.
--
--   $ xmake f -o outputdir
--   $ xmake
--
-- 4. How to run and debug target after building project?
--
--   $ xmake run [targetname]
--   $ xmake run -d [targetname]
--
-- 5. How to install target to the system directory or other output directory?
--
--   $ xmake install
--   $ xmake install -o installdir
--
-- 6. Add some frequently-used compilation flags in xmake.lua
--
-- @code
--    -- add debug and release modes
--    add_rules("mode.debug", "mode.release")
--
--    -- add macro defination
--    add_defines("NDEBUG", "_GNU_SOURCE=1")
--
--    -- set warning all as error
--    set_warnings("all", "error")
--
--    -- set language: c99, c++11
--    set_languages("c99", "c++11")
--
--    -- set optimization: none, faster, fastest, smallest
--    set_optimize("fastest")
--
--    -- add include search directories
--    add_includedirs("/usr/include", "/usr/local/include")
--
--    -- add link libraries and search directories
--    add_links("tbox")
--    add_linkdirs("/usr/local/lib", "/usr/lib")
--
--    -- add system link libraries
--    add_syslinks("z", "pthread")
--
--    -- add compilation and link flags
--    add_cxflags("-stdnolib", "-fno-strict-aliasing")
--    add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
--
-- @endcode
--

Additional Information and Error Logs

在clion里面用xmake插件自动生成的cmakelist文件

"C:\Program Files\JetBrains\CLion 2023.1.1\bin\cmake\win\x64\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2023.1.1/bin/ninja/win/x64/ninja.exe" -G Ninja -S C:\Users\Administrator\Documents\GitHub\leetcode-treenode-cpp -B C:\Users\Administrator\Documents\GitHub\leetcode-treenode-cpp\cmake-build-debug
-- Configuring done
CMake Error at CMakeLists.txt:11 (add_library):
  No SOURCES given to target: leetcode-treenode-cpp

CMake Generate step failed.  Build files cannot be regenerated correctly.

[先前的 CMake 输出已还原: 2023/4/18 10:43]
waruqi commented 1 year ago

你调下那个 cmakelists 。看哪里不对,

masx200 commented 1 year ago

CMakeLists.txt

# this is the build file for project leetcode-treenode-cpp
# it is autogenerated by the xmake build system.
# do not edit by hand.

# project
cmake_minimum_required(VERSION 3.15.0)
cmake_policy(SET CMP0091 NEW)
project(leetcode-treenode-cpp VERSION 1.1.4 LANGUAGES CXX C)

# target
add_library(leetcode-treenode-cpp STATIC "")
set_target_properties(leetcode-treenode-cpp PROPERTIES OUTPUT_NAME "leetcode-treenode-cpp")
set_target_properties(leetcode-treenode-cpp PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/windows/x86/release")
add_custom_command(OUTPUT output_leetcode-treenode-cpp_BEE6E6CE
    COMMAND echo [  0%]: compiling.module.release leetcode_treenode_cpp.TreeNode
    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release
    COMMAND "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/HostX86/x86/cl.exe" -nologo -O2 -fp:fast -std:c++20 /EHsc -experimental:module -DNDEBUG -TP -c ${CMAKE_SOURCE_DIR}/TreeNode.ixx -Fo${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/TreeNode.ixx.obj -ifcOutput ${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.TreeNode.ifc -interface
    COMMAND echo [  0%]: compiling.module.release leetcode_treenode_cpp.traversalTreeNode
    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release
    COMMAND "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/HostX86/x86/cl.exe" -nologo -O2 -fp:fast -std:c++20 /EHsc -experimental:module -DNDEBUG -TP -c ${CMAKE_SOURCE_DIR}/traversalTreeNode.ixx -Fo${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/traversalTreeNode.ixx.obj -ifcOutput ${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.traversalTreeNode.ifc -interface -reference leetcode_treenode_cpp.TreeNode=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.TreeNode.ifc
    COMMAND echo [  0%]: compiling.module.release leetcode_treenode_cpp.serializeTreeNode
    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release
    COMMAND "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/HostX86/x86/cl.exe" -nologo -O2 -fp:fast -std:c++20 /EHsc -experimental:module -DNDEBUG -TP -c ${CMAKE_SOURCE_DIR}/serializeTreeNode.ixx -Fo${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/serializeTreeNode.ixx.obj -ifcOutput ${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.serializeTreeNode.ifc -interface -reference leetcode_treenode_cpp.TreeNode=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.TreeNode.ifc
    COMMAND echo [  0%]: compiling.module.release leetcode_treenode_cpp.freeTreeNode
    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release
    COMMAND "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/HostX86/x86/cl.exe" -nologo -O2 -fp:fast -std:c++20 /EHsc -experimental:module -DNDEBUG -TP -c ${CMAKE_SOURCE_DIR}/freeTreeNode.ixx -Fo${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/freeTreeNode.ixx.obj -ifcOutput ${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.freeTreeNode.ifc -interface -reference leetcode_treenode_cpp.TreeNode=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.TreeNode.ifc
    COMMAND echo [  0%]: compiling.module.release leetcode_treenode_cpp.parseLeetCodeBinaryTree
    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release
    COMMAND "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/HostX86/x86/cl.exe" -nologo -O2 -fp:fast -std:c++20 /EHsc -experimental:module -DNDEBUG -TP -c ${CMAKE_SOURCE_DIR}/parseLeetCodeBinaryTree.ixx -Fo${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/parseLeetCodeBinaryTree.ixx.obj -ifcOutput ${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.parseLeetCodeBinaryTree.ifc -interface -reference leetcode_treenode_cpp.TreeNode=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.TreeNode.ifc -reference leetcode_treenode_cpp.freeTreeNode=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.freeTreeNode.ifc
    COMMAND echo [  0%]: compiling.module.release leetcode_treenode_cpp.bfsTravelsal
    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release
    COMMAND "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/HostX86/x86/cl.exe" -nologo -O2 -fp:fast -std:c++20 /EHsc -experimental:module -DNDEBUG -TP -c ${CMAKE_SOURCE_DIR}/bfsTravelsal.ixx -Fo${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/bfsTravelsal.ixx.obj -ifcOutput ${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.bfsTravelsal.ifc -interface -reference leetcode_treenode_cpp.TreeNode=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.TreeNode.ifc
    COMMAND echo [  0%]: compiling.module.release leetcode_treenode_cpp.LeetCodeTreeNodeToString
    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release
    COMMAND "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/HostX86/x86/cl.exe" -nologo -O2 -fp:fast -std:c++20 /EHsc -experimental:module -DNDEBUG -TP -c ${CMAKE_SOURCE_DIR}/LeetCodeTreeNodeToString.mpp -Fo${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/LeetCodeTreeNodeToString.mpp.obj -ifcOutput ${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.LeetCodeTreeNodeToString.ifc -interface -reference leetcode_treenode_cpp.TreeNode=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.TreeNode.ifc -reference leetcode_treenode_cpp.bfsTravelsal=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.bfsTravelsal.ifc
    VERBATIM
)
add_custom_target(target_leetcode-treenode-cpp_BEE6E6CE
    DEPENDS output_leetcode-treenode-cpp_BEE6E6CE
)
add_dependencies(leetcode-treenode-cpp target_leetcode-treenode-cpp_BEE6E6CE)
target_compile_options(leetcode-treenode-cpp PRIVATE
    $<$<COMPILE_LANGUAGE:C>:-DNDEBUG>
    $<$<COMPILE_LANGUAGE:CXX>:-DNDEBUG>
    $<$<COMPILE_LANGUAGE:CXX>:-experimental:module>
)
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
    target_compile_options(leetcode-treenode-cpp PRIVATE /EHsc)
else()
    target_compile_options(leetcode-treenode-cpp PRIVATE -fcxx-exceptions)
endif()
set_target_properties(leetcode-treenode-cpp PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(leetcode-treenode-cpp PRIVATE cxx_std_20)
if(MSVC)
    target_compile_options(leetcode-treenode-cpp PRIVATE $<$<CONFIG:Release>:-Ox -fp:fast>)
else()
    target_compile_options(leetcode-treenode-cpp PRIVATE -O3)
endif()
if(MSVC)
else()
    target_compile_options(leetcode-treenode-cpp PRIVATE -fvisibility=hidden)
endif()
if(MSVC)
    set_property(TARGET leetcode-treenode-cpp PROPERTY
        MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
target_link_libraries(leetcode-treenode-cpp PRIVATE
    ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/bfsTravelsal.ixx.obj
    ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/freeTreeNode.ixx.obj
    ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/parseLeetCodeBinaryTree.ixx.obj
    ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/serializeTreeNode.ixx.obj
    ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/traversalTreeNode.ixx.obj
    ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/TreeNode.ixx.obj
    ${CMAKE_SOURCE_DIR}/build/.objs/leetcode-treenode-cpp/windows/x86/release/LeetCodeTreeNodeToString.mpp.obj
)
target_sources(leetcode-treenode-cpp PRIVATE
)

# target
add_executable(test "")
set_target_properties(test PROPERTIES OUTPUT_NAME "test")
set_target_properties(test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/windows/x86/release")
add_dependencies(test leetcode-treenode-cpp)
target_include_directories(test PRIVATE
    C:/Users/Administrator/Documents/vcpkg-master/installed/x86-windows-static/include
)
target_compile_options(test PRIVATE
    $<$<COMPILE_LANGUAGE:C>:-DNDEBUG>
    $<$<COMPILE_LANGUAGE:CXX>:-DNDEBUG>
    $<$<COMPILE_LANGUAGE:CXX>:-experimental:module>
)
set_source_files_properties(${CMAKE_SOURCE_DIR}/test.cpp PROPERTIES COMPILE_OPTIONS
    "$<$<COMPILE_LANGUAGE:CXX>:-TP>;$<$<COMPILE_LANGUAGE:CXX>:-c>;$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/test.cpp>;$<$<COMPILE_LANGUAGE:CXX>:-Fo${CMAKE_SOURCE_DIR}/build/.objs/test/windows/x86/release/test.cpp.obj>;$<$<COMPILE_LANGUAGE:CXX>:-reference>;$<$<COMPILE_LANGUAGE:CXX>:leetcode_treenode_cpp.LeetCodeTreeNodeToString=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.LeetCodeTreeNodeToString.ifc>;$<$<COMPILE_LANGUAGE:CXX>:-reference>;$<$<COMPILE_LANGUAGE:CXX>:leetcode_treenode_cpp.TreeNode=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.TreeNode.ifc>;$<$<COMPILE_LANGUAGE:CXX>:-reference>;$<$<COMPILE_LANGUAGE:CXX>:leetcode_treenode_cpp.bfsTravelsal=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.bfsTravelsal.ifc>;$<$<COMPILE_LANGUAGE:CXX>:-reference>;$<$<COMPILE_LANGUAGE:CXX>:leetcode_treenode_cpp.freeTreeNode=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.freeTreeNode.ifc>;$<$<COMPILE_LANGUAGE:CXX>:-reference>;$<$<COMPILE_LANGUAGE:CXX>:leetcode_treenode_cpp.parseLeetCodeBinaryTree=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.parseLeetCodeBinaryTree.ifc>;$<$<COMPILE_LANGUAGE:CXX>:-reference>;$<$<COMPILE_LANGUAGE:CXX>:leetcode_treenode_cpp.serializeTreeNode=${CMAKE_SOURCE_DIR}/build/.gens/leetcode-treenode-cpp/windows/x86/release/rules/modules/cache/ec4a91a6/leetcode_treenode_cpp.serializeTreeNode.ifc>"
)
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
    target_compile_options(test PRIVATE /EHsc)
else()
    target_compile_options(test PRIVATE -fcxx-exceptions)
endif()
set_target_properties(test PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(test PRIVATE cxx_std_20)
if(MSVC)
    target_compile_options(test PRIVATE $<$<CONFIG:Release>:-Ox -fp:fast>)
else()
    target_compile_options(test PRIVATE -O3)
endif()
if(MSVC)
else()
    target_compile_options(test PRIVATE -fvisibility=hidden)
endif()
if(MSVC)
    set_property(TARGET test PROPERTY
        MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
target_link_libraries(test PRIVATE
    cppunit
    leetcode-treenode-cpp
)
target_link_directories(test PRIVATE
    C:/Users/Administrator/Documents/vcpkg-master/installed/x86-windows-static/lib
    build/windows/x86/release
)
target_sources(test PRIVATE
    test.cpp
)
waruqi commented 1 year ago

你先自己分析下生成的 cmakelists.txt 看看哪里有问题。

masx200 commented 1 year ago

我知道问题在哪了,

add_library(leetcode-treenode-cpp STATIC "" TreeNode.ixx test.cpp LeetCodeTreeNodeToString.mpp bfsTravelsal.ixx freeTreeNode.ixx)

是xmake这里没有自动生成需要添加到这个target的文件,手动添加之后就可以了,但是能自动添加更好

waruqi commented 1 year ago

target_sources(leetcode-treenode-cpp PRIVATE )

是这里空的,因为现在 project generator 对 c++20 modules 还没怎么支持。暂时不要去生成带 c++ modules 的 cmakelists

pwqbot commented 1 year ago

target_sources(leetcode-treenode-cpp PRIVATE )

是这里空的,因为现在 project generator 对 c++20 modules 还没怎么支持。暂时不要去生成带 c++ modules 的 cmakelists

对 compile_commands.json 和 makefile 的生成目前也是不支持的吗?

waruqi commented 1 year ago

不支持 只能直接构建

pwqbot commented 1 year ago

不支持 只能直接构建

目前不支持是因为理论上不可行还是只是暂时没有实现?

waruqi commented 1 year ago

不支持 只能直接构建

目前不支持是因为理论上不可行还是只是暂时没有实现?

暂时没实现,xmake 主要以直接构建为主,project generator 只是作为额外提供的插件,不是重点。。有时间会陆续改进,但要看个人时间和精力,有优先处理维护其他的特性和问题

pwqbot commented 1 year ago

好的,非常感谢!因为 xmake对module的支持比较全面我正在尝试从 cmake 迁移过来,但是不能生成正确的 compile_commands.json 的话 lsp 就无法工作,无法进行日常开发,我觉得这应该是很多人都会遇到的问题?不知道其他使用xmake module的人如何解决这个问题

waruqi commented 1 year ago

好的,非常感谢!因为 xmake对module的支持比较全面我正在尝试从 cmake 迁移过来,但是不能生成正确的 compile_commands.json 的话 lsp 就无法工作,无法进行日常开发,我觉得这应该是很多人都会遇到的问题?不知道其他使用xmake module的人如何解决这个问题

首先各家编译器对 c++modules 支持都是不完善的,也就 msvc 勉强可用(但还是有很多的坑和bug),按现在的支持力度,玩玩可以,想用这个去做日常开发,原本就不建议。。不管是编译器支持,配套设施,模块分发,intellisense,ide 支持等都很不完善。趟坑是难免的。。

想要完全日常可用,且跨平台稳定,至少再等几年。我就没见过几个拿这个放进正式项目里面用的,如果还要支持 gcc/clang 的更少了。

xmake 目前只对编译器直接构建,尽可能做到了跨平台可用,并且内部处理了各家编译器可能遇到的一些坑和兼容性问题。

模块分发初步支持,基本可用,但是对 IDE, intellisense 支持暂时还没时间搞。

pwqbot commented 1 year ago

好的,非常感谢!因为 xmake 对 module 的支持比较全面我正在尝试从 cmake 迁移过来,但是不能生成正确的 compile_commands.json 的话 lsp 就无法工作,无法进行日常开发,我觉得这应该是很多人都会遇到的问题?不知道其他使用 xmake module 的人如何解决这个问题

首先各家编译器对 c++modules 支持都是不完善的,也就 msvc 勉强可用(但还是有很多的坑和 bug),按现在的支持力度,玩玩可以,想用这个去做日常开发,原本就不建议。。不管是编译器支持,配套设施,模块分发,intellisense,ide 支持等都很不完善。趟坑是难免的。。

想要完全日常可用,且跨平台稳定,至少再等几年。我就没见过几个拿这个放进正式项目里面用的,如果还要支持 gcc/clang 的更少了。

xmake 目前只对编译器直接构建,尽可能做到了跨平台可用,并且内部处理了各家编译器可能遇到的一些坑和兼容性问题。

模块分发初步支持,基本可用,但是对 IDE, intellisense 支持暂时还没时间搞。

感谢指导!不过module 带来的好处还是十分吸引人的,后面等支持更完善了再来尝试下。

1821746019 commented 1 year ago

Clion对模块的智能提示就不错,visual studio加上resharper c++后也还行.模块特性用起来又爽,再加上第四代构建系统简直无敌了好吧. 望作者大大可以投入更多的精力完善对c++模块特性以及IDE的支持.c++的模块真的需要一个简洁又强大的构建系统.

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


Clion's intelligent prompts for modules are good, and visual studio plus resharper c++ is also okay. The module features are cool to use, and the fourth-generation build system is simply invincible. I hope the author can put more effort into improving the features of c++ modules and IDE support. C++ modules really need a simple and powerful build system.

waruqi commented 1 year ago

生成 compile_commands 目前支持 c++20 modules ,原本就可以用。。clion 的插件没精力维护,建议用 vscode + clangd

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


Generating compile_commands currently supports c++20 modules, which should work natively. . The plugin of clion has no energy to maintain, it is recommended to use vscode

1821746019 commented 1 year ago

确实可以正常编译运行+调试,但是clion的智能提示似乎作废 确实可用,但是clion的智能提示似乎无法使用 难道是我配置不当?我参考的是(笔记)如何在 CLion 上调试编译 xmake 项目 - 哔哩哔哩 (bilibili.com)

xmake.lua如下:

set_project("tmp")
add_rules("mode.debug", "mode.release")

target("tmp")
    set_kind("binary")
    add_files("src/*.cpp")
    add_files("src/*.ixx")

xmake project -k compile_commands生成的json如下

[
{
  "directory": "F:\\Users\\Administrator\\Desktop\\CLion_code\\~xmake\\tmp",
  "arguments": ["D:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.36.32532\\bin\\HostX64\\x64\\cl.exe", "/nologo", "/Zi", "/FS", "/Fdbuild\\windows\\x64\\debug\\compile.tmp.pdb", "/Od", "/EHsc", "/experimental:module", "/TP", "/c", "src\\test.ixx", "/Fobuild\\.objs\\tmp\\windows\\x64\\debug\\src\\test.ixx.obj", "/ifcOutput", "build\\.gens\\tmp\\windows\\x64\\debug\\rules\\modules\\cache\\b47db9d3\\test.ifc", "/interface"],
  "file": "src\\test.ixx"
},
{
  "directory": "F:\\Users\\Administrator\\Desktop\\CLion_code\\~xmake\\tmp",
  "arguments": ["D:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.36.32532\\bin\\HostX64\\x64\\cl.exe", "/c", "/nologo", "/Zi", "/FS", "/Fdbuild\\windows\\x64\\debug\\compile.tmp.pdb", "/Od", "/EHsc", "/experimental:module", "/TP", "/c", "/reference", "test=build\\.gens\\tmp\\windows\\x64\\debug\\rules\\modules\\cache\\b47db9d3\\test.ifc", "/Fobuild\\.objs\\tmp\\windows\\x64\\debug\\src\\main.cpp.obj", "src\\main.cpp"],
  "file": "src\\main.cpp"
}]
Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


It is indeed possible to compile and run + debug normally, but the smart prompt of clion seems to be unavailable It does work, but clion's intellisense doesn't seem to work Could it be that my configuration is improper? I refer to (Notes) How to debug and compile xmake projects on CLion - 哔哩哔哩 (bilibili.com)

xmake.lua is as follows:

[
{
  "directory": "F:\\Users\\Administrator\\Desktop\\CLion_code\\~xmake\\tmp",
  "arguments": ["D:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.36.32532\\bin\\HostX64\\x64\\cl. exe", "/nologo", "/Zi", "/FS", "/Fdbuild\\windows\\x64\\debug\\compile.tmp.pdb", "/Od", "/EHsc", " /experimental:module", "/TP", "/c", "src\\test.ixx", "/Fobuild\\.objs\\tmp\\windows\\x64\\debug\\src\\test .ixx.obj", "/ifcOutput", "build\\.gens\\tmp\\windows\\x64\\debug\\rules\\modules\\cache\\b47db9d3\\test.ifc", "/ interface"],
  "file": "src\\test.ixx"
},
{
  "directory": "F:\\Users\\Administrator\\Desktop\\CLion_code\\~xmake\\tmp",
  "arguments": ["D:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.36.32532\\bin\\HostX64\\x64\\cl. exe", "/c", "/nologo", "/Zi", "/FS", "/Fdbuild\\windows\\x64\\debug\\compile.tmp.pdb", "/Od", " /EHsc", "/experimental:module", "/TP", "/c", "/reference", "test=build\\.gens\\tmp\\windows\\x64\\debug\\rules\ \modules\\cache\\b47db9d3\\test.ifc", "/Fobuild\\.objs\\tmp\\windows\\x64\\debug\\src\\main.cpp.obj", "src\\ main.cpp"],
  "file": "src\\main.cpp"
}]
1821746019 commented 1 year ago

生成 compile_commands 目前支持 c++20 modules ,原本就可以用。。clion 的插件没精力维护,建议用 vscode + clangd

这么说,xmake对vscode的官方支持是最好的吗?最爱JetBrains家的智能提示了,clangd不知道怎么样.

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


Generate compile_commands currently supports c++20 modules, which can be used natively. . The clion plugin has no energy to maintain, it is recommended to use vscode + clangd

So, is xmake's official support for vscode the best? I love JetBrains' smart tips, but clangd doesn't know how.

1821746019 commented 1 year ago

忘记把test.ixx贴上去了.png 忘记把test ixx贴上去了

1821746019 commented 1 year ago

我的错,忘记set_languages("cxx20")了...

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


My fault, forgot about set_languages("cxx20")...

waruqi commented 1 year ago

难道是我配置不当?我参考的是(笔记)如何在 CLion 上调试编译 xmake 项目 - 哔哩哔哩 (bilibili.com)

不是官方视频,这边 intellisense 从没支持过 clion

xmake 生成的 compile_commands 肯定支持 c++20 modules

但是能否让 clion 支持上,怎么配置上,不归这边管。。你自己研究。。

目前能确定的就是 clangd 是支持 c++20 modules 的 compile_commands,并且其他人在 vscode 上配置使用成功过。

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


Is my configuration wrong? I refer to (notes) How to debug and compile xmake project on CLion - 哔哩哔哩 (bilibili.com)

Not an official video, intellisense has never supported clion here

The compile_commands generated by xmake definitely support c++20 modules

But whether clion can support it or how to configure it is not under the control of this side. . Do your own research. .

What can be determined at present is that clangd supports compile_commands of c++20 modules, and others have successfully configured and used it on vscode.

1821746019 commented 1 year ago

还是会有小问题,看来我最好还是向CLion官方反馈看看能不能像支持CMake那样直接原生支持XMake,或者直接跑路Rust,苦c++已久... 但是发现了另外一个问题

waruqi commented 9 months ago

现在增加了 cmake 对原生 c++ modules 的支持。https://github.com/xmake-io/xmake/pull/4746

1821746019 commented 9 months ago

现在增加了 cmake 对原生 c++ modules 的支持。#4746

那大佬啥时候有空顺便把预编译头和模块冲突的问题解决了

Issues-translate-bot commented 9 months ago

Bot detected the issue body's language is not English, translate it automatically.


Now adds cmake support for native c++ modules. #4746

When will the boss have time to solve the problem of conflicts between precompiled headers and modules?

waruqi commented 9 months ago

现在增加了 cmake 对原生 c++ modules 的支持。#4746

那大佬啥时候有空顺便把预编译头和模块冲突的问题解决了

看时间,最近估计没空

Issues-translate-bot commented 9 months ago

Bot detected the issue body's language is not English, translate it automatically.


cmake support for native c++ modules is now added. #4746

When will the boss have time to solve the problem of conflicts between precompiled headers and modules?

Look at the time, I guess I won’t be free recently

whisper-bye commented 1 day ago

环境 windows clion vs2022 preview cmake 3.31.0

看起来xmake-ide不直接支持debug,而是生成cmake然后调试。 但是生成的CMakeLists.txt无法使用import std error C2230: could not find module 'std' 看起来是找不到std.ixx,如果能copy过去也许就行了。 以上的理解正确吗?

import std in CMake 3.30 在 CMake 3.30 中导入 std https://www.kitware.com/import-std-in-cmake-3-30/

https://github.com/microsoft/STL/issues/3195#issuecomment-1770283053

if (MSVC)
    string(REGEX REPLACE "\/bin\/Hostx(64|86)\/x(64|86)\/cl\.exe" "" MSVC_ROOT ${CMAKE_CXX_COMPILER})
    configure_file("${MSVC_ROOT}/modules/std.ixx" "${PROJECT_BINARY_DIR}/std.ixx" COPYONLY)
    configure_file("${MSVC_ROOT}/modules/std.compat.ixx" "${PROJECT_BINARY_DIR}/std.compat.ixx" COPYONLY)
endif ()

感觉这个很关键,是一个最后一英里问题,跑通就能很舒服的在clion下配合xmake玩c++ modules

waruqi commented 1 day ago

可以直接提 pr过来

Issues-translate-bot commented 1 day ago

Bot detected the issue body's language is not English, translate it automatically.


You can bring it up directly and trick people into coming over.