googletest
googletest copied to clipboard
[FR]: CMake files should provide a "main" with exceptions disabled
Does the feature exist in the most recent commit?
Not as far as I can tell.
Why do we need this feature?
Some targets do not support exceptions. In particular, using Emscripten to target WebAssembly with JSPI.
Describe the proposal.
GTest's CMake files should expose a way to get gmock_main without exceptions (and ideally also without RTTI).
Internally GTest has gmock_main_no_exception and gmock_main_no_rtti, but these are not exported, only used for self-tests.
For an example see https://dawn-review.googlesource.com/c/dawn/+/247996/4/third_party/CMakeLists.txt where I've set up a custom target for gmock_main.cc with exceptions and RTTI disabled. This works but it requires directly listing source files out of the GTest source directory.
This could be as simple as exposing gmock_main_no_exception (and perhaps gmock_main_no_rtti and a new gmock_main_no_exception_no_rtti) but perhaps ideal would be to expose some kind of customizable target, or a just list of source files needed for gmock_main, so users can compile these with the flags they need. Unfortunately I am not an expert in CMake so I don't know if there's a nice canonical way to do this.
Is the feature specific to an operating system, compiler, or build system version?
No, but it's generally only necessary on weird targets like Wasm JSPI.
@kainino0x, I've tried to add the fix for this. Let's see if it gets accepted.