FetchContent_Declare: Changing SOURCE_DIR results in CMakeLists.txt being deleted
CMake version: 3.20.0-rc5
A small example to use for repro (catch2 is used purely as an example, other libs also have this issue) start out with the following in CMakeLists.txt:
cmake_minimum_required(VERSION 3.15.0)
include(FetchContent)
project(Repro)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG 20d413b8b6803c6d456874935d7014fe684e9426
)
FetchContent_MakeAvailable(catch2)
Generate the build files and change the SOURCE_DIR
to the following:
cmake_minimum_required(VERSION 3.15.0)
include(FetchContent)
project(Repro)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG 20d413b8b6803c6d456874935d7014fe684e9426
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/catch2
)
FetchContent_MakeAvailable(catch2)
Try to generate the build files again, this will error out with the following error:
CMake Error at C:/Program Files/CMake/share/cmake-3.20/Modules/FetchContent.cmake:1012 (message):
Build step for catch2 failed: 1
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.20/Modules/FetchContent.cmake:1141:EVAL:2 (__FetchContent_directPopulate)
C:/Program Files/CMake/share/cmake-3.20/Modules/FetchContent.cmake:1141 (cmake_language)
C:/Program Files/CMake/share/cmake-3.20/Modules/FetchContent.cmake:1184 (FetchContent_Populate)
CMakeLists.txt:18 (FetchContent_MakeAvailable)
and the CMakeLists.txt file will have mysteriously disappeared.