Skip to content

Commit

Permalink
Merge pull request #291 from tusooa/tusooa/explicit-except
Browse files Browse the repository at this point in the history
Allow users to explicitly enable or disable exceptions
  • Loading branch information
arximboldi authored Sep 17, 2024
2 parents 6f8b3d4 + 69824a3 commit ba8feca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit ba8feca

Please sign in to comment.