# Print out compile options of a target within a function

**URL:** https://discourse.cmake.org/t/print-out-compile-options-of-a-target-within-a-function/4175
**Category:** Usage
**Created:** [September 30, 2021, 11:53am UTC](https://discourse.cmake.org/t/print-out-compile-options-of-a-target-within-a-function/4175 "2021-09-30T11:53:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mscofield0](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mscofield0/32/1413_2.png) [@mscofield0](https://discourse.cmake.org/u/mscofield0)
#### Post date: [September 30, 2021, 11:53am UTC](https://discourse.cmake.org/t/print-out-compile-options-of-a-target-within-a-function/4175/1 "2021-09-30T11:53:47Z")

</div>

I have a `enable_sanitizers()` function like this:

```cmake
function(enable_sanitizers project_name)
      ...
      target_compile_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS} -fno-optimize-sibling-calls -lrt -fno-omit-frame-pointer)
      target_link_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS} -fno-optimize-sibling-calls -lrt -fno-omit-frame-pointer)
      ...
     message("[sanitizer] Project: ${project_name}")
     message("[sanitizer] Compile options: ${COMPILE_OPTIONS}")
     message("[sanitizer] Link options: ${LINK_OPTIONS}")
     # Tried this too:
     message("[sanitizer] Compile options: ${${project_name}_COMPILE_OPTIONS}")
     message("[sanitizer] Link options: ${${project_name}_LINK_OPTIONS}")
endfunction()

```

The thing, the reason I wanna print this is because I don’t see `CMAKE_CXX_FLAGS` being set after adding the executable, enabling the sanitizers and etc. I also don’t see sanitizers working on a small test I put up.

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [September 30, 2021, 6:12pm UTC](https://discourse.cmake.org/t/print-out-compile-options-of-a-target-within-a-function/4175/2 "2021-09-30T18:12:43Z")

</div>

To print those, you need to get them from the target (with `get_target_properties()` if memory serves - check the documentation).

But why you don’t see the options set - it’s probably that `INTERFACE` keyword. I’d guesss you either want `PRIVATE` or `PUBLIC` but not `INTERFACE` here.

---

<div class="post-metadata">

### Author: ![mscofield0](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mscofield0/32/1413_2.png) [@mscofield0](https://discourse.cmake.org/u/mscofield0)
#### Post date: [October 1, 2021, 11:05am UTC](https://discourse.cmake.org/t/print-out-compile-options-of-a-target-within-a-function/4175/3 "2021-10-01T11:05:31Z")

</div>

Ah, okay
