Print out compile options of a target within a function

I have a enable_sanitizers() function like this:

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.

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.

Ah, okay