windows平台下构建kicad:vcpkg+cmake+visual studio2022

编译kicad资料

Kicad源代码下载:
地址1:

https://github.com/KiCad/kicad-source-mirror

地址2:
稳定版本存档:

https://launchpad.net/kicad/5.0/5.0.2/+download/kicad-5.0.2.tar.xz

我使用的是稳定版本。

官网构建kicad文档:

  • build kicad
  • 从源代码构建 KiCad

KiCad构建配置选项

KiCad有许多构建选项,根据给定平台上每个选项的支持可用性,可以将这些选项配置为构建不同的选项。本节记录了这些选项及其默认值。

选项 含义 默认值
KICAD_SCRIPTING_WXPYTHON enable building the wxPython interface into Pcbnew including the wxPython console. enable
KICAD_SCRIPTING_PYTHON3 启用Python 3接口而不是Python 2的构建 disable
KICAD_CONFIG_DIR The default KiCad configuration directory

修改CMakeLists:
CAIRO
#option( KICAD_SPICE “Build Kicad with internal Spice simulator.” ON )

build方法1:vcpkg+cmake+visual studio构建

vcpkg

https://learn.microsoft.com/en-us/vcpkg/users/buildsystems/cmake-integration

跨平台C/C++软件包管理器:vcpkg

Windows 下使用 vcpkg + CMake 进行开发
基于C++环境的gRPC安装配置:vcpkg+CMake+VS2022
VCpkg+VS2022+cmake安装boost

鸿蒙源码导读-02:编译构建子系统

编译之前,使用vcpkg安装库依赖项

GLEW OpenGL Extension Wrangler Library

vcpkg install glew:x64-windows

The package glew is compatible with built-in CMake targets:

  find_package(GLEW REQUIRED)
    target_link_libraries(main PRIVATE GLEW::GLEW)

GLM OpenGL Mathematics Library

vcpkg install glm:x64-windows

this is heuristically generated, and may not be correct

    find_package(glm CONFIG REQUIRED)
    target_link_libraries(main PRIVATE glm::glm)

Cairo 2D Graphics Library(fail)

Cairo 2D图形库在OpenGL不可用时用作后备渲染画布,并且总是需要它来构建KiCad。

途径1,(我用的途径1)

下载并安装Cairo

git clone git://anongit.freedesktop.org/git/cairo
git clone git://anongit.freedesktop.org/git/pixman.git
git clone [email protected]:cairo/cairo-demos.git

对于 Microsoft VS.net 用户,在构建开罗库之前,您需要创建一个名为“cairo-features.h”的头文件, 创建一个 Win32 DLL 项目,然后将请求的源文件添加到项目中。
Cairo-features.h for MSVC 使用 Win32 字体:

#ifndef CAIRO_FEATURES_H
#define CAIRO_FEATURES_H

#define CAIRO_HAS_IMAGE_SURFACE 1
#define CAIRO_HAS_USER_FONT 1

#define CAIRO_HAS_PNG_FUNCTIONS 1

#define CAIRO_HAS_SVG_SURFACE 1
#define CAIRO_HAS_PDF_SURFACE 1
#define CAIRO_HAS_PS_SURFACE 1

#define CAIRO_HAS_WIN32_SURFACE 1
#define CAIRO_HAS_WIN32_FONT 1

#endif

make.exe路径

在windows上构建

1.安装zlib

vcpkg install zlib:x64-windows

The package zlib is compatible with built-in CMake targets:

find_package(ZLIB REQUIRED)
target_link_libraries(main PRIVATE ZLIB::ZLIB)

2.安装libpng

vcpkg install libpng:x64-windows

The package libpng is compatible with built-in CMake targets:

find_package(PNG REQUIRED)
target_link_libraries(main PRIVATE PNG::PNG)

3.安装pixman

4.修改cario\build文件夹下面的makefile.win32.common文件

ifeq ($(PIXMAN_PATH),)
PIXMAN_PATH := F:/vcpkg-master/installed/x64-windows/include/pixman-1
endif
PIXMAN_CFLAGS := -I$(PIXMAN_PATH)/
PIXMAN_LIBS := F:/vcpkg-master/installed/x64-windows/lib/pixman-1.lib

CAIRO_LIBS =  gdi32.lib msimg32.lib user32.lib

ifeq ($(CAIRO_HAS_PNG_FUNCTIONS),1)
ifeq ($(LIBPNG_PATH),)
LIBPNG_PATH :=F:/vcpkg-master/installed/x64-windows
endif
LIBPNG_CFLAGS += -I$(LIBPNG_PATH)/include/libpng16

CAIRO_LIBS +=  $(LIBPNG_PATH)/lib/libpng16.lib
endif

