【问题标题】:Set a target VS_GLOBAL property that applies to all targets using CMake使用 CMake 设置适用于所有目标的目标 VS_GLOBAL 属性
【发布时间】:2021-03-26 19:38:42
【问题描述】:

我想设置一个适用于 CMake 项目中所有目标的目标属性。具体来说,我想在 Visual Studio 中禁用 vcpkg 集成。我可以通过以下方式逐个目标地做到这一点:

set_target_properties(${mytarget} PROPERTIES VS_GLOBAL_VcpkgEnabled FALSE)

但我不知道如何为所有目标全局设置。

【问题讨论】:

    标签: visual-studio cmake vcpkg


    【解决方案1】:

    我偶然发现了一个类似的问题。我发现的解决方案涉及将属性设置为所有目标。

    function(get_all_targets var)
        set(targets)
        get_all_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR})
        set(${var} ${targets} PARENT_SCOPE)
    endfunction()
    macro(get_all_targets_recursive targets dir)
        get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
        foreach(subdir ${subdirectories})
            get_all_targets_recursive(${targets} ${subdir})
        endforeach()
    
        get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
        list(APPEND ${targets} ${current_targets})
    endmacro()
    
    set_target_properties(${all_targets} PROPERTIES VS_GLOBAL_VcpkgEnabled false)
    

    基于此资源:https://newbedev.com/how-do-i-iterate-over-all-cmake-targets-programmatically

    【讨论】:

      猜你喜欢
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      • 2022-08-18
      • 2015-11-17
      • 1970-01-01
      • 2018-01-03
      相关资源
      最近更新 更多