Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining preprocessor symbols for CLion analyzer

In my project there's a file enclosed in an ifdef preprocessor directive

#ifdef SOME_SYMBOL
... entire file ...
#endif

SOME_SYMBOL is defined by another file that's compiled before this one, and the code works as expected, but the static analyzer isn't aware of this symbol and so it treats SOME_SYMBOL is undefined. The entire file has no syntax highlighting and some of the analysis is just skipped (e.g. syntax error highlighting).

Is there a way to tell the analyzer to treat this symbol as defined without defining it in CMakeLists.txt?

I don't have the option of defining SOME_SYMBOL in CMakeLists.txt since the project depends on it being undefined in some compilation paths (changing this would be near impossible).

Update:
Seems like this is currently an open issue with JetBrains. See Issue CPP-2286

like image 819
Neowizard Avatar asked Sep 03 '15 14:09

Neowizard


1 Answers

Clion now has a macro which you can use to detect the IDE: https://youtrack.jetbrains.com/issue/CPP-1296#comment=27-1846360

#ifdef __JETBRAINS_IDE__
    // Stuff that only clion will see goes here
#endif

This allows you to put in defines to make clion render your code properly in cases where it can't be clever enough to figure it out.

The __JETBRAINS_IDE__ macro's value is a version string for the IDE. Specific versions of the macro exist for different Jetbrains IDEs: __CLION_IDE__, __STUDIO_IDE__ (for Android Studio), and __APPCODE_IDE__ (for AppCode).

Yay!

like image 104
Chris Kitching Avatar answered Sep 20 '22 22:09

Chris Kitching