Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clion: Conditional compilation flags

I have some conditional compilation flags across multiple source files, which looks as following :

#ifdef FLAG1
   code ...
#endif

I have these flags enabled in the Makefile, based on some conditions. Clion grays out the blocks of code that are within the flags and doesn't perform any syntax analysis on them. Is there a way to enable some flags directly in Clion?

like image 232
Mr.SrJenea Avatar asked Dec 05 '25 16:12

Mr.SrJenea


2 Answers

To add a preprocessor

add_definitions(-DFOO -DBAR ...)

See this link for CMake's documentation.

like image 168
clamentjohn Avatar answered Dec 08 '25 08:12

clamentjohn


To make things work correctly, make sure that:

  • your Makefile is in the root of your project in CLion, else it won't work, or at least didn't work for me
  • make sure that in the Arguments field (on the screenshot) you provide all arguments you would do for a makefile to make all macro definitions (like -DFoo=bar). So if you run run make like make USE_THIS=1 DEBUG=1, type USE_THIS=1 DEBUG=1 into this field and reload Makefile project. screenshot of CLion Makefile config
like image 31
apollov Avatar answered Dec 08 '25 08:12

apollov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!