summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-11-05 06:29:29 +0800
committerGitHub <[email protected]>2022-11-05 06:29:29 +0800
commita0c0fc7e3517e10e400e6d48338fa596202bd21c (patch)
treecdb87f9bb847a39bad4da9042f90e0a6569f3bf2
parent5cf20abdd48b4dfe645a9564975f4367e4494240 (diff)
parent4a532ca2ea7ebd5265159a6f40a809a57f330dba (diff)
Merge pull request #3025 from xmake-io/exception
C++ exception enabled/disabled switch method #2988
-rw-r--r--xmake/core/project/target.lua1
-rw-r--r--xmake/languages/c++/xmake.lua1
-rw-r--r--xmake/modules/core/tools/cl.lua13
-rw-r--r--xmake/modules/core/tools/gcc.lua21
-rw-r--r--xmake/rules/c++/xmake.lua6
-rw-r--r--xmake/toolchains/clang-cl/load.lua3
-rw-r--r--xmake/toolchains/msvc/load.lua3
7 files changed, 42 insertions, 6 deletions
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
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