summaryrefslogtreecommitdiff
path: root/cmake/Exceptions.cmake
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-07-29 23:46:01 -0700
committerrtk0c <[email protected]>2022-07-29 23:46:01 -0700
commit2b6a10b0c61841fdd52a3caea0d97f8067909e93 (patch)
tree4c2a34428fee8e4e3d4dd33fad7981c228946028 /cmake/Exceptions.cmake
parent26a894a1ebdc943cb04cb7455345566b65768d9c (diff)
Add exception and RTTI controlcplt-qt
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()