使用CMake设置适用于所有目标的目标VS_GLOBAL属性



我想设置一个适用于CMake项目中所有目标的目标属性。特别是,我想禁用Visual Studio中的vcpkg集成。我可以用以下方法逐个目标地完成:

set_target_properties(${mytarget} PROPERTIES VS_GLOBAL_VcpkgEnabled FALSE)

但我不知道如何在全球范围内设定所有目标。

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

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

相关内容

最新更新