aboutsummaryrefslogtreecommitdiff
path: root/cmake/Exceptions.cmake
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2023-09-20 23:58:58 -0700
committerrtk0c <[email protected]>2023-09-20 23:58:58 -0700
commitf138311d2d2e0cc9ba0496d523bb46f2c1c9fb73 (patch)
treef96100a813a4ffb28dcd074455d3a2f8ee426430 /cmake/Exceptions.cmake
Copy from the PlasticSCM repo, replace vendored glm wtih conan
Diffstat (limited to 'cmake/Exceptions.cmake')
-rw-r--r--cmake/Exceptions.cmake31
1 files changed, 31 insertions, 0 deletions
diff --git a/cmake/Exceptions.cmake b/cmake/Exceptions.cmake
new file mode 100644
index 0000000..89e7e69
--- /dev/null
+++ b/cmake/Exceptions.cmake
@@ -0,0 +1,31 @@
+function(target_flag_exceptions_msvc TARGET_NAME ENABLED)
+ if(ENABLED)
+ target_compile_options(${TARGET_NAME} PRIVATE /EHsc)
+ else()
+ target_compile_options(${TARGET_NAME} PRIVATE /EH-)
+ endif()
+endfunction()
+
+function(target_flag_exceptions_gcc TARGET_NAME ENABLED)
+ if(ENABLED)
+ target_compile_options(${TARGET_NAME} PRIVATE -fexceptions)
+ else()
+ target_compile_options(${TARGET_NAME} PRIVATE -fno-exceptions)
+ endif()
+endfunction()
+
+function(target_flag_exceptions TARGET_NAME ENABLED)
+ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
+ target_flag_exceptions_msvc(${TARGET_NAME} ${ENABLED})
+ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
+ target_flag_exceptions_msvc(${TARGET_NAME} ${ENABLED})
+ elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "GNU")
+ target_flag_exceptions_gcc(${TARGET_NAME} ${ENABLED})
+ endif()
+ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ target_flag_exceptions_gcc(${TARGET_NAME} ${ENABLED})
+ else()
+ message(FATAL "target_flag_exceptions(): Unknown compiler ${CMAKE_CXX_COMPILER_ID}")
+ endif()
+endfunction()