Ninja Multi-Config can't be re-configured in the same build directory
On a windows host using the Ninja Multi-Config generator like such:
cmake\3.22.1\bin\cmake.exe `
-G"Ninja Multi-Config" `
-S D:\builds\source `
-B D:\builds\cmake-build-w64 `
-DCMAKE_CROSS_CONFIGS="Release;Debug" `
-DCMAKE_DEFAULT_CONFIGS="Release;Debug" `
-DCMAKE_CONFIGURATION_TYPES="Release;Debug"
I can build my code no problem.
If I delete D:\builds\cmake-build-w64
and then run
cmake\3.22.1\bin\cmake.exe `
-G"Ninja Multi-Config" `
-S D:\builds\source `
-B D:\builds\cmake-build-w64 `
-DCMAKE_CROSS_CONFIGS="Release;Debug" `
-DCMAKE_DEFAULT_CONFIGS="Release;Debug" `
-DCMAKE_CONFIGURATION_TYPES="Release;Debug"
cmake\3.22.1\bin\cmake.exe `
-G"Ninja Multi-Config" `
-S D:\builds\source `
-B D:\builds\cmake-build-w64 `
-DCMAKE_CROSS_CONFIGS="Release;Debug" `
-DCMAKE_DEFAULT_CONFIGS="Release;Debug" `
-DCMAKE_CONFIGURATION_TYPES="Release;Debug"
(The same configuration command twice in a row)
Then my builds error out with
c1xx: fatal error C1083: Cannot open source file: 'c': No such file or directory
and i see in the error'ed command that a random 'c' has been added to the cmdline after the include list:
/DWIN32 /D_WINDOWS /GR c /O2 /Ob2 /DNDEBUG -MD /GL /X /bigobj /EHa /GR /GF /Gy /W4 -std:c++17
Specifically
/GR c /O2
Looking at CMakeFiles\impl-Release.ninja (and debug as well), i see after the first configuration:
FLAGS = /O2 /Ob2 /DNDEBUG -MT /GL /X /bigobj /EHa /GR /GF /Gy /W4 /wd4996 -std:c++17
and after the second configuration:
FLAGS = /DWIN32 /D_WINDOWS /GR c /O2 /Ob2 /DNDEBUG -MT /GL /X /bigobj /EHa /GR /GF /Gy /W4 /wd4996 -std:c++17
Meaning that /DWIN32 /D_WINDOWS /GR c
has been added to the FLAGS section of my target.
What's confusing here is that we already have these definesin the DEFINES section
-DWIN32 -DWIN64 -D_WIN32_WINNT=0x0600 -D_WINDOWS
and /GR
is already present in FLAGS
So why would CMake add them again?
Notably, the second configuration does not remove the defines from the DEFINES =, or remove the second /GR from FLAGS.
This does not happen when building the same codebase with the normal Ninja generator. Only the multi-config generator.
It also does not happen when building on a Linux host, or on a Windows host with a toolchain file explicitly targeting Linux with the Clang compiler. We only get this problem with Windows->Windows with MSVC.
What I expected is that re-running the configuration with the same options and no changes to the source directory would cause no changes to the build unless there was some CMake code in CMakeLists that explicitly tried to do that, which we don't do.