gpt4 book ai didi

visual-studio - 在 CMake 中为 3rd 方库设置解决方案文件夹属性

转载 作者:行者123 更新时间:2023-12-04 03:31:47 27 4
gpt4 key购买 nike

我的项目依赖于一个大型的 3rd 方库 (OpenMVG)。
目前没有安装。官方搭建说明推荐使用 add_subdirectory .

因此我的 CMakeLists.txt包含以下几行

add_subdirectory(${OpenMVG_DIR}/src "${CMAKE_BINARY_DIR}/openMVG")
include_directories(${OpenMVG_INCLUDES})
add_executable(f_matching f_matching.cpp)
target_link_libraries(f_matching ${OpenMVG_LIBS})

我的平台是Visual Studio,生成的解决方案在顶层包含72个项目。我想用 FOLDER CMake 属性将其组织在层次结构中。例如,我想将所有 OpenMVG 的项目移动到单独的 VS 解决方案文件夹中。

但是,正如 CMake 文档所说,此属性只能分配给目标,而不能分配给目录。
我的 CMakeLists.txt包含
set_property(DIRECTORY ${OpenMVG_DIR}/src PROPERTY FOLDER OpenMVG)

但这一行什么都不做,没有解决方案文件夹出现。
我尝试通过设置 FOLDER 来修改几个 OpenMVG 的 CMakeLists。目标上的属性(property),这有效。

在不从 OpenMVG 更改 CMakeLists 的情况下,是否有针对这种情况的解决方法?
目前,我想把时间花在其他任务上,把这个简单的编辑推迟到以后。

最佳答案

有一个“黑客”可以实现您的目标。 'add_library' 的原始版本带有下划线前缀,因此您可以通过这种方式重新实现顶级 'add_library' 函数:

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# you need it to properly set variable from function() call
set(target_list "" CACHE INTERNAL "target_list")
function(add_library name)
message("Adding library ${name}")
set(target_list ${target_list} ${name} CACHE INTERNAL "target_list")
_add_library(${name} ${ARGN})
endfunction()

# Your add_subdirectory() goes here

set_target_properties(${target_list} PROPERTIES FOLDER "OpenMVG")

当然,据我所知,它没有记录,也不是官方的,但它有效,至少现在使用 CMake 2.8.12.2。

关于visual-studio - 在 CMake 中为 3rd 方库设置解决方案文件夹属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25782256/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com