FetchContent: Populated project ignores CMAKE_CONFIGURATION_TYPES
When configuring with a multi-config generator the project populated using FetchContent ends up using the generator defaults.
For example with the CMakeLists.txt below and running cmake . -B build -G "Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES=Release
the build system for eigen (under build/_deps/eigen-subbuild
) contains build-*.ninja
files for Debug, Release, and RelWithDebInfo configurations. If I use the "Visual Studio 17 2022" generator I get Debug, Release, RelWithDebInfo, and MinSizeRel configurations.
I repro with cmake 3.20 and 3.22.
Also a strange side note: if I do the configure within Visual Studio (either CMakeSetting.json or CMakePresets.json) then FetchContent does respect CMAKE_CONFIGURATION_TYPES and only the specified configuration types exist in the build output. (I only tried with VS 2022)
CMakeLists.txt
:
cmake_minimum_required (VERSION 3.8)
project ("repro")
include(FetchContent)
cmake_path(APPEND DEPS_DIR "${CMAKE_CURRENT_SOURCE_DIR}" "deps")
# Download Eigen.
set(EIGEN_VER 3.4.0)
FetchContent_Declare(eigen
URL https://gitlab.com/libeigen/eigen/-/archive/${EIGEN_VER}/eigen-${EIGEN_VER}.zip
SOURCE_DIR ${DEPS_DIR}/eigen)
FetchContent_MakeAvailable(eigen)
CMakePresets.json
:
{
"version": 3,
"configurePresets": [
{
"name": "ninja",
"generator": "Ninja Multi-Config",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_CONFIGURATION_TYPES": "Release"
}
}
]
}