KiCAD source code for learning

Hi there,

I just downloaded source code of kicad (kicad-source-mirror-master). I want to look at the source code see if I can learn from it. I have the following questions.

  1. Is there any kind of flow chart for the software?
  2. Is there any document that show the structure of different pieces of .cpp codes? and explaining what .cpp does what?
  3. What kind of IDE can I use to edit source codes?
  4. What kind of compiler can I use to compiler all these codes?
  5. How to compiler the source codes?

Any other information that could help me dive in the source code would be very much appreciated. Thanks

Regards

Are you serious?

Look, I like your attitude, but you won’t succeed that way, not by a long shot.
Try it this way:

2 Likes

Take a look here
http://kicad-source-mirror.readthedocs.io/en/latest/Documentation/development/compiling/

this will get you started compiling from source, the rest is down to hard work, reading, finding and learning your way around the code base.

1 Like

Joan_Sparky is right if you already don’t know C++. If you do, read first the Contribute/Developers section of the Kicad web pages. Follow all the relevant links there. Then there’s at least one video: https://archive.fosdem.org/2017/schedule/event/kicad_source/.

1 Like
  1. no
  2. no
  3. any text editor
  4. officially? only GNU tools, GCC and CMAKE. Using Mingw32 on Windows… Unofficially there was an effort by Simon Richter to make it build on MSVC. https://code.launchpad.net/~sjr/kicad/msvc but not sure if it was discontinued (lots of support effort)
  5. see the link suggested by @slc; also, IMO, it is easier to build on Linux debian based (eg: ubuntu) distro.
1 Like

Hi,
KiCad is based on wxwidgets … So having a look at those would help…

https://www.wxwidgets.org/

Moreover if you are on windows, there is kicadwinbuilder that does all the job…
Then you can have a full building environment where to do your tests.

1 Like

KiCad uses CMake build system to compile the project. If you haven’t heard about it I suggest you check this first. You don’t have to be an expert on CMake to hack kicad source but knowing what cmake is and how to run it, is necessary. It’s not an IDE, it’s more like a scripting language for building C++ projects. Although its a command line application it also has a GUI that you can use. But don’t expect much from it. A great feature of CMake is that it can create ā€œprojectsā€ for many other IDE’s (Visual Studio, CodeBlocks etc.) so you can use an IDE if you want to. Some IDEs such as QtCreator and KDevelop can directly open CMake projects without any ā€œgenerationā€. I suggest you try KDevelop. My experience with it was great.

By the way in my opinion, building open source projects especially big ones such as KiCad is much easier on Linux operating systems compared to windows. Simply because its much easier to collect dependencies. As an every day linux user I might be biased though. Just saying…

Before you ā€œdiveā€ into the code, I suggest you pick a feature and try to hack it. You should have something in your mind that you want to improve. Otherwise you are going to get lost in the code. KiCad has a relatively big code base.

A warning, currently KiCad is under heavy development. Because of that there is a significant amount of duplicate code. Especially on the PCB side. In my experience, sometimes finding the corresponding code for a specific feature can be challenging. But once you do, hacking kicad isn’t so hard.

Good luck.

2 Likes

I guess I miscommunicated. My intention was not learning CPP itself but learning how KiCAD is implemented. I am not software engineer but I know or should say knew CPP once upon a time. Thanks anyway.

Thanks a lot for your help and time. I have not looked at the code base in detail yet. What I want to do is to take a feature, for example schematics, strip it to the basic level and then start from there. I had studied CPP at university and my skill level, I guess is at intermediate level. At this point I am trying to learn. I am using Windows 10 and have not had Linux on my system for many years. Is it possible to use a windows based IDE like Visual Studio? Thanks

kicad winbuilder will give you a MSYS environment

1 Like

I searched the web and I came across only the source codes. Where can I get a binary version of kicad winbuilder? Thanks

you need to read instructions…
this is not going to be a ā€˜usual’ windows programs approach like install and run :wink:

2 Likes

In theory yes. CMake can create Visual Studio projects. But that’s the easy part. CMake cannot guarantee that visual studio can build the generated project. First of all, codebase should be compatible with compiler used by visual studio. I don’t see why it shouldn’t be. But sometimes projects use specific features of a compiler (say gcc) and you may have trouble with other compilers. It’s generally a good idea to use the compiler that is used by the developers of the software, if possible. My advice is that don’t insist on an IDE at the beginning. Start with the command line, use a text editor designed for programmers (notepad++, sublime etc).

The other issue is the library dependencies. CMake doesn’t automatically download and prepare dependencies (unless it’s scripted to do so). That’s usually the hard part. I’ve never used the kicad-winbuilder, but I’m guessing it’s a tool to download everything necessary and setup an environment for building KiCad. It’s written as a CMake script. That’s why there is no binaries for it. It’s a script that is run with CMake.

winbuilder, setups an environment based on MSYS2. This is a platform for building and running linux software on Windows. It’s great because it provides tools that usually exist in linux operating systems. Such as a package manager which makes it very easy to download and install library dependencies. But these tools are actually windows native software so they can be run like any other EXE. Also software that is built under msys2 will run like a native software. I use msys2 to create windows binaries for my projects. A small warning, in my experience setting up msys2 requires a lot of download = ~5GB at least. Make sure you have good connection.

2 Likes

You will discover that the coding styles that coders use for real work is different than what you would use if you were writing code for a compSci textbook.

1 Like

I also recommend KDevelop. Actually it can be run on Windows: https://www.kdevelop.org/download. It gives great amount of information with mouse-hover-over and you can jump back and forth in the codebase easily. Modern IDEs are from another world than trying to get familiar with the code base with only a text editor (even an advanced one). I would never try the latter after using modern IDEs.

Reading/editing the code and compiling it are of course two different things; maybe it’s possible to use Visual Studio for reading and editing and MSYS environment for building.

Because we are talking about KiCad code base I would add ā€œto put it mildlyā€.

2 Likes