DISCLAIMER: The information in this site is for educational purpose only. The authors of this blog are not responsible for any kind of misuse of this information.

Thursday, April 28, 2016

CLion preprocessor include hack

Ahoj !

Clion is a great IDE and I really enjoy it. But, with some little buts:

The indexer is CMake oriented. It learns what to index and how by cmake directions.
In many cases we work with a makefile projects. Usually it's pretty easy to convert it to cmake for the CLion indexer to work properly.

But, when it comes to preprocessor includes what would you do ?
By preprocessor includes I mean "-include" compiler directions passed to gcc.

My hacky-but-working solution was to add the includes directions to each file, wrapped in #ifdef block that will be false on compilation but true for CLion indexer:

#ifdef CLION_PREPROCESSOR_INCLUDE
#include <...>
#endif

In CMakeLists.txt add_defenitions will contain -DCLION_PREPROCESSOR_INCLUDE

And now the indexer will work fine :D

Another issue was discovered during this hack.
Clion indexer has the classic bug of recursive indexing a file contains #include directive to itself ...