CMake:文件在子目录中的Globbing

时间:2013-03-19 09:51:03

标签: cmake

我想在CMake中添加一个安装指令(即:我希望make install做正确的事)来谷歌模拟和谷歌测试框架,因为我需要它们进行交叉编译。

由于这是一个外部库,我希望保持更改而不是非反转。 是否有可能在不使用GLOB_RECURSE的情况下让CMake File Globbing工作到glob子目录?

我遇到的gtest的问题是,如果我以递归的形式表示,包含/ gtest / interal会被我定义的函数弄平。因此,目录中的文件包括/ 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})

1 个答案:

答案 0 :(得分:3)

将我的评论转化为答案。

我相信你应该能够达到你想要的install(DIRECTORY ...)

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
)

我不熟悉gtest目录结构;以上假设标题位于includeinclude/gtest/internal中。如果您感兴趣的标题位于include/gtestinclude/gtest/internal,则可以将gtest添加到第一个目录名称,并删除EXCLUDE模式和第二个install命令。