Skip to content

Commit ba8feca

Browse files
authored
Merge pull request arximboldi#291 from tusooa/tusooa/explicit-except
Allow users to explicitly enable or disable exceptions
2 parents 6f8b3d4 + 69824a3 commit ba8feca

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ option(immer_BUILD_EXAMPLES "Build examples" ON)
4242
option(immer_BUILD_DOCS "Build docs" ON)
4343
option(immer_BUILD_EXTRAS "Build extras" ON)
4444
option(immer_INSTALL_FUZZERS "Install fuzzers" off)
45+
option(immer_ENABLE_EXCEPTIONS "Always enable exceptions regardless of detected compiler support" OFF)
46+
option(immer_DISABLE_EXCEPTIONS "Always disable exceptions regardless of detected compiler support" OFF)
47+
48+
if (immer_ENABLE_EXCEPTIONS AND immer_DISABLE_EXCEPTIONS)
49+
message(FATAL_ERROR "Cannot both enable and disable exceptions")
50+
endif()
4551

4652
set(CXX_STANDARD
4753
14
@@ -101,6 +107,17 @@ target_include_directories(
101107
INTERFACE $<BUILD_INTERFACE:${immer_BINARY_DIR}/>
102108
$<BUILD_INTERFACE:${immer_SOURCE_DIR}/>
103109
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
110+
111+
if(immer_ENABLE_EXCEPTIONS)
112+
message(STATUS "Explicitly enabling exceptions")
113+
target_compile_definitions(immer INTERFACE IMMER_USE_EXCEPTIONS)
114+
endif()
115+
116+
if(immer_DISABLE_EXCEPTIONS)
117+
message(STATUS "Explicitly disabling exceptions")
118+
target_compile_definitions(immer INTERFACE IMMER_NO_EXCEPTIONS)
119+
endif()
120+
104121
install(TARGETS immer EXPORT ImmerConfig)
105122
install(EXPORT ImmerConfig DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Immer")
106123
install(DIRECTORY immer DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

immer/config.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#endif
2323
#endif
2424

25+
#if !defined(IMMER_USE_EXCEPTIONS) && !defined(IMMER_NO_EXCEPTIONS)
2526
#if defined(_MSC_VER)
2627
#if !_HAS_EXCEPTIONS
2728
#define IMMER_NO_EXCEPTIONS
@@ -31,6 +32,7 @@
3132
#define IMMER_NO_EXCEPTIONS
3233
#endif
3334
#endif
35+
#endif
3436

3537
#ifdef IMMER_NO_EXCEPTIONS
3638
#define IMMER_TRY if (true)

0 commit comments

Comments
 (0)