ifeq ($(CAIRO_HAS_PS_SURFACE)$(CAIRO_HAS_PDF_SURFACE),00)
else

ZLIB_PATH := F:/vcpkg-master/installed/x64-windows/
ZLIB_CFLAGS += -I$(ZLIB_PATH)/include
CAIRO_LIBS += $(ZLIB_PATH)/lib/zlib.lib
endif

DEFAULT_CFLAGS = -nologo $(CFG_CFLAGS)
DEFAULT_CFLAGS += -I. -I$(top_srcdir) -I$(top_srcdir)/src
UCRT_CFLAGS = -I"C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"
MSVC_CFLAGS = -I"D:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.16.27023/include"
MFC_CFLAGS = -I"C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/um"
share_cflags= -I"C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/shared"

DEFAULT_CFLAGS += $(PIXMAN_CFLAGS) $(LIBPNG_CFLAGS) $(ZLIB_CFLAGS) $(UCRT_CFLAGS) $(MSVC_CFLAGS) $(MFC_CFLAGS) $(share_cflags)

5.运行编译命令:

D:\kicad\cairo\cairo>  make.exe -f Makefile.win32 CFG=release

“assert.h”: No such file or directory

cairo-analysis-surface.c
d:\kicad\cairo\cairo\src\cairoint.h(55): fatal error C1083: 无法打开包括文件: “assert.h”: No such file or directory
make[1]: *** […/build/Makefile.win32.common:67: release/cairo-analysis-surface.obj] Error 2
make[1]: Leaving directory ‘/d/kicad/cairo/cairo/src’
make: *** [Makefile.win32:12: cairo] Error 2

“windows.h” : No such file or directory

要么修复下VS,重新装下MFC

并将windows.h所在文件夹包含makefile.32.common文件中

C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um

除了包含um文件夹,shared文件夹也要包含,
否则会找不到
“winapifamily.h":no such file or directory

C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared

link: unknown option – n

需要使用MVSC的link.exe,将下面路径配置到环境变量,并上移到最前面后,问题解决。


D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64

windows平台下构建kicad:vcpkg+cmake+visual studio2022_第1张图片
参考文献:
link: unknown option – n

LNK1181: 无法打开输入文件“gdi32.lib”

PS D:\kicad\cairo\cairo>  make.exe -f Makefile.win32 CFG=release

make[1]: Entering directory '/d/kicad/cairo/cairo/src'

LINK : fatal error LNK1181: 无法打开输入文件“gdi32.lib”
make[1]: *** [Makefile.win32:16: release/cairo.dll] Error 157
make[1]: Leaving directory '/d/kicad/cairo/cairo/src'
make: *** [Makefile.win32:12: cairo] Error 2

因为对makefile不是很熟,所有的lib都是自己一个个找出来的,具体路径包括:

D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.16.27023\lib\x64
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\ucrt\x64
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22621.0\um\x64
F:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64

所有的lib包括:
windows平台下构建kicad:vcpkg+cmake+visual studio2022_第2张图片

编译成功

make[1]: Entering directory '/d/kicad/cairo/cairo/src'

  正在创建库 release/cairo.lib 和对象 release/cairo.exp
cairo-fixed.obj : warning LNK4221: 此对象文件未定义任何之前未定义的公共符号,因此任何耗用此库的链接操作都不会使用此文件
cairo-atomic.obj : warning LNK4221: 此对象文件未定义任何之前未定义的公共符号,因此任何耗用此库的链接操作都不会使用此文件
Built successfully!
You should copy the following files to a proper place now:

        src/cairo-features.h
        src/cairo.h
        src/cairo-version.h
        src/cairo-deprecated.h
        src/cairo-win32.h
        src/cairo-script.h
        src/cairo-ps.h
        src/cairo-pdf.h
        src/cairo-svg.h
        src/release/cairo.dll
        src/release/cairo-static.lib
make[1]: Leaving directory '/d/kicad/cairo/cairo/src'

途径2

下载Cairo

boost

vcpkg install boost:x64-windows

The package boost is compatible with built-in CMake targets:

find_package(Boost REQUIRED [COMPONENTS ...])
target_link_libraries(main PRIVATE Boost::boost Boost:: Boost:: ...)

wxpython(fail)

wxPython库用于为Pcbnew提供脚本控制台。除非禁用了wxPython脚本构建配置选项,否则需要安装它。在构建支持wxPython的KiCad时,请确保wxWidgets库的版本与系统上安装的wxPython版本相同。已知不匹配的版本会导致运行时问题。

C:\Users\44257>vcpkg install wxPython:x64-windows
Computing installation plan...
error: while looking for wxpython:x64-windows:
error: while loading wxpython:
error: wxpython does not exist

Curl Multi-Protocol File Transfer Library(fail)

The Curl Multi-Protocol File Transfer Library is used to provide secure internet file transfer access for the GitHub plug in. This library needs to be installed unless the GitHub plug build option is disabled.

curl provides CMake targets:

this is heuristically generated, and may not be correct

  find_package(CURL CONFIG REQUIRED)
    target_link_libraries(main PRIVATE CURL::libcurl)

OpenCascade Library(not install)

disable OCE build option is disabled.

ngspice(fail)

wxWidgets

wxWidgets Windows下安装 配置 编译 创建项目 实现“hello world”(Visual Studio2019)详细图文教程

The package wxwidgets provides CMake targets:

find_package(wxWidgets CONFIG REQUIRED)
target_link_libraries(main PRIVATE wx::core wx::base)

方法1在cmake配置时遇到的错误

Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)

vcpkg install pkgconf:x64-windows

https://stackoverflow.com/a/73763184

问题已经解决

NGSPICE library missing

*** NGSPICE library missing ***
Most of ngspice packages do not provide the required libngspice library.
You can either compile ngspice configured with --with-ngshared parameter
or run a script that does the job for you:
cd ./scripts
chmod +x get_libngspice_so.sh
./get_libngspice_so.sh
sudo ./get_libngspice_so.sh install

CMake Error at D:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find ngspice (missing: NGSPICE_INCLUDE_DIR NGSPICE_LIBRARY
NGSPICE_DLL)
Call Stack (most recent call first):
D:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
CMakeModules/Findngspice.cmake:39 (find_package_handle_standard_args)
F:/vcpkg-master/scripts/buildsystems/vcpkg.cmake:852 (_find_package)
CMakeLists.txt:632 (find_package)

解决方案:
关掉KICAD_SPICE选项,配置成功。
windows平台下构建kicad:vcpkg+cmake+visual studio2022_第3张图片

list GET given empty list

CMake Error at CMakeModules/FindOpenSSL.cmake:304 (list):
list GET given empty list
Call Stack (most recent call first):
F:/vcpkg-master/installed/x64-windows/share/openssl/vcpkg-cmake-wrapper.cmake:37 (_find_package)
F:/vcpkg-master/scripts/buildsystems/vcpkg.cmake:806 (include)
common/CMakeLists.txt:27 (find_package)

    file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str
         REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
    message(STATUS "OPENSSL_VERSION_STR=${openssl_version_str}")

    string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F]).*$"
           "\\1;\\2;\\3;\\4;\\5" OPENSSL_VERSION_LIST "${openssl_version_str}")
    list(GET OPENSSL_VERSION_LIST 0 OPENSSL_VERSION_MAJOR)
    list(GET OPENSSL_VERSION_LIST 1 OPENSSL_VERSION_MINOR)

官网关于OPENSSL_VERSION_NUMBER的解释:
OPENSSL_VERSION_NUMBER

/* from openssl/opensslv.h */
#define OPENSSL_VERSION_NUMBER 0xnnnnnnnnL

上面的代码解析#define OPENSSL_VERSION_NUMBER 0xnnnnnnnnL没有问题,但最新版的openssl OPENSSL_VERSION_NUMBER格式变了,
根据github cmake中的FindOpenSSL.cmake文件修改解析OPENSSL_VERSION_NUMBER部分代码,问题解决。

build 方法2:使用 MSYS2 进行构建

参考文案:
https://mirrors.cqu.edu.cn/kicad/doxygen/md_Documentation_development_compiling.html

安装依赖库

mingw-w64-x86_64-wxWidgets




resolving dependencies...
looking for conflicting packages...
:: mingw-w64-x86_64-wxwidgets3.0-msw and mingw-w64-x86_64-wxwidgets3.2-common are in conflict (mingw-w64-x86_64-wxwidgets-common). Remove mingw-w64-x86_64-wxwidgets3.2-common? [Y/n] y
:: mingw-w64-x86_64-wxwidgets3.0-msw and mingw-w64-x86_64-wxwidgets3.2-msw are in conflict (mingw-w64-x86_64-wxconfig). Remove mingw-w64-x86_64-wxwidgets3.2-msw? [Y/n] y
error: failed to prepare transaction (could not satisfy dependencies)
:: removing mingw-w64-x86_64-wxwidgets3.2-msw breaks dependency 'mingw-w64-x86_64-wxmsw3.2' required by mingw-w64-x86_64-wxPython

改成安装3.2版本:

# pacman -S    mingw-w64-x86_64-wxWidgets3.2

你可能感兴趣的:(kicad,kicad,vcpkg,cmake,visual,studio,windows)