-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Passing -DGTEST_HAS_RTTI=0 using cmake has no effect #4678
Comments
Doing a code search in the Google Test GitHub for It might thus be better to not have this be a build-time option as again, In the no-RTTI case, either globally defining or # globally define for all targets in this and subsequent scopes
add_compile_definitions(GTEST_HAS_RTTI=0) Or, this could be done on a per-target basis: # for some specific target called "abc". we allow propagation of this requirement to downstream targets
target_compile_definitions(abc PUBLIC GTEST_HAS_RTTI=0) I would also recommend, if it suits your use case, to define your own imported target that you can link against instead of # good to have some kind of project namespace
add_library(myproj::gtest INTERFACE IMPORTED)
# transitively depend on Google Test library and add compile definitions
target_link_libraries(myproj::gtest INTERFACE GTest::gtest)
target_compile_definitions(myproj::gtest INTERFACE GTEST_HAS_RTTI=0 MYPROJ_ACTIVATE_TESTING_MACRO) Something similar could be done for # project test runner getting built
add_library(mytest test1.cc test22.cc)
target_link_libraries(mytest PRIVATE myproj::gtest) |
Describe the issue
When passing -DGTEST_HAS_RTTI=0 to cmake the value of GTEST_HAS_RTTI still ends being 1, which causes gtest to use typeid. This is obviously a problem when trying to use gtest with code that was compiled with -fno-rtti.
As a side-note, I ran into this problem when using gtest though vcpkg, so in order to define this preprocessor macro i had to add a patch to gtest's CMakeLists.txt and add add_definitions(-DGTEST_HAS_RTTI=0) because it does not support passing the options defined in gtest-port.h. Consider adding support for these options in the cmakelists file in the future so a patch is not needed and instead passing GTEST_HAS_RTTI=OFF to vcpkg_cmake_configure will be enough
Steps to reproduce the problem
try and link gtest compiled with -DGTEST_HAS_RTTI=0 into a binary compiled with -fno-rtti. The problem occurs when trying to use TYPED_TEST_SUITE()
What version of GoogleTest are you using?
1.14.0 through vcpkg
What operating system and version are you using?
ubuntu22.04
What compiler and version are you using?
gcc 13.2
What build system are you using?
cmake 3.28
Additional context
No response
The text was updated successfully, but these errors were encountered: