Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] cmake support how to integrate the compile_commands.json parser into CDT

Hi Alexander,

Am Mi., 17. Juni 2020 um 09:31 Uhr schrieb Alexander Fedorov
<alexander.fedorov@xxxxxxxxxx>:
>
> Well, currently all these parts, such as the "server" and "front-end", are managed from the IDE.
> For example if user adds the source file - it needs to be added to json as well, and we need to guess the commands for this new unit, and for this we need to know how the surrounding units are configured.

Just *creating* a source file does not *add* it to the files that get
compiled. Cmake users must modify the CMakeLists.txt file to have the
new file compiled:
For example
add_executable(myExe main.c)
must be changed to
add_executable(myExe main.c newfile.c) in that case.
When the next build of the project is triggered, the build scripts
generated by cmake will detect the modification and will call cmake
which then re-creates the  cc.json (and the CMakeCache.txt file). The
updated cc.json file then contains a new section for the newly created
source file.

I admit this scenario is not covered by the new indexer support
bundles: If a user created a new source file and opened it in the
editor, there will be no syntax highlighting support for that file in
the editor until that file has been added in a CMakeLists.txt to the
files-to-be-built and a build was performed.

> we need to guess the commands for this new unit, and for this we need to know how the surrounding units are configured.

I agree. Unfortunately, commpile_commands.json gives us just a list of
files to compile along with the compiler options. No /surrounding
units/ to guess options from.
But we could assume that each file in a given directory gets the same
compiler options. Then we could implement a guessing strategy based on
the file system path of the newly created file and its files
extension. The strategy would take the compiler options of the
first/last source file with the same extension found in
the files parent directory. (Other strategies are conceivable; it's a
temporary guess)

Martin


Back to the top