xmake-io / xmake

šŸ”„ A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.14k stars 782 forks source link

Generated Cmakelists file seems to be wrong when you use conditional add_files() #5476

Closed Glacia closed 3 months ago

Glacia commented 3 months ago

Xmake Version

2.9.4

Operating System Version and Architecture

Windows 10 22H2

Describe Bug

I use xmake project -k cmakelists command to generate cmake file for IDE, but if i use conditional add_files in xmake file then the generated cmake file doesn't have conditionally added files. Actual compilation is working as intended.

Expected Behavior

Cmake file should contain conditionally added sources.

Project Configuration

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

option("GUI")
    set_default(false)
    set_showmenu(true)
    set_category("Application type")
    add_defines("GUI")

option("Console")
    set_default(true)
    set_showmenu(true)
    set_category("Application type")
    add_defines("CONSOLE")

target("elib")
    set_kind("static")
    set_options("GUI", "Console")

    if is_config("GUI") then
        add_files("src/windows/*.c")
    elseif is_config("Console") then
        add_files("src/console/*.c")
    end

    add_files("src/*.c")

Additional Information and Error Logs

Generated cmake file:

# project
cmake_minimum_required(VERSION 3.15.0)
cmake_policy(SET CMP0091 NEW)
project(elib LANGUAGES C)

# target
add_library(elib STATIC "")
set_target_properties(elib PROPERTIES OUTPUT_NAME "elib")
set_target_properties(elib PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/windows/x64/debug")
target_compile_definitions(elib PRIVATE
    CONSOLE
)
set_target_properties(elib PROPERTIES C_EXTENSIONS OFF)
target_compile_features(elib PRIVATE c_std_99)
if(MSVC)
    target_compile_options(elib PRIVATE $<$<CONFIG:Debug>:-Od>)
else()
    target_compile_options(elib PRIVATE -O0)
endif()
if(MSVC)
    target_compile_options(elib PRIVATE -Zi)
else()
    target_compile_options(elib PRIVATE -g)
endif()
if(MSVC)
    set_property(TARGET elib PROPERTY
        MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
target_sources(elib PRIVATE
# Source files should be here
)
waruqi commented 3 months ago

use has_config instead of is_config

Glacia commented 3 months ago

Yeah, that worked. Thanks! Sorry for bothering. Really appreciate your work, xmake is awesome.