C++/CMake Analysis with Code Variants

Hi all,

I am building an open-source project with Travis and followed the guides to also scan it with SonarCloud.
The project is written in C++ and CMake.
There are basically two variants of the software, that are chose by a CMake define (cmake -D…).
Depending on this define, different Source Files are build.
What I managed to do is to run two jobs in Travis consecutively (one for each variant) and wrap the build with the sonar scanner.
In the Travis logs both variants complete and it seems both sonar results are uploaded.
However, in the Sonar Project I do only see results (bugs, smells, etc.) for the second variant, the code of the first seems not to be checked.

Is it the correct approach to analyze such a project structure?
Or do I need to analyze both variants within one build?
That would not make any sense from functional point of view, but I could manage to do so using wrappers/mocks, etc.

  • ALM used: GitHub
  • CI system used: Travis CI
  • Scanner command used: sonar-scanner -Dsonar.cfamily.cache.enabled=true -Dsonar.cfamily.cache.path={TRAVIS_HOME}/.cfamily -Dsonar.cfamily.threads={NUMBER_OF_PROCESSORS}
  • Languages of the repository: C/C++
  • Only if the SonarCloud project is public, the URL: https://sonarcloud.io/dashboard?id=tiolan_imqtt

Hi @tiolan,

I guess you are talking about https://github.com/tiolan/imqtt/blob/dae989c01a943144cc28296933016915bb8122c8/.travis.yml.

Are the set of source files disjoint between the two variants?

If yes, you can do something like:

create a file build.sh with something like:

cmake --build buildfirst -j ${NUMBER_OF_PROCESSORS}

cmake --build buildsecond -j ${NUMBER_OF_PROCESSORS}

and in your .travis.yml do something like:

build-wrapper-linux-x86-64 --out-dir bw-output bash build.sh
sonar-scanner -Dsonar.cfamily.cache.enabled=true -Dsonar.cfamily.cache.path=${TRAVIS_HOME}/.cfamily -Dsonar.cfamily.threads=${NUMBER_OF_PROCESSORS}

This did the trick! Many thanks for the fast support.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.