这是我第一次在 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()
最佳答案
您似乎想使用 FetchContent_Populate
命令的简短形式。但是传递QUIET选项会生成长格式。
实际上,短格式默认情况下已经是 QUIET 了:它依赖于 FETCHCONTENT_QUIET
缓存变量的值,该变量默认为 ON
。
只需使用简短形式:
FetchContent_Populate("gsl")
来自documentation FetchContent
CMake 模块。
FetchContent_Populate
命令有两种形式:
简短形式,仅接受内容名称。
此表单从之前的
FetchContent_Declare
调用中派生所有总体选项。长格式,接受附加选项。
这种形式意味着所有填充选项都将直接传递给命令。
关于cmake - 为什么即使使用 GIT_REPOSITORY,FetchContent 也会显示 "no download info"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49827556/