这是我第一次在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()
答案 0 :(得分:3)
您似乎想要使用FetchContent_Populate
命令的简短格式。但是传递 QUIET 选项会使长形式。
实际上,简短格式默认情况下已经是QUIET:它依赖于FETCHCONTENT_QUIET
缓存变量的值,默认情况下为ON
。
只需使用简短格式:
FetchContent_Populate("gsl")
来自FetchContent
CMake模块的documentation。
FetchContent_Populate
命令有两种形式:
简短格式,仅接受内容名称。
此表格从之前的FetchContent_Declare
电话中获取所有人口选项。
长格式,接受其他选项。
此表单表示所有人口选项将直接传递给命令。