I have a CMAKE configuration where all my project configurations include the /RTC1
(Both Runtime Checks) compiler flag. However, I wish to switch to the Default
option for only one project, as it also has the /clr
compiler flag; which is incompatible with the Runtime Checks flag. I'm relatively new to CMAKE, so this may have an obvious solution, but I've so far been unable to find this.
Any help would be appreciated.
I didn't manage to find a solution whereby I could nicely remove the particular options, but I did find a way of stripping the option from the compiler flags variable using a REGEX REPLACE:
STRING (REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Where this may not be the most ideal approach, it has worked well in my situation where it is a special-cased scenario.
If you are adding your flags with add_definitions()
, then you can remove them with remove_definitions
, see documentation.
Also, you can play with COMPILE_DEFINITIONS target property.
I'd recently faced with the same problem and found no elegant solution. However this code does the job:
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
STRING (REGEX REPLACE "/RTC[^ ]*" "" ${flag_var} "${${flag_var}}")
endforeach(flag_var)
set_property(TARGET necessary_targets_here APPEND_STRING PROPERTY COMPILE_FLAGS " /RTC1")
If you only need to clear /RTC
flag for one configuration (ex. Debug) you may try the following approach:
STRING (REGEX REPLACE "/RTC[^ ]*" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
foreach(target_var necessary_targets_here)
target_compile_options(${target_var} PRIVATE $<$<CONFIG:Debug>: /RTC1>)
endforeach()
Please, note using generator expression $<$<CONFIG:Debug>: /RTC1 >
which expands to /RTC1
only in Debug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With