BUILD_BYPRODUCTS和cmake + ninja + googletest + ExternalProject_Add的依赖循环

时间:2016-01-29 08:52:42

标签: cmake googletest ninja

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

   # 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上运行。

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分: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"