Skip to content
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

Allow users to explicitly enable or disable exceptions #291

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ option(immer_BUILD_EXAMPLES "Build examples" ON)
option(immer_BUILD_DOCS "Build docs" ON)
option(immer_BUILD_EXTRAS "Build extras" ON)
option(immer_INSTALL_FUZZERS "Install fuzzers" off)
option(immer_ENABLE_EXCEPTIONS "Always enable exceptions regardless of detected compiler support" OFF)
option(immer_DISABLE_EXCEPTIONS "Always disable exceptions regardless of detected compiler support" OFF)

if (immer_ENABLE_EXCEPTIONS AND immer_DISABLE_EXCEPTIONS)
message(FATAL_ERROR "Cannot both enable and disable exceptions")
endif()

set(CXX_STANDARD
14
Expand Down Expand Up @@ -101,6 +107,17 @@ target_include_directories(
INTERFACE $<BUILD_INTERFACE:${immer_BINARY_DIR}/>
$<BUILD_INTERFACE:${immer_SOURCE_DIR}/>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

if(immer_ENABLE_EXCEPTIONS)
message(STATUS "Explicitly enabling exceptions")
target_compile_definitions(immer INTERFACE IMMER_USE_EXCEPTIONS)
endif()

if(immer_DISABLE_EXCEPTIONS)
message(STATUS "Explicitly disabling exceptions")
target_compile_definitions(immer INTERFACE IMMER_NO_EXCEPTIONS)
endif()

install(TARGETS immer EXPORT ImmerConfig)
install(EXPORT ImmerConfig DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Immer")
install(DIRECTORY immer DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
Expand Down
2 changes: 2 additions & 0 deletions immer/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#endif
#endif

#if !defined(IMMER_USE_EXCEPTIONS) && !defined(IMMER_NO_EXCEPTIONS)
#if defined(_MSC_VER)
#if !_HAS_EXCEPTIONS
#define IMMER_NO_EXCEPTIONS
Expand All @@ -31,6 +32,7 @@
#define IMMER_NO_EXCEPTIONS
#endif
#endif
#endif

#ifdef IMMER_NO_EXCEPTIONS
#define IMMER_TRY if (true)
Expand Down