Creating a C/C++ system is a bit more complex than creating a system for other languages. First we need to select or create a compiler definition. Then we need to define the required include directories for each module as well as the macro definitions required for conditional compilation. Sometimes it is also necessary to exclude certain compilation units from modules. The "Create New C/C++ System..." wizard gives you maximum flexibility to specify all that. But if you use CMake or Visual Studio you can also import the system more conveniently.
The first page of each C/C++ system creation wizard will allow you to select an existing compiler definition or create a new one. If you decide to create a new compiler definition the next wizard pages will guide you through this process step by step.
If you use the "Create New C/C++ System..." wizard please make sure to select the root directory of your system as the storage location for the Sonargraph folder. Only source files located directly or indirectly under this directory can be added to the system. The wizard will scan all files under this directory for "#include" statements and will try to locate the referenced include files. The scanner does NOT consider conditional compilation, so you might see lots of irrelevant unresolved include references that you can ignore safely. By adding additional include folders you can make sure that all relevant include references can be resolved.
While we provide many different choices for C/C++ project setup I recommend to use the ccspy wizard (see below) for project setup. The documentation for ccspy can be found here: https://github.com/sonargraph/ccspy. The basic idea is that ccspy works as an intermediary between your build tool (e.g. make) and your compiler. Each time a file is compiled ccspy will record the used compiler options in a file in the ccspy target directory, which will then be used by Sonargraph to analyze your project.
Here are the other wizards to create new C/C++ systems:
-
System based on C/C++ CMake JSON command file: Allows to create a system out of a generated compile command JSON file.
Name your new system and choose a directory to store it. In the next wizard page you need to choose the location of your JSON command file. To generate such a file you need to run cmake with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON.
The next wizard page presents the root directories found in the JSON file and allows you to fine tune those directories and sub-directories you want marked as root directories or excluded in the resulting system. You need to mark at least one root directory:
The final page of the wizard allows to give a name to each one of the modules that will be created out of the root directories marked in the previous step. Sonargraph will try to guess a module name out of the root folder name. You are able to change that name if it should not fit.
-
System based on ccspy target directory: Works pretty identical to the cmake JSON importer (see above), except that you have to specify the ccspy target directory. Make sure to build your system before you analyze it to ensure the most up-to-date input.
-
System based on C/C++ Visual Studio 2010 (or newer) Solution file: See Section 7.2.1, “ Importing C++ Modules from Visual Studio Files ”
Most wizards are similar whether you create a new system or add modules to an existing system.