Use the CMAKE_EXPORT_COMPILE_COMMANDS Parser for adding the include dirs to the CDT Configuration?

93 views
Skip to first unread message

peter....@gmail.com

unread,
Apr 11, 2019, 8:21:05 AM4/11/19
to cmake4eclipse user mailing list
Hi,

this is my setup:
Eclipse Neon 4.6.3
Eclipse CDT 9.2.1
cmake4eclipse 1.14.0
CMake 3.12.2

I am adding some include directories in the CMakeLists.txt with

target_include_directories(${THETARGET} PUBLIC ${THE_INCLUDE_DIRS})

Building works, and all header files within the project are indexed/found so when i click on a #include i can navigate to the header file.

Now i want to use SonarLint for static code analysis which is an Eclipse Plugin to basically run SonarQube locally. It requires the include directories being configured/present in the CDT project configuration. When i add all the include dirs manually with "Properties" -> C/C++ General -> Paths and Symbols -> Includes it works but it would be great if the include dirs would be added automatically by the cmake4eclipse plugin.

Is this maybe already possible, planned or out of scope?

I already enabled the "CMAKE_EXPORT_COMPILE_COMMANDS Parser" but this had no effect.

thx,
Peter

Martin Weber

unread,
Apr 11, 2019, 2:30:01 PM4/11/19
to cmake4ecl...@googlegroups.com
Am Donnerstag, 11. April 2019, 14:21:05 CEST schrieb peter....@gmail.com:
> Hi,
>
> this is my setup:
> Eclipse Neon 4.6.3
> Eclipse CDT 9.2.1
> cmake4eclipse 1.14.0
> CMake 3.12.2
>
> I am adding some include directories in the CMakeLists.txt with
>
> target_include_directories(${THETARGET} PUBLIC ${THE_INCLUDE_DIRS})
>
> Building works, and all header files within the project are indexed/found so
> when i click on a #include i can navigate to the header file.
>
> Now i want to use SonarLint for static code analysis which is an Eclipse
> Plugin to basically run SonarQube locally. It requires the include
> directories being configured/present in the CDT project configuration. When

Does it really required that? If so, SonarLint would not know about the
include paths built in to the gcc compiler.

> i add all the include dirs manually with "Properties" -> C/C++ General ->
> Paths and Symbols -> Includes it works but it would be great if the include
> dirs would be added automatically by the cmake4eclipse plugin.
>
> Is this maybe already possible, planned or out of scope?
>
> I already enabled the "CMAKE_EXPORT_COMPILE_COMMANDS Parser" but this had no
> effect.

Not quite sure what 'no effect' does refer to. The purpose of the
"CMAKE_EXPORT_COMPILE_COMMANDS Parser" is to tell the CDT indexer about the
target_include_directories(). The includes show up in the Preprocessot Include
Paths, Macros etc page in the project configuration.

Martin


--
Cd wrttn wtht vwls s mch trsr.




Peter Bauer

unread,
Apr 12, 2019, 4:55:56 AM4/12/19
to Martin Weber, cmake4ecl...@googlegroups.com
Hello Martin,

Am Do., 11. Apr. 2019 um 20:30 Uhr schrieb Martin Weber <fifteen...@gmail.com>:
[...] 
> Now i want to use SonarLint for static code analysis which is an Eclipse
> Plugin to basically run SonarQube locally. It requires the include
> directories being configured/present in the CDT project configuration. When

Does it really required that? If so, SonarLint would not know about the
include paths built in to the gcc compiler.

When a file is analyzed by SonarLint it reports an error that it is not able to find the respective .h file which is included in the .c file and the results of the analysis are incomplete. When i then manually add the folder containing the .h file to the include dirs as described below there is no error and the results are correct. This is also what the support of SonarSource said: the include dirs need to be present in the Eclipse CDT project configuration.
 
> i add all the include dirs manually with "Properties" -> C/C++ General ->
> Paths and Symbols -> Includes it works but it would be great if the include
> dirs would be added automatically by the cmake4eclipse plugin.
>
> Is this maybe already possible, planned or out of scope?
>
> I already enabled the "CMAKE_EXPORT_COMPILE_COMMANDS Parser" but this had no
> effect.

Not quite sure what 'no effect' does refer to. The purpose of the
"CMAKE_EXPORT_COMPILE_COMMANDS Parser" is to tell the CDT indexer about the
target_include_directories(). The includes show up in the Preprocessot Include
Paths, Macros etc page in the project configuration.

"No effect" means that the include dirs do not appear in the list of include dirs of the project as you wrote (please see the attached screenshots) and that SonarLint is still not able to find the .h files in the include dirs.
So to recap: When enabling the "CMAKE_EXPORT_COMPILE_COMMANDS Parser", the include dirs should automatically be added to the project configuration and appear in the list?
Can i debug this somehow to find out why it is not working for me?
 
thx,
Peter

Martin


--
Cd wrttn wtht vwls s mch trsr.




--
You received this message because you are subscribed to the Google Groups "cmake4eclipse user mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cmake4eclipse-u...@googlegroups.com.
To post to this group, send email to cmake4ecl...@googlegroups.com.
Visit this group at https://groups.google.com/group/cmake4eclipse-users.
For more options, visit https://groups.google.com/d/optout.
eclipse_include_dirs_empty.PNG
entries.PNG

Martin Weber

unread,
Apr 12, 2019, 3:01:23 PM4/12/19
to cmake4ecl...@googlegroups.com
Am Freitag, 12. April 2019, 10:55:43 CEST schrieb Peter Bauer:
> Hello Martin,
>
> Am Do., 11. Apr. 2019 um 20:30 Uhr schrieb Martin Weber <
> fifteen...@gmail.com>:
> [...]
>
> > > Now i want to use SonarLint for static code analysis which is an Eclipse
> > > Plugin to basically run SonarQube locally. It requires the include
> > > directories being configured/present in the CDT project configuration.
> >
> > When
> >
> > Does it really required that? If so, SonarLint would not know about the
> > include paths built in to the gcc compiler.
>
> When a file is analyzed by SonarLint it reports an error that it is not
> able to find the respective .h file which is included in the .c file and
> the results of the analysis are incomplete. When i then manually add the
> folder containing the .h file to the include dirs as described below there
> is no error and the results are correct. This is also what the support of
> SonarSource said: the include dirs need to be present in the Eclipse CDT
> project configuration.

I cannot believe Sonarlint is limited to the the include paths manually
entered in the CDT project. If it were, it would not find the standard include
dirs, too.
See below.
...

> > target_include_directories(). The includes show up in the Preprocessot
> > Include
> > Paths, Macros etc page in the project configuration.
>
> "No effect" means that the include dirs do not appear in the list of
> include dirs of the project as you wrote (please see the attached
> screenshots) and that SonarLint is still not able to find the .h files in
> the include dirs.
> So to recap: When enabling the "CMAKE_EXPORT_COMPILE_COMMANDS Parser", the
> include dirs should automatically be added to the project configuration and
> appear in the list?

Yes. And Sonarlint would pick them up.

> Can i debug this somehow to find out why it is not working for me?

The "CMAKE_EXPORT_COMPILE_COMMANDS * Parser" reports problem with Info
severity. You might want to see these in this case:
In the Problems view, change the filter to also show messages of Info severity
and make sure the Location column is shown.
The delete the generated CMakeCache.txt file in the build directory and re-
build.
Probably your compiler is not recognized so you will find a message
complaining about that.

barret...@gmail.com

unread,
Sep 25, 2019, 9:19:07 AM9/25/19
to cmake4eclipse user mailing list

How hard would it be to add my own parser? I'm using IAR...

It's been a while since I've developed any java and I've never written any plugin for eclipse...How hard could it be right? ;)

No, seriously - am I biting off way more than I can chew?

15 knots

unread,
Sep 25, 2019, 3:37:06 PM9/25/19
to cmake4eclipse user mailing list
Am Mi., 25. Sept. 2019 um 15:19 Uhr schrieb <barret...@gmail.com>:
>
>
Please have a look at a possible solution here
https://github.com/15knots/cmake4eclipse/issues/117#issuecomment-530459927
and look at the image in the first post.

> How hard would it be to add my own parser? I'm using IAR...

You will have to know about java regex, at a minimum. At you will need
the compiler manual to know the command-line options.

What is IAR?

>
> It's been a while since I've developed any java and I've never written any plugin for eclipse...How hard could it be right? ;)

Depends on your experience.

Martin

barret...@gmail.com

unread,
Sep 30, 2019, 11:42:57 PM9/30/19
to cmake4eclipse user mailing list
IAR is a commercial compiler for cross compilation. https://www.iar.com/iar-embedded-workbench/

I'd prefer using a compiler that is open source and has more community exposure, plugins for IDEs, etc. I'll take a look and make a contribution if I get around to it. There's lots on my todo list and this doesn't quite top the other items :) 


On Wednesday, September 25, 2019 at 2:37:06 PM UTC-5, 15 knots wrote:
Reply all
Reply to author
Forward
0 new messages