← Back to team overview

kicad-developers team mailing list archive

Using Visual Studio 2017 CE for KiCad development

 

Hi all,

I've managed to get KiCad code base to build in VS 2017 and more
importantly be parsed
by intellisense. Thought I'd share the config for other windows devs.

I've been using Atom so far with relative success but it's not great.
Decided to try if KiCad can
be worked on in real IDE with contextual autocomplete that works.

MS has been investing in building support in Visual Studio for non ms build
systems. GCC,
clang, cmake, non x86 targets, all of this has been coming along in recent
releases.
Not everything works like in ms build projects, but it's still miles ahead
of generic text editors.

Prerequisite: have msys2 windows environment with working KiCad build.

Get VS 15.8.0 or later. I've tested this on 15.8.1 community edition
preview. (It's free).

Install additional components:
Linux development with C++
Visual C++ tools for CMake and Linux

Then open VS and go to File -> Open... -> CMake...
select CMakeLists.txt in KiCad src root.

Next go to CMake -> Change CMake Settings -> CMakeLists.txt
In popup window choose Mingw64 Release (or Debug)
A file named CMakeSettings.json will be created and you have to tweak a few
things.
I've attached my CMakeSettings.json for reference but the important bits
are:

configurations.environments.MINGW64_ROOT - this is path to your mingw64
folder
configurations.environments.FLAVOR - mingw flavor, I use x86_64-w64-mingw32
configurations.environments.TOOLSET_VERSION should be autodetected, if not
check
    mingw64\lib\gcc\x86_64-w64-mingw32 folder for version. It's 7.3.0 for me
configurations.environments.INCLUDE - add ${env.MINGW64_ROOT}\\include to
the list
configurations.generator - I set it to "MSYS Makefiles" and VS frowns on it
but it works.
    Maybe "Unix Makefiles" work too, I didn't check.
configurations.cmakeCommandArgs - this is the tricky one that I had to do
trial and error
   dance with a lot and also read cmake find rules that don't always work.
I found this
   combination to do the job:
   "-DCMAKE_PREFIX_PATH=${env.MINGW64_ROOT} -DMINGW:STRING=TRUE
    -DMSYS:STRING=TRUE -DCYGWIN:STRING=TRUE
    -DOPENGL_INCLUDE_DIR=${env.MINGW64_ROOT}\\include",
configurations.buildCommandArgs - remove the "-v" that VS puts there, it
just prints version
    for make. I put "-j6" instead to speed up the build.
configurations.intelliSenseMode - VS should auto fill this to
"linux-gcc-x64"

Remaining configs can be left default, or you can tweak them to your taste.

After you save the CMakeSettings.json VS will automatically regenerate
CMake cache.
Go to CMake menu and you can build all targets or specific ones from there.
In my case intellisense only picked up cache after I did full build, so
maybe it is required
to do at least once.

But result is so worth it:

[image: intellisense.png]

Hope this helps!

Regards,
Andrew

PNG image

Attachment: CMakeSettings.json
Description: application/json


Follow ups