Modify the default compiling commands

I am a competitive programmmer and I use CLion IDE(which uses CMake) to write code for problems in the contest. In my c++ programs, I want to do certain things if a macro named prayutsu is defined along with the compilation, e.g -

#ifdef prayutsu
freopen("inputs.txt", "r", stdin);
freopen("outputs.txt", "w", stdout);
freopen("errors.txt", "w", stderr);
#endif

Now, this is achievable normally if I compile my program with the command - $ g++ file_name.cpp -Dprayutsu but I want to set this as default so that whenever I run my program by pressing the play button, then it gets compiled in the same way. So, do we have some option to configure this?

You can use target_compile_definitions(mytgt PRIVATE prayutsu) to add the -D flag for the mytgt target (probably added via add_executable(mytgt)).

2 Likes

Thanks @ben.boeckel
It worked beautifully. :smile: