I am using the gcov sensor and the build-wrapper to analyse the code.
The code is laid out in several "modules" that each has a directory in the top level. Inside each directory is a further directory with source code and a directory with test code.
i.e.
./module1
./module1/source
./module1/test
./module2
./module2/source
./module2/test
Both the source and test code are C++. GNU Make is used to run the compilation. Each module can be compiled separately or the whole thing can be built from the top level. Sometimes there is an Application directory if the module generates a shared library and an executable.
For the first module I can see the following warnings while the analyser runs:
10:52:12.612 DEBUG: 'Swift Squid Sensor' skipped because there is no related file in current project
10:52:12.614 DEBUG: Sensors : gcov -> SonarJavaXmlFileSensor
10:52:12.614 INFO: Sensor gcov [cpp]
10:52:12.617 INFO: Sensor gcov [cpp] (done) | time=3ms
10:52:12.618 INFO: Sensor SonarJavaXmlFileSensor [java]
10:52:12.618 INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms
10:52:12.631 DEBUG: 'module1/sources/ACompiledFile.cpp' generated metadata with charset 'US-ASCII'
For the second module I see
10:52:12.799 DEBUG: 'Swift Squid Sensor' skipped because there is no related file in current project
10:52:12.800 DEBUG: Sensors : gcov -> SonarJavaXmlFileSensor
10:52:12.800 INFO: Sensor gcov [cpp]
10:52:12.801 INFO: Sensor gcov [cpp] (done) | time=1ms
10:52:12.801 INFO: Sensor SonarJavaXmlFileSensor [java]
10:52:12.801 INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms
10:52:12.804 DEBUG: 'module2/source/file1.cpp' generated metadata with charset 'US-ASCII'
10:52:12.807 DEBUG: 'module2/source/file2.cpp' generated metadata with charset 'US-ASCII'
10:52:12.809 DEBUG: 'module2/source/file2.h' generated metadata with charset 'US-ASCII'
10:52:12.815 WARN: Invalid character encountered in file module2/source/file3.cpp at line 361 for encoding US-ASCII. Please fix file content or configure the encoding to be used using property 'sonar.sourceEncoding'.
10:52:12.819 DEBUG: 'module2/source/file3.cpp' generated metadata with charset 'US-ASCII'
10:52:12.820 DEBUG: 'HeliosEmulator/Tests/MyOwnNewMacros.h' generated metadata with charset 'US-ASCII'
When I check the SonarQube dashboard for the project there is no coverage data reported.
My current sonar-project.properties file reads as:
# must be unique in a given SonarQube instance
sonar.projectKey=MYPROJ
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=My Project
sonar.projectVersion=0.0.0
# Project Link Data
sonar.projectDescription=Code that will run
# List of the module identifiers
sonar.modules=module1,module2
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=./Sources,./Tests
module2.sonar.sources=./Application,./Sources,./Tests
sonar.cfamily.build-wrapper-output=build_output
# Exclude 3rd Party Code
# path to test source directories (optional)
#sonar.test.inclusions=Tests/
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
# Existing reports
sonar.cfamily.build-wrapper-output=build_output
#sonar.cfamily.cppunit.reportsPath=junit
sonar.cfamily.gcov.reportsPath=.
#sonar.cxx.cppcheck.reportPath=cppcheck-result-1.xml
#sonar.cxx.xunit.reportPath=cpputest_*.xml
sonar.junit.reportPaths=junit
As the above suggests; I did initially try setting things up with cppcheck and the community wrapper. The company I work for has purchased SonarQube and has stated they would like me to use the official wrapper instead.
The gcov files are listed in each module's root directory. Before this I tried generating them from the top level directory and haveing all the code analysed as a single module. I got error messages about the system being unable to find the related source files though. I beleive this was becase gcov was being run from the top level directory, when gcc was being called from inside each module directory. The gcov documentation states that it must be run from the same directory as GCC.
After I get the test coverage working, it would be good to get test results recorded as well. That is a separate issue and as the code uses the CppUTest framework I do not have a xunit style report to feed in.
Any help or advise that people can probvide will be very greatfully recieveied. I have not managed to find much about using SonarQube with C++ at all on my websearches.