Running cmake twice on Windows after creating CMakePresets.json fails with generator platform error
I'm working on the OpenFX project, adding cmake and conan support. The issue I'm facing is basically that running our conan+cmake build script twice fails the second time on Windows.
Conan (1.59.0) creates a CMakePresets.json
file like this:
% cat build/generators/CMakePresets.json
{
"version": 3,
"vendor": {
"conan": {}
},
"cmakeMinimumRequired": {
"major": 3,
"minor": 15,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "'default' config",
"description": "'default' configure using 'Visual Studio 17 2022' generator",
"generator": "Visual Studio 17 2022",
"cacheVariables": {
"CMAKE_POLICY_DEFAULT_CMP0091": "NEW"
},
"toolchainFile": "C:\\Users\\garyo\\src\\OpenFX\\build\\generators\\conan_toolchain.cmake",
"binaryDir": "C:\\Users\\garyo\\src\\OpenFX\\build"
}
],
...
and on the second run, without changing anything, we get this error from cmake:
+ cmake --preset default -DBUILD_EXAMPLE_PLUGINS=TRUE
Preset CMake variables:
CMAKE_POLICY_DEFAULT_CMP0091="NEW"
CMAKE_TOOLCHAIN_FILE:FILEPATH="C:\Users\garyo\src\OpenFX\build\generators\conan_toolchain.cmake"
CMake Error: Error: generator platform:
Does not match the platform used previously: x64
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
I notice that the conan_toolchain.cmake
does define set(CMAKE_GENERATOR_PLATFORM "x64" CACHE STRING "" FORCE)
but this is not enough to prevent the error. The only thing I have found that prevents the error is to manually add configurePresets[0].architecture = "x64"
to the conan-generated toolchain file. But perhaps I'm missing something? You can check out the project at github at https://github.com/AcademySoftwareFoundation/openfx -- to repro on Windows, check out the cmake
branch of that repo, use an msys shell, conan 1.59.0, cmake 3.23.0, and just run scripts/build-cmake.sh
twice. The first time it will succeed, then the second time it will fail with the above error.
When I reported this as a conan issue (see here, they suggested that this looks like a cmake bug (or at least an unexpected behavior) and I should report it here. I'm hoping you can help me figure out a workaround.