CMake crashes while configuring (Incorrect use of CMake)
envgap__libcpr__cpr-852
01 / FAILURE SIGNATURE
As reported upstream
# !!! This command results in an error !!!
Not a benchmark task.
- In a clean container the reported failure did not reproduce, or the known fix did not make the project run.
02 / ENVIRONMENT RECIPE
- Base commit
142a496e49bc71dc1be85a3ce47bb25573670000- Manifest
CMakeLists.txt- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
libcpr/cpr #852 · read the original issue
### Description
When I add a **Cpr** project to my project (according to the instructions in the **README.md**), the following code in the **Cpr** project's **CMakeLists.txt** causes **CMake** to crash during the configuration phase when using the **Ninja Multi-Config** generator on Linux (Ubuntu 20.04 / 22.04):
```cmake
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (NOT isMultiConfig)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${ALLOWED_BUILD_TYPES}")
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
elseif(NOT CMAKE_BUILD_TYPE IN_LIST ALLOWED_BUILD_TYPES)
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
endif()
else()
unset(CMAKE_BUILD_TYPE)
foreach(TYPE ${ALLOWED_BUILD_TYPES})
if (NOT ${TYPE} IN_LIST CMAKE_CONFIGURATION_TYPES)
# !!! This command results in an error !!!
list(APPEND CMAKE_CONFIGURATION_TYPES ${TYPE})
endif()
endforeach()
endif()
```
According to the discussion here https://gitlab.kitware.com/cmake/cmake/-/issues/24181, the cmake maintainer thinks that setting CMAKE_CONFIGURATION_TYPES in this manner should not happen. That is supposed to be a cache option for users to set.
Therefore, I ask you to remove the modification of the CMAKE_CONFIGURATION_TYPES variable inside the Cpr project.
### Example/How to Reproduce
The error is reproduced in the Ubuntu 20.04 / 22.04 operating system (most likely this error will also occur in other Linux distributions)
To reproduce, you need to create a project with the following **CMakeLists.txt** file:
```cmake
cmake_minimum_required(VERSION 3.20)
project(CMakeBugList)
include(FetchContent)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git
GIT_TAG 871ed52d350214a034f6ef8a3b8f51c5ce1bd400) # The commit hash for 1.9.0. Replace with the latest from: https://github.com/libcpr/cpr/releases
FetchContent_MakeAvailable(cpr)
```
Now let's create a build directory and try to configure the project using the **Ninja Multi-Config** generator:
```shell
cmake ../Bug -G "Ninja Multi-Config"
...
terminate called after throwing an instance of 'std::out_of_range'
what(): map::at
Aborted (core dumped)
```
### Possible Fix
_No response_
### Where did you get it from?
GitHub (branch e.g. master), Other (specify in "Additional Context/Your Environment")
### Additional Context/Your Environment
- OS: Ubuntu 20.04 / 22.04
- Version: master / 1.9.2
04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]