Windows
1.安装visual studio Pro 2019 以上版本,建议2022,自行破解,安装时一定要勾选上cmake工具;安装Git bash
2.去Gitlab上fork kicad的master分支到自己的gitlab仓库上,在本地创建kicad-source路径,初始化本地仓库, clone自己Gitlab仓库的kicad源码
3.在自定义路径下安装vcpkg(vs的环境配置工具),不要放在kicad-source路径下即可。执行
git clone https://github.com/microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat
4.到kicad-source下找到CMakeSettings.json.sample
,在此路径下复制并粘贴,改名字为CMakeSettings.json
,打开json文件修改"VcPkgDir"
的键值对,改为本地的vcpkg安装文件,example
{ "VcPkgDir": "D:/vcpkg/" },
5.打开vs2022,选择打开文件夹,选择kicad-source文件夹,vs集成的cmake工具会自动执行,等待vcpkg安装好依赖,直到cmake报错swig缺失再继续第六步
6.自行安装swig,路径不要放在kicad-source下,SWIG - Browse /swigwin at SourceForge.net ,解压压缩包,然后找到swig.exe,将路径替换到下面的your_swig_path
,替换后复制到CMakeSettings.json
的"name": "x64-Debug"
下的"cmakeCommandArgs"
的键值对,注意每一个反斜杠用两个反斜杠替换
{"environments": [{"BuildDir": "${workspaceRoot}\\build","InstallDir": "${workspaceRoot}\\build\\install"},{"environment": "vcpkg","VcPkgDir": "D:/ExtendLib/vcpkg/vcpkg/"},{"environment": "mingw_64","MINGW64_ROOT": "D:/msys64/mingw64","BIN_ROOT": "${env.MINGW64_ROOT}/bin","FLAVOR": "x86_64-w64-mingw32","TOOLSET_VERSION": "10.2.0","PATH": "${env.MINGW64_ROOT}/bin;${env.MINGW64_ROOT}/../usr/local/bin;${env.MINGW64_ROOT}/../usr/bin;${env.MINGW64_ROOT}/../bin;${env.PATH}","INCLUDE": "${env.INCLUDE};${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION};${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION}/tr1;${env.MINGW64_ROOT}/include/c++/${env.TOOLSET_VERSION}/${env.FLAVOR}"}],"configurations": [{"name": "x86-Debug","generator": "Ninja","configurationType": "Debug","inheritEnvironments": [ "msvc_x86", "vcpkg" ],"buildRoot": "${env.BuildDir}\\${name}","installRoot": "${env.InstallDir}\\${name}","addressSanitizerEnabled": false,"cmakeCommandArgs": "","buildCommandArgs": "-v","ctestCommandArgs": "","variables": [{"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": "x86-Release","generator": "Ninja","configurationType": "RelWithDebInfo","inheritEnvironments": [ "msvc_x86", "vcpkg" ],"buildRoot": "${env.BuildDir}\\${name}","installRoot": "${env.InstallDir}\\${name}","cmakeCommandArgs": "","buildCommandArgs": "-v","ctestCommandArgs": "","variables": [{"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-Debug","generator": "Visual Studio 17 2022","configurationType": "Debug","inheritEnvironments": [ "msvc_x64_x64", "vcpkg" ],"buildRoot": "${env.BuildDir}\\${name}","installRoot": "${env.InstallDir}\\${name}","cmakeCommandArgs": "-DSWIG_EXECUTABLE=D:/ExtendLib/vcpkg/swigwin-4.1.1/swig.exe","buildCommandArgs": "-v","ctestCommandArgs": "","variables": [{"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": "Visual Studio 17 2022","configurationType": "RelWithDebInfo","inheritEnvironments": [ "msvc_x64_x64", "vcpkg" ],"buildRoot": "${env.BuildDir}\\${name}","installRoot": "${env.InstallDir}\\${name}","cmakeCommandArgs": "-DSWIG_EXECUTABLE=D:/ExtendLib/vcpkg/swigwin-4.1.1/swig.exe","buildCommandArgs": "-v","ctestCommandArgs": "","variables": [{"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": "MSYS2-x64-Debug","generator": "Ninja","configurationType": "Debug","inheritEnvironments": [ "mingw_64" ],"buildRoot": "${env.BuildDir}\\${name}","installRoot": "${env.InstallDir}\\${name}","cmakeCommandArgs": "","buildCommandArgs": "-v","ctestCommandArgs": "","intelliSenseMode": "linux-gcc-x64","cmakeToolchain": "","variables": [{"name": "CMAKE_C_COMPILER","value": "${env.BIN_ROOT}/gcc.exe"},{"name": "CMAKE_CXX_COMPILER","value": "${env.BIN_ROOT}/g++.exe"},{"name": "KICAD_BUILD_QA_TESTS","value": "False","type": "BOOL"},{"name": "KICAD_WIN32_DPI_AWARE","value": "ON","type": "BOOL"}]}]
}
7.第6步后vs会自动进行cmake直到显示"CMake generation finished",此时就说明生成makefile成功了,之后可以进行全量编译。注意此时CMakeSettings.json
里的"x64-Debug"
的生成器是"generator": "Ninja"
,它不是MSBuild,所以不会生成VS的工程文件,构建的方式也是按照"Ninja"
的构建方式去构建的,如果只追求快速编译生成可以使用它,如果要调试debug,可以选择使用MSBuild生成VS的工程文件*.sln,再打开VS的*.sln来进行开发和调试。具体做法就是把"x64-Debug"
的生成器替换成"generator": "Visual Studio 17 2022 Win64"
,具体可以直接改CMakeSettings.json
,也可以在vs界面里选择。修改后会重新进行cmake
注意:vs里面的cmake可以自行设置,一般默认的是CMakeSettings.json只要被修改,VS的cmake会自动开始运行,读取CMakeSettings.json执行修改
8.
如果是要在debug模式下进行调试,还需要进行launch.vs.json
的修改替换,把下面的json代码直接替换即可,都是相对路径,不需要修改。具体打开launch.vs.json
的方式是VS Menu->Debug->Debug and Launch Settings。注意这里改的是整个kicad项的launch.vs.json
,如果是要独立生成调试pcbnew
或 eeschema
,需要单独配置这些项的launch.vs.json
,配置参数参考下面的对应部分。
注意:这里第8步,是kicad官方的操作方式,这种配置修改launch.vs.json的调试启动方式是有前提条件的,1.在vscode里面,vs2017以及以后版本的VS;2.
基于目录的项目的代码,而没有创建解决方案或者项目文件的项目(详细介绍参考微软官方简介:Launch.vs.json 架构参考 (C++) | Microsoft Learn),所以说对于使用VS进行常规调试的程序者来说,这是不舒服的,我就想按照常规的方式使用VS直接单步调试代码,能行么?可以的,搞一个批处理脚本设置对应的启动属性就可以,批处理脚本如下(前提是已经使用MSVC构建好vs解决方案):
set "KICAD_RUN_FROM_BUILD_DIR=1"
set "KICAD_USE_EXTERNAL_PYTHONHOME=1"
set "PYTHONHOME=D:/ExtendLib/kicad-source-mirror-master/build/x64-Debug/vcpkg_installed/x64-windows/tools/python3"
set "PYTHONPATH=D:/ExtendLib/kicad-source-mirror-master/build/x64-Debug/pcbnew;D:/ExtendLib/kicad-source-mirror-master/pcbnew/python"
set "path=D:/ExtendLib/kicad-source-mirror-master/build/x64-Debug/vcpkg_installed/x64-windows/debug/bin"
%~dp0kicad.sln
pause
使用很简单,把该批处理文件放在如下目录
如果不想使用该脚本,也可以在自身电脑里面添加对应的环境变量,也是可以滴
9.通过kicad调试所有模块(pcbnew等)
通过上述方式启动vs解决方案,编译代码,通过vs调试程序,进入kicad主界面
点击任意子模块,此处以PCB Editor为例,
提示加载E:\vs2022\projects\kicad-master\build\x64-Debug\kicad\pcbnew\_pcbnew.dll 失败找不到指定模块,so,我找到_pcbnew.dll文件放在对应目录下,继续调试,还是不行,还是提示同样的错误,这不合理,看一下代码:
输入的路径是对的,返回是false,失败,经过一番折腾,发现_pcbnew.dll是要把其它依赖文件放在一起的,如下:
加了其它依赖库,再调试,OK,可以了