summaryrefslogtreecommitdiff
path: root/xmake/rules/c++
diff options
context:
space:
mode:
Diffstat (limited to 'xmake/rules/c++')
-rw-r--r--xmake/rules/c++/config/basic.lua (renamed from xmake/rules/c++/build_sanitizer/xmake.lua)40
-rw-r--r--xmake/rules/c++/config/main.lua (renamed from xmake/rules/c++/build_optimization/xmake.lua)28
-rw-r--r--xmake/rules/c++/config/optimization.lua (renamed from xmake/rules/c++/build_optimization/config.lua)26
-rw-r--r--xmake/rules/c++/config/sanitizer.lua (renamed from xmake/rules/c++/build_sanitizer/config.lua)5
-rw-r--r--xmake/rules/c++/xmake.lua24
5 files changed, 61 insertions, 62 deletions
diff --git a/xmake/rules/c++/build_sanitizer/xmake.lua b/xmake/rules/c++/config/basic.lua
index 89149f414..e9c810417 100644
--- a/xmake/rules/c++/build_sanitizer/xmake.lua
+++ b/xmake/rules/c++/config/basic.lua
@@ -15,30 +15,24 @@
-- Copyright (C) 2015-present, Xmake Open Source Community.
--
-- @author ruki
--- @file xmake.lua
+-- @file basic.lua
--
--- define rule: c.build.sanitizer
-rule("c.build.sanitizer")
- on_config(function (target)
- import("config")(target, "cc")
- end)
+-- main entry
+function main(target, sourcekind)
+ -- enable c++ exceptions by default on Windows
+ if sourcekind == "cxx" and target:is_plat("windows") and not target:get("exceptions") then
+ target:set("exceptions", "cxx")
+ end
--- define rule: c++.build.sanitizer
-rule("c++.build.sanitizer")
- on_config(function (target)
- import("config")(target, "cxx")
- end)
-
--- define rule: objc.build.sanitizer
-rule("objc.build.sanitizer")
- on_config(function (target)
- import("config")(target, "mm")
- end)
-
--- define rule: objc++.build.sanitizer
-rule("objc++.build.sanitizer")
- on_config(function (target)
- import("config")(target, "mxx")
- end)
+ -- https://github.com/xmake-io/xmake/issues/4621
+ -- tcc on Windows static library needs special handling
+ if target:is_plat("windows") and target:is_static() then
+ local toolname = sourcekind == "cxx" and "cxx" or "cc"
+ if target:has_tool(toolname, "tcc") then
+ target:set("extension", ".a")
+ target:set("prefixname", "lib")
+ end
+ end
+end
diff --git a/xmake/rules/c++/build_optimization/xmake.lua b/xmake/rules/c++/config/main.lua
index 82693035e..78d1362af 100644
--- a/xmake/rules/c++/build_optimization/xmake.lua
+++ b/xmake/rules/c++/config/main.lua
@@ -15,18 +15,24 @@
-- Copyright (C) 2015-present, Xmake Open Source Community.
--
-- @author ruki
--- @file xmake.lua
+-- @file main.lua
--
--- define rule: c.build.optimization
-rule("c.build.optimization")
- on_config(function (target)
- import("config")(target, "cc")
- end)
+-- imports
+import("basic", {alias = "config_basic"})
+import("optimization", {alias = "config_optimization"})
+import("sanitizer", {alias = "config_sanitizer"})
--- define rule: c++.build.optimization
-rule("c++.build.optimization")
- on_config(function (target)
- import("config")(target, "cxx")
- end)
+-- main entry
+function main(target, sourcekind)
+
+ -- config basic configs
+ config_basic(target, sourcekind)
+
+ -- config optimization configs
+ config_optimization(target, sourcekind)
+
+ -- config sanitizer configs
+ config_sanitizer(target, sourcekind)
+end
diff --git a/xmake/rules/c++/build_optimization/config.lua b/xmake/rules/c++/config/optimization.lua
index 686ef76c5..4332bd833 100644
--- a/xmake/rules/c++/build_optimization/config.lua
+++ b/xmake/rules/c++/config/optimization.lua
@@ -15,7 +15,7 @@
-- Copyright (C) 2015-present, Xmake Open Source Community.
--
-- @author ruki
--- @file config.lua
+-- @file optimization.lua
--
-- imports
@@ -24,10 +24,15 @@ import("core.project.project")
-- add lto optimization
function _add_lto_optimization(target, sourcekind)
-
-- add cflags
local _, cc = target:tool(sourcekind)
- local cflag = sourcekind == "cxx" and "cxxflags" or "cflags"
+ local flagnames = {
+ cc = "cflags",
+ cxx = "cxxflags",
+ mm = "mflags",
+ mxx = "mxxflags"
+ }
+ local cflag = flagnames[sourcekind] or (sourcekind == "cxx" and "cxxflags" or "cflags")
if cc == "cl" then
target:add(cflag, "-GL")
elseif cc == "clang" or cc == "clangxx" or cc == "clang_cl" then
@@ -67,7 +72,14 @@ function _add_lto_optimization(target, sourcekind)
-- @see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
local optimize = target:get("optimize")
if optimize then
- local optimize_flags = compiler.map_flags(sourcekind == "cc" and "c" or "cxx", "optimize", optimize)
+ local lang_map = {
+ cc = "c",
+ cxx = "cxx",
+ mm = "c",
+ mxx = "cxx"
+ }
+ local lang = lang_map[sourcekind] or "cxx"
+ local optimize_flags = compiler.map_flags(lang, "optimize", optimize)
target:add("ldflags", optimize_flags)
target:add("shflags", optimize_flags)
end
@@ -87,9 +99,11 @@ function _add_lto_optimization(target, sourcekind)
end
end
+-- main entry
function main(target, sourcekind)
- if target:policy("build.optimization.lto") or
- project.policy("build.optimization.lto") then
+ -- handle lto optimization
+ if target:policy("build.optimization.lto") or project.policy("build.optimization.lto") then
_add_lto_optimization(target, sourcekind)
end
end
+
diff --git a/xmake/rules/c++/build_sanitizer/config.lua b/xmake/rules/c++/config/sanitizer.lua
index be5ba7225..aeea8492f 100644
--- a/xmake/rules/c++/build_sanitizer/config.lua
+++ b/xmake/rules/c++/config/sanitizer.lua
@@ -15,18 +15,16 @@
-- Copyright (C) 2015-present, Xmake Open Source Community.
--
-- @author ruki
--- @file config.lua
+-- @file sanitizer.lua
--
-- imports
-import("core.tool.compiler")
import("core.project.project")
import("lib.detect.find_tool")
import("core.base.semver")
-- add build sanitizer
function _add_build_sanitizer(target, sourcekind, checkmode)
-
-- add cflags
local _, cc = target:tool(sourcekind)
local flagnames = {
@@ -62,7 +60,6 @@ function main(target, sourcekind)
end
if sanitizer then
-
-- enable the debug symbols for sanitizer
if not target:get("symbols") then
target:set("symbols", "debug")
diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua
index e0673837d..dbb24451d 100644
--- a/xmake/rules/c++/xmake.lua
+++ b/xmake/rules/c++/xmake.lua
@@ -20,31 +20,19 @@
rule("c.build")
set_sourcekinds("cc")
- add_deps("c.build.pcheader", "c.build.optimization", "c.build.sanitizer")
- on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true})
+ add_deps("c.build.pcheader")
on_config(function (target)
- -- https://github.com/xmake-io/xmake/issues/4621
- if target:is_plat("windows") and target:is_static() and target:has_tool("cc", "tcc") then
- target:set("extension", ".a")
- target:set("prefixname", "lib")
- end
+ import("config")(target, "cc")
end)
+ on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true})
rule("c++.build")
set_sourcekinds("cxx")
- add_deps("c++.build.pcheader", "c++.build.modules", "c++.build.optimization", "c++.build.sanitizer")
- on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true})
+ add_deps("c++.build.pcheader", "c++.build.modules")
on_config(function (target)
- -- enable c++ exceptions by default
- if target:is_plat("windows") and not target:get("exceptions") then
- target:set("exceptions", "cxx")
- end
- -- https://github.com/xmake-io/xmake/issues/4621
- if target:is_plat("windows") and target:is_static() and target:has_tool("cxx", "tcc") then
- target:set("extension", ".a")
- target:set("prefixname", "lib")
- end
+ import("config")(target, "cxx")
end)
+ on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true})
rule("c")