# Modify the default compiling commands

**URL:** https://discourse.cmake.org/t/modify-the-default-compiling-commands/3224
**Category:** Usage
**Tags:** os:linux, comp:gcc
**Created:** [April 28, 2021, 7:41am UTC](https://discourse.cmake.org/t/modify-the-default-compiling-commands/3224 "2021-04-28T07:41:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![prayutsu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/prayutsu/32/1412_2.png) [@prayutsu](https://discourse.cmake.org/u/prayutsu)
#### Post date: [April 28, 2021, 7:41am UTC](https://discourse.cmake.org/t/modify-the-default-compiling-commands/3224/1 "2021-04-28T07:41:13Z")

</div>

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 -

```auto
#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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 28, 2021, 12:57pm UTC](https://discourse.cmake.org/t/modify-the-default-compiling-commands/3224/2 "2021-04-28T12:57:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![prayutsu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/prayutsu/32/1412_2.png) [@prayutsu](https://discourse.cmake.org/u/prayutsu)
#### Post date: [April 28, 2021, 5:07pm UTC](https://discourse.cmake.org/t/modify-the-default-compiling-commands/3224/3 "2021-04-28T17:07:05Z")

</div>

Thanks @ben.boeckel  
It worked beautifully. 😄
