CMake:子目录中的文件全局绑定
我想在CMake中的google mock和google测试框架中添加一个安装指令(即:我想让CMake:子目录中的文件全局绑定,cmake,Cmake,我想在CMake中的google mock和google测试框架中添加一个安装指令(即:我想让让install做正确的事情),因为我需要交叉编译它们 因为这是一个外部库,所以我希望保持更改不是反向的。 是否有可能让CMake File Globbing在不使用glob_RECURSE的情况下工作到glob a子目录 我在使用gtest时遇到的问题是,如果我递归地全局化,include/gtest/interal就会被我定义的函数压扁。因此,目录中的文件include/gtest/internal
让install
做正确的事情),因为我需要交叉编译它们
因为这是一个外部库,所以我希望保持更改不是反向的。
是否有可能让CMake File Globbing在不使用glob_RECURSE
的情况下工作到glob a子目录
我在使用gtest时遇到的问题是,如果我递归地全局化,include/gtest/interal就会被我定义的函数压扁。因此,目录中的文件include/gtest/internal被安装到${prefix}/include/gtest
而不是${prefix}/include/gtest/internal
如果可能,我不想在include目录中添加CMakeLists.txt
文件
function(install_header dest_dir)
foreach(header ${ARGN})
install(FILES include/${header}
DESTINATION include/google/${dest_dir}
)
endforeach()
endfunction()
# doesn't work with GLOB
# but works with GLOB_RECURSE -- however copies more than intended
file(GLOB headers RELATIVE ${gtest_SOURCE_DIR}/include/ *.h.pump *.h )
file(GLOB internalheaders RELATIVE ${gtest_SOURCE_DIR}/include/gtest/internal/ *.h.pump *.h )
if(NOT headers)
message(FATAL_ERROR "headers not found")
endif()
if(NOT internalheaders)
message(FATAL_ERROR "headers not found")
endif()
install_header(gtest ${headers})
install_header(gtest/internal ${internalheaders})
把我的评论变成答案 我相信您应该能够通过
安装(目录…
)实现您的目标:
我不熟悉gtest目录结构;以上假设标题位于
include
和include/gtest/internal
中。如果您感兴趣的标题位于include/gtest
和include/gtest/internal
中,您可以将gtest
添加到第一个目录名中,并去掉EXCLUDE
模式和第二个install
命令。您考虑过install(目录…文件匹配…)
?@Angew哦,亲爱的。我一定是瞎了。这看起来比什么都少。不幸的是,这对我一点帮助都没有。因为zip文件是签入的,而不是源文件。实现补丁程序比以其他方式安装10个头文件更昂贵。。
install(
DIRECTORY ${gtest_SOURCE_DIR}/include/ #notice trailing slash - will not append "include" to destination
DESTINATION include/google/gtest
FILES_MATCHING PATTERN "*.h.pump" PATTERN "*.h" # install only files matching a pattern
PATTERN REGEX "/internal/" EXCLUDE # ignore files matching this pattern (will be installed separately)
)
install(
DIRECTORY ${gtest_SOURCE_DIR}/include/gtest/internal #notice no trailing slash - "internal" will be appended to destination
DESTINATION include/google/gtest
FILES_MATCHING PATTERN "*.h.pump" PATTERN "*.h" # install only files matching a pattern
)