From 4889bfdb1fc75dfaa90a702f26d07715cb592d15 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 5 Nov 2022 00:57:10 +0800 Subject: add set_exceptions --- xmake/core/project/target.lua | 1 + xmake/languages/c++/xmake.lua | 1 + xmake/modules/core/tools/cl.lua | 13 +++++++++++++ xmake/modules/core/tools/gcc.lua | 21 +++++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index ddbd2927a..080b8249b 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -2284,6 +2284,7 @@ function target.apis() , "target.set_languages" , "target.set_toolchains" , "target.set_runargs" + , "target.set_exceptions" -- target.add_xxx , "target.add_deps" , "target.add_rules" diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index 6d4b48b2b..e28bb2733 100644 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -47,6 +47,7 @@ language("c++") , "target.undefines" , "target.frameworkdirs" , "target.frameworks" + , "target.exceptions" , "target.pcheader" , "target.pcxxheader" , "toolchain.includedirs" diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 7cce576ae..a20e4d85b 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -298,6 +298,19 @@ function nf_sysincludedir(self, dir) end end +-- make the exception flag +-- +-- e.g. +-- set_exceptions("cxx") +-- set_exceptions("no-cxx") +function nf_exception(self, exp) + local maps = { + cxx = "/EHsc", + ["no-cxx"] = "/EHsc-" + } + return maps[exp] +end + -- make the c precompiled header flag function nf_pcheader(self, pcheaderfile, target) diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index a3888ac34..cd11743c7 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -302,6 +302,27 @@ function nf_frameworkdir(self, frameworkdir) return {"-F" .. path.translate(frameworkdir)} end +-- make the exception flag +-- +-- e.g. +-- set_exceptions("cxx") +-- set_exceptions("objc") +-- set_exceptions("no-cxx") +-- set_exceptions("no-objc") +-- set_exceptions("cxx", "objc") +function nf_exception(self, exp) + local maps = { + cxx = "-fcxx-exceptions", + ["no-cxx"] = "-fno-cxx-exceptions", + objc = "-fobjc-exceptions", + ["no-objc"] = "-fno-objc-exceptions" + } + local value = maps[exp] + if value then + return {exp:startswith("no-") and "-fno-exceptions" or "-fexceptions", value} + end +end + -- make the c precompiled header flag function nf_pcheader(self, pcheaderfile, target) if self:kind() == "cc" then -- cgit v1.3.1 From 4a532ca2ea7ebd5265159a6f40a809a57f330dba Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 5 Nov 2022 00:58:30 +0800 Subject: enable cxx exceptions bu default --- xmake/rules/c++/xmake.lua | 6 ++++++ xmake/toolchains/clang-cl/load.lua | 3 --- xmake/toolchains/msvc/load.lua | 3 --- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua index 2f7977768..3d160ab65 100644 --- a/xmake/rules/c++/xmake.lua +++ b/xmake/rules/c++/xmake.lua @@ -27,6 +27,12 @@ rule("c++.build") set_sourcekinds("cxx") add_deps("c++.build.pcheader", "c++.build.modules", "c++.build.optimization") on_build_files("private.action.build.object", {batch = true, distcc = true}) + on_config(function (target) + -- we enable c++ exceptions by default + if target:is_plat("windows") and not target:get("exceptions") then + target:set("exceptions", "cxx") + end + end) rule("c++") diff --git a/xmake/toolchains/clang-cl/load.lua b/xmake/toolchains/clang-cl/load.lua index b2db0761e..5e38f0010 100644 --- a/xmake/toolchains/clang-cl/load.lua +++ b/xmake/toolchains/clang-cl/load.lua @@ -65,8 +65,5 @@ function main(toolchain) _add_vsenv(toolchain, name) end end - - -- add some default flags - toolchain:add("clang_cl.cxxflags", "/EHsc") end diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua index 74e119e35..51b851c00 100644 --- a/xmake/toolchains/msvc/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -69,8 +69,5 @@ function main(toolchain) _add_vsenv(toolchain, name) end end - - -- add some default flags - toolchain:add("cl.cxxflags", "/EHsc") end -- cgit v1.3.1