I have a simple CMake project which uses CMakePresets.json to set up common settings and Ninja as its underlying build system to compile a C++ program. The problem that I'm facing right now is in CLion where it always picks x86 architecture by default instead of x64. If I explicitly tell Ninja to use x64 it will throw the following error:
CMake Error at CMakeLists.txt:3 (project):
Generator
Ninja
does not support platform specification, but platform
x64
was specified.
I know that I should run vcvarsall.bat in x64 mode to define proper environment variables but I couldn't find a way to do it automatically in CLion.
So calling vcvarsall.bat
isn't pleasant since I should manually run vcvarsall.bat.
Is there any way to automate this process inside CMake?
This is my CMakePresets.json if anyone curious to know:
{
"version": 3,
"configurePresets": [
{
"name": "windows-base",
"description": "Target Windows with the Visual Studio development environment.",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/Build/${presetName}",
"installDir": "${sourceDir}/Install/${presetName}",
"architecture": {
"value": "x64",
"strategy": "external"
},
"toolset": {
"value": "host=x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
}
},
{
"name": "x64-debug",
"displayName": "Debug",
"description": "Target Windows (64-bit) with the Visual Studio development environment. (Debug)",
"inherits": "windows-base",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }
},
{
"name": "x64-release",
"displayName": "Release",
"description": "Target Windows (64-bit) with the Visual Studio development environment. (Release)",
"inherits": "windows-base",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
},
{
"name": "x64-release_with_debug_information",
"displayName": "Release with Debug Information",
"description": "Target Windows (64-bit) with the Visual Studio development environment. (RelWithDebInfo)",
"inherits": "windows-base",
"cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo" }
}
],
"buildPresets": [
{
"name": "Debug Preset",
"configurePreset": "x64-debug"
},
{
"name": "Release Preset",
"configurePreset": "x64-release"
},
{
"name": "Release with Debug Information Preset",
"configurePreset": "x64-release_with_debug_information"
}
]
}
Thanks in advance.