Developing KiCad: Configure an IDE

Hey guys,

I wanted to start tinkering with the source and see if I can fix some easy bugs.
The doc gives me everyone a basic idea what is needed to start compiling KiCad from source.

A good IDE helps out a lot while developing and debugging.
I wanted to document the way to set up a environment for beginners like me, that have a basic understanding of C++ and CMake but did probably not work with such a big project.

Please note that I am developing on linux.

There are a lot of different IDEs out there. I am used to Eclipse, but this mail and the general good reviews made me pick QTCreator as an IDE.

The start of everything is by downloading the sourcecode.
I will put everything into a folder in my home

mkdir KiCad
cd KiCad
git clone https://gitlab.com/kicad/code/kicad
cd kicad

Now we will create additional folders for the project file, the build folders and where the binarys are placed.

mkdir qtcreator
mkdir -p build/release/bin
mkdir -p build/debug/bin

After this we need to create our build configuration with CMake.
I will just show how it is done for a debug build.
For a good overview over the build-options you can view the CMakeLists and/or the Compile Option Symbols
I do not want to install the compiled program into my standard directories, so I will install them into build/debug/bin

cd build/debug
cmake -DCMAKE_INSTALL_PREFIX=/path/to/KiCad/kicad/build/debug/bin/ -DCMAKE_BUILD_TYPE=Debug
…/…/

Now a lot of missing dependencies will pop up.
To find out what packages you are missing, you have several options (at least under ubuntu):

apt search themissingpackagename

And now you have to look for the right package. You are generally looking for somithing like:

libyourpackage-dev
or
youpackage

For other systems or for packages where you are not sure, just search the missing dependency and the name of your system and you will most likely see what is needed to install them.

After some time and installing you will have a successful make run.

Now you can open up QtCreator and follow the guide of the mail:

QtCreator > New > Import Project > Import Existing Project
Projekname: KiCad
Location: /path/to/KiCad/kicad/qtcreator

Next

Files: /path/to/KiCad/kicad/qtcreator

Next

disable Git

Finish

Go to project KiCad > right click > add existing directory
sourcedirectory: /path/to/KiCad/kicad > Start Parsing > check checkbox

ok
(…wait…)

Now we can configure our build setting as we need them to be.
For this we go into the project tab.
(Sorry for the german, I think you get the basic idea nonetheless)


With this you should be able to comile, run and debug your code.
Just choose the configuration you just made with this button:
grafik
And click the hammer.
You should be able to open the compile window (bottom of the window, tab 4) and see how it is building.


There are a view things left I (currenttly) could not figure out.
E.g. the IDE does not resolve wx libraries, although it compiles them.

If anyone has an idea please let me know.
It should work in theory, at least according to: QtCreator External Lib


If anybody wants to add a guide for other IDEs, please post them here or link them.

3 Likes

If you thinker with the source code you may want to fork it in gitlab and use the workflow where you can later publish your changes and even make merge requests. If you do that, you can also use the wiki of your fork. That may be a better place to write articles like this, although a post can be made a wiki here, too.

I did that for an article about making documentation changes, it can be found in my documentation fork here: https://gitlab.com/eelik-kicad/kicad-doc/-/wikis/Contribute-to-KiCad-documentation-through-GitLab.

2 Likes

Thanks Herstrat, you’ve just defined me :slight_smile: I’ll try your tutorial right after finding a chance.

I’ve gone through a lot of different IDEs to find best experience working on KiCad code. Here are my impressions:

  • KDevelop - free, good syntax parser and navigation but works well only on Linux, needs a lot of ram, very slow indexing
  • CLion - costs $$, great navigation and refactoring, somewhat slow, works well on Linux and Windows, doesn’t support any build system except for make (I think latest release has ninja support but I moved on already)
  • Visual Studio - free (community edition), buggy cmake support, can’t make intellisense see some headers, works only on Windows
  • VSCode - free, great syntax parser, decent navigation, not so great refactoring utilities, works well and consistently on Linux and Windows, supports variety of build systems (I use ninja because it’s faster than make)

So I stopped on VSCode now and use it for all C++ development. Platformio for embedded code works great on it too.

3 Likes

Don’t want to derail the discussion but also curious about your embedded development experience with PlatformIO. Looking interesting.

You don’t happen to have an idea why QtCreator does not find the libs to the external wx libs?

“Starter” bugs can be found here:

