How do I remove compile options from target

I need to send a build to a code verification service and they require it be built with certain flags.
I am able to get most with target_compile_options but I cannot set it to “Default” like we do in the IDE which has the effect of removing “/RTC1”

How do I REMOVE options?

Is there a class like Public Private Interface Unset or a target_remove_compiler_options.

1 Like

Usually you don’t remove them; you should instead not set them in the first place. However, you can go in and work with the backing properties directly (should be COMPILE_OPTIONS).

I did not set them. CMake must set them as default from their project template.
To verify I completely removed the build folder after I changed the optimization.
People have asked for this for years, I see
I can set it to the values, just not none which would be same as setting to Default in IDE.

So hard to sell management on CMake with Roadblocks like this.

To my surprise, COMPILE_OPTIONS Is empty before and after I try setting. I think it is applied later.

1 Like

Oh, the flags? string(REPLACE) on CMAKE_<LANG>_FLAGS_<CONFIG> and friends is the way to go there. CMake doesn’t have an abstraction for all of the flags (yet?), and doing anything about these flags requires a policy to change at this point, so it is slow going.

/RTC1 is just set for the DEBUG configuration, so the easiest way could be to build a RELEASE instead.
Do you need an near production or non-optimized build for that service?

Perhaps this relates to this unresolved bug with RTC1? Our company had to remove the RTC1 flag from our debug builds as a result.

RTC1 is being applied to your project via CMAKE_LANG_FLAGS_DEBUG . You will want to modify the variable for both C/C++ most likely.

You can modify the variable from the command line or via your CMake code. Whatever makes sense in your scenario.