`target_compile_options()` not setting compile flags

For some reason target_compile_options() isn’t setting the compile flags for my target.

This is roughly what the CMake code looks like:

macro(internal_add_application)
  parse_arguments(${ARGV})
  add_executable(${PROJECT_NAME})
  ...
  target_compile_options(${PROJECT_NAME} PRIVATE -fsanitize=address,leak,undefined)
endmacro()

macro(add_application)
  internal_add_application(${ARGV})
  ...
endmacro()

I have no bright idea on what the problem here is.

Just for reference, I’m guessing this is related to the problem in this post?

How did you verify that the options weren’t set? Variables such as CMAKE_CXX_FLAGS will not be modified by target_compile_options, you’d have to check the actual options on the target via get_target_properties on property COMPILE_OPTIONS (or by checking the actual compiler calls in the output of a verbose build).

The flags are not in the target properties, I’ve checked with get_target_property() after that post. I literally have no idea why they aren’t being set.

get_target_property(cflags ${AVL_CURRENT_PROJECT_NAME} COMPILE_OPTIONS)
message("The project has set the following flags: ${cflags}")

And the warning flags, for example, get set.

The example code looks fine to me. I’d check cmake --trace-expand to make sure that your -fsanitize= flags are actually being added in the first place.

I’ll note that -fsanitize= usually needs passed to the linker as well to grab the right runtime library too.

It was my bad, something to do completely irrelevant to CMake. Sorry