MSYS2 with CLion BUILD KICAD

本文介绍如何使用MSYS2环境在Windows上构建KiCad。内容包括安装必要的依赖包、配置CMake以及集成开发环境CLion的设置。特别针对Boost版本问题和OCE从源码编译给出了解决方案。

title: Windows (MSYS2) weight: 13 summary: Guide on building KiCad using MSYS2 tags: ["windows"] ---

Building using MSYS2

Setup

The MSYS2 project provides packages for all of the require dependencies to build KiCad. To setup the MSYS2 build environment, download and run the MSYS2 64-bit Installer available from the msys2 home page. After the installer is finished, update to the latest package versions by running the msys2_shell.cmd file located in the MSYS2 install path and running the command pacman -Syu. If the msys2-runtime package is updated, close the shell and run msys2_shell.cmd.

Building

The following commands assume you are building for 64-bit Windows, and that you already have the KiCad source code in a folder called kicad-source in your home directory. See below for changes if you need to build for 32-bit instead. Run mingw64.exe from the MSYS2 install path. At the command prompt run the the following commands:

pacman -S base-devel \
            git \
            mingw-w64-x86_64-cmake \
            mingw-w64-x86_64-doxygen \
            mingw-w64-x86_64-gcc \
            mingw-w64-x86_64-python2 \
            mingw-w64-x86_64-pkg-config \
            mingw-w64-x86_64-swig \
            mingw-w64-x86_64-boost \
            mingw-w64-x86_64-cairo \
            mingw-w64-x86_64-glew \
            mingw-w64-x86_64-curl \
            mingw-w64-x86_64-wxPython \
            mingw-w64-x86_64-wxWidgets \
            mingw-w64-x86_64-toolchain \
            mingw-w64-x86_64-glm \
            mingw-w64-x86_64-oce \
            mingw-w64-x86_64-ngspice \
            mingw-w64-x86_64-zlib
cd kicad-source
mkdir -p build/release
mkdir build/debug               # Optional for debug build.
cd build/release
cmake -DCMAKE_BUILD_TYPE=Release \
        -G "MSYS Makefiles" \
        -DCMAKE_PREFIX_PATH=/mingw64 \
        -DCMAKE_INSTALL_PREFIX=/mingw64 \
        -DDEFAULT_INSTALL_PATH=/mingw64 \
        ../../
make -j N install   # Where N is the number of concurrent threads that your system can handle

# 手动配置opencascade   wxWidgets 
cmake -DCMAKE_BUILD_TYPE=Release \
      -G "MSYS Makefiles" \
      -DCMAKE_PREFIX_PATH=/mingw64 \
      -DCMAKE_INSTALL_PREFIX=/mingw64 \
      -DDEFAULT_INSTALL_PATH=/mingw64 \
      -DOCC_INCLUDE_DIR=/mingw64/include/opencascade \
      -DwxWidgets_CONFIG_EXECUTABLE=/mingw64/bin/wx-config-3.1 \
      -DwxWidgets_INCLUDE_DIRS=/mingw64/include/wx-3.1 \
      ../../

For 32-bit builds, run mingw32.exe and change x86_64 to i686 in the package names and change the paths in the cmake configuration from /mingw64 to /mingw32.

For debug builds, run the cmake command with -DCMAKE_BUILD_TYPE=Debug from the build/debug folder.

MSYS2 with CLion

KiCad in combiation with MSYS2 can be configured to be used with CLion to provide a nice IDE experience.

Toolchain Setup

First you must register MSYS2 as a toolchain, or namely, the compiler.

File > Preferences to open the Settings window.

Navigate to Build, Execution, Development and then the Toolchains page.

Add a new toolchain, and configure it as such

  • Name: MSYS2-MinGW64

  • Environment Path: <your msys2 install folder>\mingw64\

  • CMake: <your msys2 install folder>\mingw64\bin\cmake.exe

All other fields will become automatically populated.

Project Setup

File > Open and select the folder containing the kicad source. CLion may attempt to start CMake generation and fail, this is ok.

Open the Settings window again. Navigate to Build, Execution, Development and then the CMake page. These settings are saved to the project.

You want to create a Debug configuration as such

  • Name: Debug-MSYS2

  • Build-Type: Debug

  • Toolchain: MSYS2-MinGW64

  • CMake options:

-G "MinGW Makefiles"
-DCMAKE_PREFIX_PATH=C:/msys2-x64/mingw64/;C:/msys2-x64/mingw64/x86_64-w64-mingw32/
-DCMAKE_INSTALL_PREFIX=/mingw64
-DDEFAULT_INSTALL_PATH=/mingw64

