Thursday, April 6, 2023

Building KiCad from Source

KiCad has become increasingly capable of taking on large PCB designs.  It's good to take a look at the source code.  We'll try to the build on Ubuntu 20.04.  The latest version is 7; and the work on version 8 has begun.  The source code is cloned, `git clone --filter=blob:none https://gitlab.com/kicad/code/kicad.git`; we use the filter to keep the repo small, still it is almost 400MB. 

The next is to install all the necessary libraries, wxWidgets, Boost C++, GLEW, ZLib, GLM, GLUT, Cario 2D Graphics, OpenCascade, ngspice, curl, wxpython

libbz2-dev, libcairo2-dev, libglu1-mesa-dev,  libgl1-mesa-dev, libglew-dev, libx11-dev, libwxgtk3.2-dev, mesa-common-dev,  libssl-dev, python3-dev,  python3-wxgtk4.0, libboost-all-dev, libglm-dev, libcurl4-openssl-dev,  libgtk-3-dev, ngspice-dev, libngspice0-dev, libocct-modeling-algorithms-dev, libocct-modeling-data-dev, libocct-data-exchange-dev, libocct-visualization-dev, libocct-foundation-dev, libocct-ocaf-dev, unixodbc-dev, zlib1g-dev

The KiCad 7 requires  wxwidget 3.2, which is not in the Ubuntu repositories.  We have to get an unofficial release from https://repos.codelite.org/wx3.2.0/ubuntu/.  And wxpython version 4.0 has to be installed and built against wxwidget 3.2.

And some tools, 

cmake, doxygen, build-essential, pkg-config, source-highlight, cmake-curses-gui, debhelper, swig4.0, dblatex, po4a, asciidoc, shared-mime-info

To make the build faster, we'll use ninja as the build system and lld as the loader.

cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DKICAD_USE_EGL=ON -DCMAKE_INSTALL_PREFIX=/opt/kicad -DCMAKE_CXX_FLAGS=-fuse-ld=lld ../../

Then kick off the build with ninja.  The build process took a hour and half on my computer.   The build files total 11GB.   The installed files are almost 3GB, without symbol and footprint libraries which are on a separate repository.  The files are large because we build with debugging info.  

To make a smaller release build, 

cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DKICAD_BUILD_QA_TESTS=OFF -DKICAD_USE_EGL=ON -DCMAKE_INSTALL_PREFIX=/opt/kicad -DCMAKE_CXX_FLAGS=-fuse-ld=lld ../../

This only takes about half an hour, with the build files total 600MB and the installed files less than 300MB.  The executables are much smaller in size.

No comments:

Post a Comment