FetchContent fails with SYSTEM and commit hash other than HEAD
CMake-Version: 3.25.0, Git-Version: 2.38.0
When trying to fetch a dependency using SYSTEM
and referencing a commit hash using GIT_TAG
other than HEAD
, FetchContent fails:
cmake_minimum_required(VERSION 3.25.0)
project(fetch_content_bug)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 9b9a42166803e864a8b08c22cadfe8db447acb40 # not HEAD
GIT_SHALLOW OFF
SYSTEM
)
FetchContent_MakeAvailable(googletest)
$ cmake ..
Microsoft (R)-Build-Engine, Version 16.11.2+f32259642 für .NET Framework
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
Checking Build System
Creating directories for 'googletest-populate'
Building Custom Rule C:/Users/<hidden>/cmake_bug_repro/build/_deps/googletest-subbuild/CMakeLists.txt
Performing download step (git clone) for 'googletest-populate'
Cloning into 'googletest-src'...
fatal: reference is not a tree: 9b9a42166803e864a8b08c22cadfe8db447acb40
CMake Error at googletest-subbuild/googletest-populate-prefix/tmp/googletest-populate-gitclone.cmake:49 (message):
Failed to checkout tag: '9b9a42166803e864a8b08c22cadfe8db447acb40'
...
CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/FetchContent.cmake:1616 (message):
Build step for googletest failed: 1
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.25/Modules/FetchContent.cmake:1756:EVAL:2 (__FetchContent_directPopulate)
C:/Program Files/CMake/share/cmake-3.25/Modules/FetchContent.cmake:1756 (cmake_language)
C:/Program Files/CMake/share/cmake-3.25/Modules/FetchContent.cmake:1970 (FetchContent_Populate)
CMakeLists.txt:43 (FetchContent_MakeAvailable)
-- Configuring incomplete, errors occurred!
Removing SYSTEM
works:
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 6b63c98ac43efc992122f1da12aaf0a0e0658206 # not HEAD
GIT_SHALLOW OFF
)
Using HEAD
for GIT_TAG
with SYSTEM
works:
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG e68764c147ea0dac1e8811925c531d937396878e # head
GIT_SHALLOW OFF
SYSTEM
)
Using tags for GIT_TAG
with SYSTEM
works:
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.12.0
GIT_SHALLOW OFF
SYSTEM
)