summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLatias94 <[email protected]>2023-03-21 14:07:46 +0800
committerLatias94 <[email protected]>2023-03-21 14:07:46 +0800
commite26aab595219f2b39c22d210d6ff2405f23bed75 (patch)
tree1196c1b46e10a230c25611633badea6c117f298c
parent8d75606dbf979386ed314bcbc01ef38dcfa10a5e (diff)
cmakelists support `set_exceptions`
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua
index d22117aa1..b2910f676 100644
--- a/xmake/plugins/project/cmake/cmakelists.lua
+++ b/xmake/plugins/project/cmake/cmakelists.lua
@@ -610,6 +610,35 @@ function _add_target_warnings(cmakelists, target)
end
end
+-- add target exceptions
+function _add_target_exceptions(cmakelists, target)
+ local flags_gcc =
+ {
+ cxx = "-fcxx-exceptions",
+ ["no-cxx"] = "-fno-cxx-exceptions",
+ objc = "-fobjc-exceptions",
+ ["no-objc"] = "-fno-objc-exceptions"
+ }
+ local flags_msvc =
+ {
+ cxx = "/EHsc",
+ ["no-cxx"] = "/EHsc-"
+ }
+ local exceptions = target:get("exceptions")
+ if exceptions then
+ cmakelists:print("if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL \"MSVC\")")
+ -- msvc or clang-cl
+ for _, exception in ipairs(exceptions) do
+ cmakelists:print(" target_compile_options(%s PRIVATE %s)", target:name(), flags_msvc[exception])
+ end
+ cmakelists:print("else()")
+ for _, exception in ipairs(exceptions) do
+ cmakelists:print(" target_compile_options(%s PRIVATE %s)", target:name(), flags_gcc[exception])
+ end
+ cmakelists:print("endif()")
+ end
+end
+
-- add target languages
function _add_target_languages(cmakelists, target)
local features =
@@ -1034,6 +1063,9 @@ function _add_target(cmakelists, target, outputdir)
-- add target warnings
_add_target_warnings(cmakelists, target)
+ -- add target exceptions
+ _add_target_exceptions(cmakelists, target)
+
-- add target languages
_add_target_languages(cmakelists, target)