My project needs to disable RTTI however I’m getting this build warning.
This is all I’m doing.
target_compile_optons(foo_target PRIVATE /GR-)
My project needs to disable RTTI however I’m getting this build warning.
This is all I’m doing.
target_compile_optons(foo_target PRIVATE /GR-)
It looks like CMake passes /GR
by default for MSVC. You’ll have to remove it from CMAKE_CXX_FLAGS
.
Won’t that effect projects called by add_subdirectory relying on RTTI @ben.boeckel?
CMAKE_CXX_FLAGS
applies to all targets; you’ll have to add it back for RTTI-using targets if you want to remove it for any of them. Fixing this would need RTTI to become a target property like the MSVC stdlib selection did recently.
“you’ll have to add it back for RRTI-using targets”
How do you mean? I’m confused about the execution.
Also making RTTI a target property sounds like a good idea.
Once it is out of the CMAKE_CXX_FLAGS
, you’ll have to add either /GR
or /GR-
to every target (I don’t know what the default behavior is; you may be able to elide that flag setting).
In case anyone is curious this is what I ended up doing to get rid of this warning:
In ended up doing this string replacement in my top level CMakeLists.txt
As Ben said I was able to elide that flag setting.
I would still prefer RTTI to be a property, but this will do for now.
string(REPLACE "/GR" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
FWIW this issue has been fixed with newer CMake versions via CMP0117:
https://cmake.org/cmake/help/latest/policy/CMP0117.html