As CMake likes to pick up tools from unrelated toolkits in PATH, the most robust way is to hardcode a proper PATH in CMakeSettings.json.
For VS Community 2022 version 17.2.1, x64:
- Open VS Developer command prompt:
%comspec% /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat" -arch=amd64 -host_arch=amd64
- Execute
echo %PATH%
, copy the result into a text editor.
- Remove everything from that string that doesn’t belong to MS/Windows tools.
- Put it as a PATH environment variable to CMakeSettings.json.
- If python build doesn’t work, something like
-DPYTHON_EXECUTABLE=${env.BuildDir}\\${name}\\vcpkg_installed\\x64-windows\\tools\\python3\\python.exe
can be added to cmakeCommandArgs
.
- Or, up/downgrade your system’s python to 3.9.10 (or whatever is in the logs).
- If KiCad build complains about not finding
kernel32.lib
or standard C++ library headers, add these to the environment variables configuration also:
"LIB": "${env.LIB}",
"LIBPATH": "${env.LIBPATH}",
"INCLUDE": "${env.INCLUDE}",
My CMakeSettings.json
{
"environments": [
{
"BuildDir": "${workspaceRoot}\\build",
"InstallDir": "${workspaceRoot}\\build\\install"
},
{
"environment": "vcpkg",
"VcPkgDir": "S:/kicad-build/vcpkg",
"PATH": "S:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\bin\\HostX64\\x64;S:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\VC\\VCPackages;S:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow;S:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer;S:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\bin\\Roslyn;S:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Team Tools\\Performance Tools\\x64;S:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Team Tools\\Performance Tools;C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.7.2 Tools\\x64\\;C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.19041.0\\\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\bin\\\\x64;S:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\\\MSBuild\\Current\\Bin\\amd64;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319;S:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\;S:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\;C:\\WINDOWS;C:\\WINDOWS\\system32;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\",
"LIB": "${env.LIB}",
"LIBPATH": "${env.LIBPATH}",
"INCLUDE": "${env.INCLUDE}"
}
],
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64", "vcpkg" ],
"buildRoot": "${env.BuildDir}\\${name}",
"installRoot": "${env.InstallDir}\\${name}",
"cmakeCommandArgs": "-DSWIG_EXECUTABLE=S:\\kicad-build\\swigwin-4.0.2\\swig.exe -DPYTHON_EXECUTABLE=${env.BuildDir}\\${name}\\vcpkg_installed\\x64-windows\\tools\\python3\\python.exe",
"buildCommandArgs": "-v -j 4",
"ctestCommandArgs": "",
"variables": [
{
"name": "KICAD_SPICE",
"value": "OFF",
"type": "STRING"
},
{
"name": "KICAD_USE_OCC",
"value": "ON",
"type": "BOOL"
},
{
"name": "KICAD_BUILD_QA_TESTS",
"value": "False",
"type": "BOOL"
},
{
"name": "KICAD_WIN32_DPI_AWARE",
"value": "ON",
"type": "BOOL"
}
],
"cmakeToolchain": "${env.VcPkgDir}/scripts/buildsystems/vcpkg.cmake"
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [ "msvc_x64_x64", "vcpkg" ],
"buildRoot": "${env.BuildDir}\\${name}",
"installRoot": "${env.InstallDir}\\${name}",
"cmakeCommandArgs": "-DSWIG_EXECUTABLE=S:\\kicad-build\\swigwin-4.0.2\\swig.exe -DPYTHON_EXECUTABLE=${env.BuildDir}\\${name}\\vcpkg_installed\\x64-windows\\tools\\python3\\python.exe",
"buildCommandArgs": "-v -j 4",
"ctestCommandArgs": "",
"variables": [
{
"name": "KICAD_SPICE",
"value": "OFF",
"type": "STRING"
},
{
"name": "KICAD_USE_OCC",
"value": "ON",
"type": "BOOL"
},
{
"name": "KICAD_BUILD_QA_TESTS",
"value": "False",
"type": "BOOL"
},
{
"name": "KICAD_WIN32_DPI_AWARE",
"value": "ON",
"type": "BOOL"
}
],
"cmakeToolchain": "${env.VcPkgDir}/scripts/buildsystems/vcpkg.cmake"
}
]
}
Sure, there must be a better way…
Edit:
So I ended up with overriding PATH
, LIB
, LIBPATH
, INCLUDE
variables in CMakeSettings.json
. Setting PYTHON_EXECUTABLE
is not necessary now.
These lines didn’t do anything, they only helped me to notice the Provided 'inheritEnvironments' doesn't provide the necessary environment variables
error:
"LIB": "${env.LIB}",
"LIBPATH": "${env.LIBPATH}",
"INCLUDE": "${env.INCLUDE}",
Here’s how my CMakeSettings.json
looks like now:
Click to expand
{
"environments": [
{
"BuildDir": "${workspaceRoot}\\build",
"InstallDir": "${workspaceRoot}\\build\\install"
},
{
"environment": "vcpkg",
"VcPkgDir": "C:/kicad-build/vcpkg",
"PATH": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\bin\\HostX64\\x64;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\VC\\VCPackages;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\CommonExtensions\\Microsoft\\TeamFoundation\\Team Explorer;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\bin\\Roslyn;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Team Tools\\Performance Tools\\x64;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Team Tools\\Performance Tools;C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.7.2 Tools\\x64\\;C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.19041.0\\\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\bin\\\\x64;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\\\MSBuild\\Current\\Bin\\amd64;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\;C:\\WINDOWS;C:\\WINDOWS\\system32;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\",
"LIB": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\ATLMFC\\lib\\x64;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\lib\\x64;C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.7.2\\lib\\um\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.19041.0\\ucrt\\x64;C:\\Program Files (x86)\\Windows Kits\\10\\\\lib\\10.0.19041.0\\\\um\\x64",
"LIBPATH": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\ATLMFC\\lib\\x64;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\lib\\x64;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\lib\\x86\\store\\references;C:\\Program Files (x86)\\Windows Kits\\10\\UnionMetadata\\10.0.19041.0;C:\\Program Files (x86)\\Windows Kits\\10\\References\\10.0.19041.0;C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319",
"INCLUDE": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\ATLMFC\\include;C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\include;C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.7.2\\include\\um;C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.19041.0\\ucrt;C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.19041.0\\\\shared;C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.19041.0\\\\um;C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.19041.0\\\\winrt;C:\\Program Files (x86)\\Windows Kits\\10\\\\include\\10.0.19041.0\\\\cppwinrt"
}
],
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64", "vcpkg" ],
"buildRoot": "${env.BuildDir}\\${name}",
"installRoot": "${env.InstallDir}\\${name}",
"cmakeCommandArgs": "-DSWIG_EXECUTABLE=C:\\kicad-build\\swigwin-4.0.2\\swig.exe",
"buildCommandArgs": "-v -j 4",
"ctestCommandArgs": "",
"variables": [
{
"name": "KICAD_SPICE",
"value": "OFF",
"type": "STRING"
},
{
"name": "KICAD_USE_OCC",
"value": "ON",
"type": "BOOL"
},
{
"name": "KICAD_BUILD_QA_TESTS",
"value": "OFF",
"type": "BOOL"
},
{
"name": "KICAD_WIN32_DPI_AWARE",
"value": "ON",
"type": "BOOL"
}
],
"cmakeToolchain": "${env.VcPkgDir}/scripts/buildsystems/vcpkg.cmake"
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [ "msvc_x64_x64", "vcpkg" ],
"buildRoot": "${env.BuildDir}\\${name}",
"installRoot": "${env.InstallDir}\\${name}",
"cmakeCommandArgs": "-DSWIG_EXECUTABLE=C:\\kicad-build\\swigwin-4.0.2\\swig.exe",
"buildCommandArgs": "-v -j 4",
"ctestCommandArgs": "",
"variables": [
{
"name": "KICAD_SPICE",
"value": "OFF",
"type": "STRING"
},
{
"name": "KICAD_USE_OCC",
"value": "ON",
"type": "BOOL"
},
{
"name": "KICAD_BUILD_QA_TESTS",
"value": "OFF",
"type": "BOOL"
},
{
"name": "KICAD_WIN32_DPI_AWARE",
"value": "ON",
"type": "BOOL"
}
],
"cmakeToolchain": "${env.VcPkgDir}/scripts/buildsystems/vcpkg.cmake"
}
]
}