3

尝试使用外部项目来构建谷歌测试。

   # Add googletest
ExternalProject_Add( googletest
    GIT_REPOSITORY https://github.com/google/googletest.git

    # We don't need to run update command. Takes time
    # and the version we initially d/l will shoudl be fine
    CMAKE_ARGS = "-Dgtest_disable_pthreads=1"

    # Don't run update
    UPDATE_COMMAND ""

    # Disable install step
    INSTALL_COMMAND ""

   # BUILD_BYPRODUCTS googletest-prefix/src/googletest-stamp/googletest-gitinfo.txt
   # BUILD_BYPRODUCTS googletest-prefix/tmp/googletest-cfgcmd.txt
    BUILD_BYPRODUCTS "googletest-prefix/src/googletest-build/googlemock/libgmock_main.a"
    )
# Get include dirs for googletest framework
ExternalProject_Get_Property(googletest source_dir)
set(GTEST_INCLUDE_DIRS
   ${source_dir}/googlemock/include
   ${source_dir}/googletest/include
   )

# Create library target for gmock main, which is used to create
# test executables
ExternalProject_Get_Property(googletest binary_dir)
set(GTEST_LIBRARY_PATH ${binary_dir}/googlemock/libgmock_main.a)
set(GTEST_LIBRARY gmock_main)
add_library(${GTEST_LIBRARY} UNKNOWN IMPORTED)
set_property(TARGET ${GTEST_LIBRARY} PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARY_PATH})
add_dependencies(${GTEST_LIBRARY} googletest)

使用忍者生成器,我收到以下警告。

 Policy CMP0058 is not set: Ninja requires custom command byproducts to be
  explicit.  Run "cmake --help-policy CMP0058" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  This project specifies custom command DEPENDS on files in the build tree
  that are not specified as the OUTPUT or BYPRODUCTS of any
  add_custom_command or add_custom_target:

   googletest-prefix/src/googletest-stamp/googletest-gitinfo.txt
   googletest-prefix/tmp/googletest-cfgcmd.txt

  For compatibility with versions of CMake that did not have the BYPRODUCTS
  option, CMake is generating phony rules for such files to convince 'ninja'
  to build.

  Project authors should add the missing BYPRODUCTS or OUTPUT options to the
  custom commands that produce these files.

如果我通过在我的外部项目命令中取消注释构建副产品行来满足 cmake 错误的请求,我会收到一个循环依赖错误。但是,如果我将构建副产品排除在外,那么该项目似乎构建得很好。

$ ninja
ninja: error: dependency cycle: googletest-prefix/src/googletest-stamp/googletest-configure -> googletest-prefix/tmp/googletest-cfgcmd.txt -> googletest-prefix/src/googletest-stamp/googletest-configure

我正在使用 cmake 3.4、ninja 1.6,并使用 MSYS2 包在 Windows 上运行。

4

2 回答 2

2

我将 cmake_policy(SET CMP0058 NEW) 添加到我的顶级 CMakeLists.txt 文件中,正如 --help-policy 文本所解释的那样。之后它不再生成警告。我猜这些文件是不需要的。不确定它们是如何被视为依赖项的。

于 2016-01-29T19:43:14.017 回答
0

尝试在 ExternalProject_Add 函数中使用类似的东西:

        set(GMOCK_FILE_DIR "gmock-${GMOCK_VERSION}/src/googletest_github-build/googlemock/")
        BUILD_BYPRODUCTS "${GMOCK_FILE_DIR}gtest/libgtest_main.a"
        BUILD_BYPRODUCTS "${GMOCK_FILE_DIR}gtest/libgtest.a"
        BUILD_BYPRODUCTS "${GMOCK_FILE_DIR}libgmock_main.a"
        BUILD_BYPRODUCTS "${GMOCK_FILE_DIR}libgmock.a"
于 2019-05-23T15:28:30.810 回答