Creating a complex project file(s) for an existing large project

René J.V. Bertin rjvbertin at gmail.com
Tue Aug 3 17:53:11 BST 2021


On Tuesday August 03 2021 17:34:10 Sven Brauch wrote:

>The code analysis is more complicated. For this, KDevelop needs to know 
>your compiler flags, your defines, and your include directories. You can 
>either configure them manually in the project settings, or port your 
>build system to something understood by KDevelop (probably CMake).

IIRC, someone developed a plugin (or hacked an existing one) to allow the import of projects that have a compile_commands.json database. It would be nice to have such a plugin in the official release but I'm not aware that any work has been done towards that.
I do recall discussing (on here) a utility that creates such a database from the output of make, typically of a complete build run (but it's long ago enough that I can't remember details like the name of that utility).

Either way, this gives you a backdoor allowing to see how well KDevelop could suit your need:
- make sure KDevelop uses a CMake version that is 3.0.1 or less; that way the CMake server mode import will be deactivated and the old compile_commands.json based importer will be used (which is also a lot faster ;-) )
- create a simple minimal CMakeLists.txt that doesn't have to do anything, just not raise an error; run CMake on it in the desired build directory so a CMakeCache.txt file is created
- re-run configure to recreate the Makefile, and then generate a compile_commands.json file using a utility like mentioned above
- import the project using that CMakeLists.txt file and (presumably) the source directory as the build directory

The CMake import wizard should now realise that you are importing an already configured project + build dir, and NOT invoke CMake; instead it will obtain most if not all project information from the compile_commands.json file.

I've done similar things for simple autoconf based projects. It's not idea, but it's a way out if you don't want to bother writing a CMakeLists.txt file (or one of the equivalents that KDevelop supports, meson for instance) but still want to get code parsing that is relevant for how you're building your code.

Caveat emptor: if your project is really big and/or your compile commands really long this may not work. KDevelop uses Qt's json parser which has an internal size limit and just fails if the input file is over that limit.

R



More information about the KDevelop mailing list