std::out_of_range exception when adding to CMAKE_CONFIGURATION_TYPES list in subdirectory on Linux (Ubuntu 20.04)
std::out_of_range exception when adding to CMAKE_CONFIGURATION_TYPES list in subdirectory on Linux (Ubuntu 20.04)
When trying to add a new value to the CMAKE_CONFIGURATION_TYPES variable in a CMake subdirectory, it crashes with the error:
terminate called after throwing an instance of 'std::out_of_range'
what(): map::at
CMake was installed from the repository
https://apt.kitware.com/ubuntu/ focal main
I checked for the error on versions:
- 3.20.5-0kitware1ubuntu20.04.1
- 3.23.2-0kitware1ubuntu20.04.1
- 3.25.0-0kitware1ubuntu20.04.1
Possibly other versions are affected as well.
To reproduce, you need to create a project with the following CMakeLists.txt file:
cmake_minimum_required(VERSION 3.20)
project(CMakeBugList)
add_subdirectory(dir0)
Let's create a dir0 subdirectory containing the following CMakeLists.txt file:
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES} SomeValue)
# or
# list(APPEND CMAKE_CONFIGURATION_TYPES SomeValue)
Now let's create a build directory and try to configure the project using the Ninja Multi-Config generator:
cmake ../CMakeBugList -G "Ninja Multi-Config"
-- The C compiler identification is GNU 11.1.0
-- The CXX compiler identification is GNU 11.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
terminate called after throwing an instance of 'std::out_of_range'
what(): map::at
Aborted (core dumped)