bug: 3.22 + Ninja Multi-Config + CMAKE_CONFIGURATION_TYPES env var
CMake 3.22 introduced environment variable CMAKE_CONFIGURATION_TYPES to set multi configuration types.
The problem appears when environment variable CMAKE_CONFIGURATION_TYPES is set to a list starting with Release, causing surprising breakage of try_compile() with Ninja Multi-Config, even for internal CMake scripts.
NOTE: using set(CMAKE_CONFIGURATION_TYPES Release;Debug)
does NOT trigger the bug. It has to be environment variable CMAKE_CONFIGURATION_TYPES=Release;Debug (has to have Release as first entity of list).
I used:
- Linux, MacOS or Windows
- Ninja Multi-Config
- GCC, Clang, Intel, IntelLLVM
- environment variable CMAKE_CONFIGURATION_TYPES=Release;... (Release is first, others don't care)
NOTE: This bug is NOT FindMPI specific, I just happened to notice it with FindMPI's internal try_compile():
Reproduce problem
Set environment variable CMAKE_CONFIGURATION_TYPES=Release;Debug
Use CMakeLists.txt like:
cmake_minimum_required(VERSION 3.22)
project(oops LANGUAGES C)
find_package(MPI)
> cmake -B build -G "Ninja Multi-Config"
results in:
-- The C compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - works
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at C:/cmake-3.22.0-windows-x86_64/share/cmake-3.22/Modules/FindMPI.cmake:1267 (try_compile):
Cannot copy output executable
''
to destination specified by COPY_FILE:
'C:/temp/build/CMakeFiles/FindMPI/test_mpi_C.bin'
Unable to find the executable at any of:
C:/temp/build/CMakeFiles/CMakeTmp/cmTC_cf635.exe
C:/temp/build/CMakeFiles/CMakeTmp/Debug/cmTC_cf635.exe
C:/temp/build/CMakeFiles/CMakeTmp/Development/cmTC_cf635.exe
Call Stack (most recent call first):
c:/cmake-3.22.0-windows-x86_64/share/cmake-3.22/Modules/FindMPI.cmake:1319 (_MPI_try_staged_settings)
C:/cmake-3.22.0-windows-x86_64/share/cmake-3.22/Modules/FindMPI.cmake:1642 (_MPI_check_lang_works)
CMakeLists.txt:5 (find_package)
CMake Error at C:/cmake-3.22.0-windows-x86_64/share/cmake-3.22/Modules/FindMPI.cmake:1746 (file):
file STRINGS file "C:/temp/build/CMakeFiles/FindMPI/test_mpi_C.bin" cannot
be read.
Call Stack (most recent call first):
CMakeLists.txt:5 (find_package)
-- Found MPI_C: C:/msys64/mingw64/lib/libmsmpi.a
-- Found MPI: TRUE found components: C
-- Configuring incomplete, errors occurred!
Notice in CMakeError.log and CMakeOutput.log that "Release" has infiltrated try_compile() commands, causing the failure.
Reference: this was causing #22824 (closed), but I didn't realize the details then