# Unable to set value for preprocessor variable

**URL:** https://discourse.cmake.org/t/unable-to-set-value-for-preprocessor-variable/2760
**Category:** Usage
**Created:** [February 15, 2021, 6:31am UTC](https://discourse.cmake.org/t/unable-to-set-value-for-preprocessor-variable/2760 "2021-02-15T06:31:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![imlost](https://discourse.cmake.org/user_avatar/discourse.cmake.org/imlost/32/676_2.png) [@imlost](https://discourse.cmake.org/u/imlost)
#### Post date: [February 15, 2021, 6:31am UTC](https://discourse.cmake.org/t/unable-to-set-value-for-preprocessor-variable/2760/1 "2021-02-15T06:31:17Z")

</div>

Hi have a library in my project that needs a preprocessor variable set with an integer value. I can define it, but not set the value. The library is in a sub directory with its own CmakeLists file. What am I missing?

Create Command:  
`cmake .. -DCOMPONENT_TESTS=ON -DTEST_LOG_LEVEL=5`

Main cmakelists file:  
`option(TEST_LOG_LEVEL "Message level when logging (higher value is more verbose)" 5)`

Library cmakelists file:  
`target_compile_definitions(Tester PUBLIC TEST_LOG_LEVEL)`  
In code:  
#ifdef TEST\_LOG\_LEVEL  
if(lvl \> TEST\_LOG\_LEVEL)  
{  
std::cout \<\< “level is” \<\< (int)(TEST\_LOG\_LEVEL) \<\< “\n”;  
return;  
}  
#endif

Output:  
`level is1`

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [February 15, 2021, 7:53am UTC](https://discourse.cmake.org/t/unable-to-set-value-for-preprocessor-variable/2760/2 "2021-02-15T07:53:01Z")

</div>

In order to get the value of a variable, you need to use a [variable reference](https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#variable-references), i.e. `${<variable>}`.

In your case, I guess you wanted to write:

```auto
target_compile_definitions(Tester PUBLIC
  TEST_LOG_LEVEL=${TEST_LOG_LEVEL}
)

```