-G "MinGW Makefiles" 
-DCMAKE_PREFIX_PATH=D:/msys64/mingw64/;D:/msys64/mingw64/x86_64-w64-mingw32/ 
-DCMAKE_INSTALL_PREFIX=/mingw64 
-DDEFAULT_INSTALL_PATH=/mingw64 
-DOCC_INCLUDE_DIR=D:/msys64/mingw64/include/opencascade 
-DwxWidgets_CONFIG_EXECUTABLE=/mingw64/bin/wx-config-3.1  
-DwxWidgets_INCLUDE_DIRS=/mingw64/include/wx-3.1
-G "MinGW Makefiles" 
-DCMAKE_PREFIX_PATH=D:/msys64/mingw64/;D:/msys64/mingw64/x86_64-w64-mingw32/ 
-DCMAKE_INSTALL_PREFIX=/mingw64 -DDEFAULT_INSTALL_PATH=/mingw64 
-DOCC_INCLUDE_DIR=D:/msys64/mingw64/include/opencascade 
-DwxWidgets_CONFIG_EXECUTABLE=/mingw64/bin/wx-config-3.1  
-DwxWidgets_INCLUDE_DIRS=/mingw64/include/wx-3.1 
-DMSYS=TRUE 
-DMINGW=TRUE 
-DCYGWIN=TRUE 
-DBoost_NO_BOOST_CMAKE=ON

  • Build-directory: build/debug-msys2

  • Environment:

PATH=C:/Windows/system32\;C:/msys2-x64/usr/bin\;C:/msys2-x64/mingw64/bin\;C:/msys2-x64/mingw64/x86_64-w64-mingw32/bin\;%PATH%
PATH=C:/Windows/system32\;D:/msys64/usr/bin\;D:/msys64/mingw64/bin\;D:/msys64/mingw64/x86_64-w64-mingw32/bin\;%PATH%

 

(Please replace C:/msys2-x64 in the CMake options and in the Environment PATH with your actual MSYS2 installation path.)

You may now trigger the "Reload CMake Cache" option in CLion to generate the cmake project You should delete the "junk" build folder (usually name cmake-build-debug-xxxx) it may have created in the source before it was changed above. We change the build folder because we have a gitignore for /build

Warning: Receiving warning messages about Boost versions is normal.

Known MSYS2 Build Issues

There are some known issues that are specific to MSYS2. This section provides a list of the currently known issues when building KiCad using MSYS2.

Building with Boost 1.70

There is an issue building KiCad with Boost version 1.70 due to CMake not defining the proper link libraries during configuration. Boost 1.70 can be used but -DBoost_NO_BOOST_CMAKE=ON needs to be added during CMake configuration to insure the link libraries are properly generated.

Building OCE from source

KiCad requires OCE by default, and the version installed by pacman can cause build errors in x86_64 systems as of March 2018. In order to work around this, you can build OCE from source on these systems. Building OCE on Windows requires that you place the source code in a very short directory path, otherwise you will run into errors caused by the maximum path length on Windows. In the example below, the MINGW-packages repository is cloned to /c/mwp, which is equivalent to C:\mwp in Windows path terminology. You may wish to change the destination of the git clone command if you do not want to place it on the root of your C drive, but if you run in to strange compilation errors about missing files, it is probably because your path is too long.

git clone https://github.com/Alexpux/MINGW-packages /c/mwp
cd /c/mwp/mingw-w64-oce
makepkg-mingw -is
### 如何在 CLion配置 MSYS2 环境 #### 配置步骤说明 在 Windows 下使用 CLion 进行 C++ 开发时,可以通过配置 MSYS2 来设置编译环境。以下是详细的配置方法: #### 1. 安装 MSYS2 工具链 首先需要安装 MSYS2配置其工具链。通过命令行依次执行以下命令以安装必要的组件[^1]: ```bash pacman -S mingw-w64-clang-x86_64-toolchain pacman -S mingw-w64-clang-x86_64-gdb ``` 这些命令将安装 Clang 编译器以及调试工具 GDB。 #### 2. 配置 CLion 的工具链 打开 CLion,进入 **设置** 菜单,并导航到 **构建、执行、部署 > 工具链**[^2]: - 点击加号(+)按钮,选择新增一个工具链。 - 将工具链类型设置为 **MinGW**。 - 在工具链的路径中指定 MSYS2 的安装目录下的 `mingw64` 文件夹位置。例如:`C:\msys64\mingw64`。 如果 CLion 自动检测到的 GCC 和 G++ 编译器路径不正确,可以手动修改这些路径。具体编译器和构建工具的可执行文件地址通常位于 MSYS2 安装目录下的 `mingw64\bin` 文件夹中。 #### 3. 配置 CMake 使用 MSYS2 工具链 确保 CLion 的 CMake 设置能够识别 MSYS2 的工具链。可以在项目的 `CMakeLists.txt` 文件中添加以下内容来指定 Boost 库的位置(如果项目需要 Boost)[^3]: ```cmake set(BOOST_ROOT "E:\\CLionProjects\\deps\\boost_1_77_0") set(BOOST_LIBRARYDIR "E:\\CLionProjects\\deps\\boost_1_77_0\\lib64-msvc-14.2") find_package(Boost 1.77 REQUIRED COMPONENTS filesystem) link_directories(${Boost_LIBRARY_DIRS}) include_directories(${Boost_INCLUDE_DIRS}) target_link_libraries(Project ${Boost_LIBRARIES}) ``` 请根据实际的 Boost 安装路径调整上述代码中的路径。 #### 4. 测试配置 完成上述配置后,可以创建一个简单的 C++ 项目并尝试编译运行。例如,以下是一个简单的测试代码: ```cpp #include <iostream> int main() { std::cout << "Hello, MSYS2 in CLion!" << std::endl; return 0; } ``` 如果一切配置正确,该程序应能成功编译并输出预期结果。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值