Skip to content

sonar.cxx.defines

Günter Wirth edited this page Jan 8, 2022 · 9 revisions

List of macros to be used by the preprocessor during analysis. The syntax is the same as #define directives, except for the #define keyword itself. This is a multiline property, which means:

  • if you're using SonarQube's UI just write one macro per line
  • when setting via sonar-project.properties file separate macros using \n\

Hint: Prefer the usage of the sonar.cxx.forceIncludes parameter to define more complex multi-line macros.

For most build environments, the cxx plugin predefined macros are not sufficient. Please check your build environment and project settings to see which additional macros you need to define with sonar.cxx.defines.

Hint: With sonar.cxx.defines and sonar.cxx.forceIncludes the predefined macro values can be redefined.

Sample:

The following macros from a header file

#define DEBUG 1
#define STRING "Hello"
#define SUM(a, b) ((a)+(b))

must be added to sonar-project.properties as follows:

sonar.cxx.defines=DEBUG 1 \n\
                  STRING "Hello" \n\
                  SUM(a, b) ((a)+(b)) \n\
  • the maximum total number of characters is 4000
  • additional blanks are removed
  • \n is the separator
  • backslash (\) at the end of the line is to split over multiple lines

Automatically extract macros from the build system

The cxx plugin can also automatically extract include paths and macros from MSBuild .LOG files or JSON Compilation Databases. More information can be found at the respective parameter sonar.cxx.msbuild.reportPaths or sonar.cxx.jsonCompilationDatabase.

Clone this wiki locally