spdlog
spdlog copied to clipboard
FMT_EXCEPTIONS not being set to 0 when SPDLOG_NO_EXCEPTIONS is OFF
The fmt exceptions are still enable in MSVC even after SPDLOG_NO_EXCEPTIONS has been set to OFF. https://github.com/gabime/spdlog/blob/069a2e8fc947f63855d770fdc3c3eb427f19988f/CMakeLists.txt#L258-L260
A possible fix would be to set the target compiler flags to disable exception such as:
And change line 258 to 260 to:
if(SPDLOG_NO_EXCEPTIONS)
if(NOT SPDLOG_FMT_EXTERNAL OR NOT SPDLOG_FMT_EXTERNAL_HO)
target_compile_definitions(spdlog PUBLIC FMT_EXCEPTIONS=0)
endif()
if(NOT MSVC)
target_compile_options(spdlog PRIVATE -fno-exceptions)
else()
target_compile_options(spdlog PRIVATE /EHsc)
endif()
endif()
what does /EHsc
do?
The definitions of the FMT_TRY
and FMT_NORETURN
macros branch off at the FMT_EXCEPTIONS
macro.
https://github.com/fmtlib/fmt/blob/bce8d4ed087a0560492426f9f5be2713804daded/include/fmt/format.h#L131-L137
https://github.com/fmtlib/fmt/blob/bce8d4ed087a0560492426f9f5be2713804daded/include/fmt/core.h#L141-L147
If an unbundled fmt library was built with FMT_EXCEPTIONS=1
, wouldn't that break application binary compatibility?
what does
/EHsc
do?
The /EH is to define the exception handling in MSVC. the options s
and c
are:
- s: Enables standard C++ stack unwinding. Catches only standard C++ exceptions when you use catch(...) syntax.
- c: When used with /EHs, the compiler assumes that functions declared as extern "C" never throw a C++ exception. Took those from https://learn.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model?view=msvc-170
The definitions of the
FMT_TRY
andFMT_NORETURN
macros branch off at theFMT_EXCEPTIONS
macro.https://github.com/fmtlib/fmt/blob/bce8d4ed087a0560492426f9f5be2713804daded/include/fmt/format.h#L131-L137
https://github.com/fmtlib/fmt/blob/bce8d4ed087a0560492426f9f5be2713804daded/include/fmt/core.h#L141-L147
If an unbundled fmt library was built with
FMT_EXCEPTIONS=1
, wouldn't that break application binary compatibility?
I am not sure about it, but wouldn't the check if(NOT SPDLOG_FMT_EXTERNAL OR NOT SPDLOG_FMT_EXTERNAL_HO)
before setting target_compile_definitions(spdlog PUBLIC FMT_EXCEPTIONS=0)
prevent that?
Also as far as I understand, the fmt library, when set to be external, is statically linked to SPDLOG, no? As per those lines: https://github.com/gabime/spdlog/blob/069a2e8fc947f63855d770fdc3c3eb427f19988f/CMakeLists.txt#L217-L223 https://github.com/gabime/spdlog/blob/069a2e8fc947f63855d770fdc3c3eb427f19988f/CMakeLists.txt#L157-L170
I am not sure about it, but wouldn't the check if(NOT SPDLOG_FMT_EXTERNAL OR NOT SPDLOG_FMT_EXTERNAL_HO) before setting target_compile_definitions(spdlog PUBLIC FMT_EXCEPTIONS=0) prevent that?
Probably, yes.
Fixed in d1eb68154f2a60c7d59e99d1504e6c6ac03fedb4
Thanks @rafaelBauer .