为什么FetchContent说"没有下载信息"即使有GIT_REPOSITORY?

时间:2018-04-14 03:19:55

标签: cmake

这是我第一次在CMake 3.11中使用FetchContent并且它似乎没有注意到我给它一个Git存储库:

CMake Error at C:/Program Files/CMake/share/cmake-3.11/Modules/ExternalProject.cmake:2525 (message):
  No download info given for 'gsl-populate' and its source directory:

   C:/Dev/foo/build/gsl-src

  is not an existing non-empty directory.  Please specify one of:

   * SOURCE_DIR with an existing non-empty directory
   * DOWNLOAD_COMMAND
   * URL
   * GIT_REPOSITORY
   * SVN_REPOSITORY
   * HG_REPOSITORY
   * CVS_REPOSITORY and CVS_MODULE
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.11/Modules/ExternalProject.cmake:3100 (_ep_add_download_command)
  CMakeLists.txt:13 (ExternalProject_Add)


-- Configuring incomplete, errors occurred!
See also "C:/Dev/foo/build/gsl-subbuild/CMakeFiles/CMakeOutput.log".

CMake Error at C:/Program Files/CMake/share/cmake-3.11/Modules/FetchContent.cmake:786 (message):
  CMake step for gsl failed: 1
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.11/Modules/FetchContent.cmake:822 (__FetchContent_directPopulate)
  cmake/FetchGSL.cmake:21 (FetchContent_Populate)
  CMakeLists.txt:29 (include)

FetchGSL.cmake脚本是:

include("FetchContent")

set(GSL_GIT_REPOSITORY "https://github.com/Microsoft/GSL.git"
  CACHE STRING "C++ Guideline Support Library Git repository URL")

set(GSL_GIT_TAG "d846fe50a3f0bb7767c7e087a05f4be95f4da0ec"
  CACHE STRING "C++ Guideline Support Library Git commit ID, branch, or tag")

mark_as_advanced(GSL_GIT_REPOSITORY GSL_GIT_TAG)

FetchContent_Declare(
  "gsl"
  GIT_REPOSITORY "${GSL_GIT_REPOSITORY}"
  GIT_TAG "${GSL_GIT_TAG}"
  GIT_SHALLOW 1
)

FetchContent_GetProperties("gsl")

if(NOT gsl_POPULATED)
  FetchContent_Populate("gsl" QUIET)
  add_library(GSL::GSL IMPORTED INTERFACE)
  set_target_properties(
    GSL::GSL
    PROPERTIES
      INTERFACE_COMPILE_FEATURES "cxx_std_14"
      INTERFACE_INCLUDE_DIRECTORIES "${gsl_SOURCE_DIR}/include"
  )
endif()

1 个答案:

答案 0 :(得分:3)

您似乎想要使用FetchContent_Populate命令的简短格式。但是传递 QUIET 选项会使长形式

实际上,简短格式默认情况下已经是QUIET:它依赖于FETCHCONTENT_QUIET缓存变量的值,默认情况下为ON

只需使用简短格式

FetchContent_Populate("gsl")

来自FetchContent CMake模块的documentation

FetchContent_Populate命令有两种形式:

  1. 简短格式,仅接受内容名称。

    此表格从之前的FetchContent_Declare电话中获取所有人口选项

  2. 长格式,接受其他选项。

    此表单表示所有人口选项将直接传递给命令