cmake - BUILD_BYPRODUCTS 和 cmake + ninja + googletest + ExternalProject_Add 的依赖周期

标签 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)

使用 ninja 生成器时,我收到以下警告。

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

最佳答案

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

关于cmake - BUILD_BYPRODUCTS 和 cmake + ninja + googletest + ExternalProject_Add 的依赖周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35080358/

相关文章:

c++ - 在谷歌模拟中捕获回调的参数

c++ - 当我尝试构建 gnome builder 时,ninja 在 glib ctype.h 文件中给出错误

c++ - ARM 与较旧的 glibc 交叉编译

c++ - github上的CMake/C++项目组织

installation - 在 CMake 中,如何在目标安装后运行脚本?

c++ - 在 CLion 中设置 Google 测试

c++ - 包含其他库的 CMake add_library

c++ - 未定义对 Gtest 的 pthread 的引用

android - 使用 jni 库构建 AOSP 应用程序

build - ninja 如何检测要重建的文件?