xmake-io / xmake

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

xmake 生成 cmakelists 错误 #5490

Closed PolarLinda6 closed 1 month ago

PolarLinda6 commented 1 month ago

Xmake 版本

2.9.4

操作系统版本和架构

Windows 11 version 23H2

描述问题

xmake project -k cmakelists 生成的 cmakelists 存在一些问题

  1. 对 msvc 引入 -m64 参数与 stdlibc++ 标准库
  2. 在引入 release debug 多种 mode 情况下, 只生成了一种
  3. add_files("Src/*.cpp") add_headerfiles("Include/*.hpp") 未生成 * 收集文件

期待的结果

if(MSVC)
    target_compile_options(Main PRIVATE /W4)
    target_compile_options(Main PRIVATE /WX)
end

if(Gcc)
    set_property(TARGET Main PROPERTY GCC_RUNTIME_LIBRARY "stdc++_static")
elseif(Clang)
    set_property(TARGET Main PROPERTY CLANG_RUNTIME_LIBRARY "c++_static")
end

add_executable(${PROJECT_NAME})
file(GLOB SOURCE_FILES Src/*.cpp)
file(GLOB HEADER_FILES Include/*.hpp)
target_sources(${PROJECT_NAME} PRIVATE ${SOURCE_FILES} ${HEADER_FILES})

工程配置

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

if is_config("toolchain", "clang") then
  set_runtimes("c++_shared")
elseif is_config("toolchain", "gcc") then
  set_runtimes("stdc++_static")
end

add_files("Src/*.cpp")
add_headerfiles("Include/*.hpp")

xmake.lua.txt

附加信息和错误日志

image image image

CMakeLists.txt

Issues-translate-bot commented 1 month ago

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


Title: xmake generates cmakelists errors

waruqi commented 1 month ago

对 msvc 引入 -m64 参数与 stdlibc++ 标准库 add_files("Src/.cpp") add_headerfiles("Include/.hpp") 未生成 * 收集文件

无法复现,这边 ok

# this is the build file for project 
# 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(test91 LANGUAGES CXX)

# target
add_executable(test91 "")
set_target_properties(test91 PROPERTIES OUTPUT_NAME "test91")
set_target_properties(test91 PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/windows/x64/release")
target_compile_options(test91 PRIVATE
    $<$<COMPILE_LANGUAGE:C>:-DNDEBUG>
    $<$<COMPILE_LANGUAGE:CXX>:-DNDEBUG>
)
if(MSVC)
    target_compile_options(test91 PRIVATE /EHsc)
elseif(Clang)
    target_compile_options(test91 PRIVATE -fexceptions)
    target_compile_options(test91 PRIVATE -fcxx-exceptions)
elseif(Gcc)
    target_compile_options(test91 PRIVATE -fexceptions)
endif()
if(MSVC)
    target_compile_options(test91 PRIVATE $<$<CONFIG:Release>:-O2>)
else()
    target_compile_options(test91 PRIVATE -O3)
endif()
if(MSVC)
else()
    target_compile_options(test91 PRIVATE -fvisibility=hidden)
endif()
if(MSVC)
    set_property(TARGET test91 PROPERTY
        MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
target_sources(test91 PRIVATE
    src/main.cpp
    include/test.hpp
)

if is_config("toolchain", "clang") then
  set_runtimes("c++_shared")
elseif is_config("toolchain", "gcc") then
  set_runtimes("stdc++_static")
end

target("test91")
    set_kind("binary")
    add_files("src/*.cpp")
    add_headerfiles("include/*.hpp")

在引入 release debug 多种 mode 情况下, 只生成了一种

支持不了,目前也不会考虑支持。

PolarLinda6 commented 1 month ago

我在您的 xmake.lua 中添加了 set_config("toolchain", "gcc") 复现了以上问题

PS: 我在 linux gcc 下尝试生成 cmakelists.txt 移植到 msvc 环境使用( 这可能是无法复现的原因 )

Test.zip

# this is the build file for project 
# 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)
set(CMAKE_C_COMPILER "/usr/sbin/gcc")
set(CMAKE_CXX_COMPILER "/usr/sbin/g++")
project(test91 LANGUAGES CXX)

# target
add_executable(test91 "")
set_target_properties(test91 PROPERTIES OUTPUT_NAME "test91")
set_target_properties(test91 PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/linux/x86_64/debug")
target_compile_options(test91 PRIVATE
    $<$<COMPILE_LANGUAGE:C>:-m64>
    $<$<COMPILE_LANGUAGE:CXX>:-m64>
)
if(MSVC)
    set_property(TARGET test91 PROPERTY
        MSVC_RUNTIME_LIBRARY "stdc++_static")
endif()
target_link_options(test91 PRIVATE
    -m64
)
target_sources(test91 PRIVATE
    src/main.cpp
    include/test.hpp
)
if is_config("toolchain", "clang") then
  set_runtimes("c++_shared")
elseif is_config("toolchain", "gcc") then
  set_runtimes("stdc++_static")
end

set_config("toolchain", "gcc")

target("test91")
    set_kind("binary")
    add_files("src/*.cpp")
    add_headerfiles("include/*.hpp")
waruqi commented 1 month ago

我在您的 xmake.lua 中添加了 set_config("toolchain", "gcc") 复现了以上问题 PS: 我在 linux gcc 下尝试生成 cmakelists.txt 移植到 msvc 环境使用( 这可能是无法复现的原因 )

。。。。你都用了 gcc 了,不就得加 -m64 么,有啥问题。。生成 cmakelists.txt 不支持跨平台,哪个系统上生成,就在哪个系统上用

Issues-translate-bot commented 1 month ago

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


I added set_config("toolchain", "gcc") in your xmake.lua The above problem was reproduced PS: I tried to generate cmakelists.txt under linux gcc and transplant it to msvc environment for use (this may be the reason why it cannot be reproduced)

. . . . You already use gcc, don’t you have to add -m64? What’s the problem? . Generating cmakelists.txt does not support cross-platform. It will be used on which system it is generated.