These are not the only bugs fitting for beginners, someone just has taken time to mark them as such.

@herostrat, thank you for documenting your build attempt. Have you kept track of how many MiB/GiB of hard drive space all these tools and libraries occupied on your machine? I gather your /Kicad/kicad/ directory structure was to isolate your build attempt (source plus binaries plus executable) from a working production-version kicad you already had installed on your machine ? Did you succeed in making new executable code?

Does anybody think I can compile the existing code into an executable in linux without using an IDE ? Just using gcc, g++, and cmake? Thus far, I have only used make. I have never used cmake.

Yes, of course. It’s “offcially” documented here: https://docs.kicad.org/doxygen/md_Documentation_development_compiling.html but I think it’s not easy to read and understand. Compiling on e.g. debian has been discussed here before.

Thanks, eelik. Is there a way to create another kicad executable, without overwriting my existing production-version ( Version: 5.1.5+dfsg1-2~bpo10+1, release build ) when I do the #make install ?

@herostrat I’m not that familiar with Qt Creator (I mostly use CLion and Visual Studio these days) but some IDEs have separate path configuration for the “code intelligence” features than are actually used for compilation. Probably what is going on is that CMake can find the WX headers, but Qt Creator cannot. You may need to add things to INCLUDEPATH in your .pro file or something like that.

Pass your desired install path to cmake using -DCMAKE_INSTALL_PREFIX=<whatever>

2 Likes

Do you have suggestions about making it easier? The documentation can always be updated.

First of all it should be split into three, one for each platform (Win, Lin, Mac). After that it would be much easier to follow. I would even go as far as having separate documents for different Linux distros, even if it creates duplicated text.

EDIT: part of the documentation for Debian is here: https://kicad.org/download/debian/. But I don’t know if it’s up to date; and I have proposed a better alternative for installing the dependencies easily without knowing what they are.

Hey Russ,
yes that is possible and was done in my writeup.
As already mentioned the -DCMAKE_INSTALL_PREFIX does define where the binaries are stored after comiling.
So no official builds are overwritten or modified.

As for my attempt, the total sizes if I compile KiCad in Release and in Debug Mode, together with the sourcecode and objectcode (so everything I need to compile run and debug everything) I get around 8GiB diskspace and I cannot see any (major) difference in RAM usage for a live debugging.

1 Like

Yeah I thought so too, unfortunately I am too blind to see and to stupid to correctly search for a solution.
ATM it is just an inconvenience but I hope someone who reads this has an idea :slight_smile:

That is one way, but if you are using one of the supported KiCad linux versions (currently only Ubuntu and Fedora, I haven’t done Debian yet), you can try the scripts that I have been putting together to build out CI docker containers to build and test KiCad in the code repository. They are available here: https://gitlab.com/kicad/kicad-ci/source_containers/tree/master/scripts. This has several options for different packages to install (such as different Python versions, OCE, OCC, with/without ngspice, etc.), and also includes tooling for compiling, debugging, and doing the formatting checks. (note: ngspice on Ubuntu 18.04 is somewhat problematic, and requires some after-processing that is done in its dockerfile not in the install script). Or, if you are feeling adventurous and have used containers before, you can even try to use the actual containers from that repository. I know that KiCad can successfully configure on each container, and builds fine on Fedora (I haven’t run the build on the Ubuntu container yet).

If you want to have different versions (e.g. both 5.1 and master) installed side-by-side, I would suggest that you also use the CMake variable -DKICAD_CONFIG_DIR=<wherever> to separate the configuration files for the two.

All of the KiCad dependencies can take upwards of 700-800MB of space on an install. (The Ubuntu containers increased from 25MB to 646MB with everything installed, and Fedora increased from 63MB to 733MB with everything installed). The actual compiled code can be upwards of 6-8GB for the debug builds, and probably around half to 3/4 of that for release builds.

Edit:

Splitting by platform would work, but I would suggest we avoid splitting by the Linux distros. We could just provide the dependency list, and then link to the CI install scripts for the dependency installation for each OS. I would like to avoid hard-coding the package names into the docs if at all possible. After dependency installation, all linux builds will basically be the same.

At least in debian and fedore package systems (.deb and .rpm) based distros) there is a way to install build dependencies - and not only libraries, but build systems etc. - as long as prepackaged nightly builds are available for the platform. I would document that. It’s been explained in some forum threads.