3

我想在 CMake 中向 google mock 和 google test 框架添加一个安装指令(即:我想做make install正确的事情),因为我需要交叉编译它们。

由于这是一个外部库,我想保持更改而不是逆向。是否有可能让 CMake File Globbing 在不使用的情况下对子目录进行 glob GLOB_RECURSE

我遇到的 gtest 问题是如果我递归地使用我定义的函数,include/gtest/interal 会被压扁。因此目录中的文件 include/gtest/internal 被安装${prefix}/include/gtest${prefix}/include/gtest/internal

如果可能的话,我不想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})
4

1 回答 1

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 目录结构;以上假设标题位于 ininclude和 in 中include/gtest/internal。如果您感兴趣的标头位于include/gtestand include/gtest/internal,您可以添加gtest到第一个目录名称,并摆脱EXCLUDE模式和第二个install命令。

于 2013-03-19T13:42:03.437 回答