summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-04-13 22:39:50 +0800
committerruki <[email protected]>2018-04-13 09:59:00 +0800
commitd8a540a7e74e224d0a19dec874628a69766bcd98 (patch)
tree9e35ccf811eca836899f0a423de1f22e73f3eca7
parentf2c934d1370eed2e674a94c4f678a3cf3da812f0 (diff)
add debug and release rules
-rw-r--r--CHANGELOG.md4
-rw-r--r--tests/projects/console_c/xmake.lua23
-rw-r--r--tests/projects/qt_console/xmake.lua25
-rw-r--r--xmake/core/project/project.lua2
-rw-r--r--xmake/rules/mode/xmake.lua57
-rw-r--r--xmake/rules/qt/console/xmake.lua (renamed from xmake/rules/qt_console/xmake.lua)0
6 files changed, 67 insertions, 44 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c5481e2f6..eb1f698f3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,12 +6,14 @@
* [#158](https://github.com/tboox/xmake/issues/158): Support CUDA Toolkit and Compiler
* Add `set_tools` and `add_tools` apis to change the toolchains for special target
+* Add builtin rules: `mode:debug` and `mode:release`
### Changes
* Add FAQ to the auto-generated xmake.lua
* Support android NDK >= r14
* Improve warning flags for swiftc
+* Improve custom rules
### Bugs fixed
@@ -447,12 +449,14 @@
* [#158](https://github.com/tboox/xmake/issues/158): 增加对Cuda编译环境的支持
* 添加`set_tools`和`add_tools`接口为指定target目标设置编译工具链
+* 添加内建规则:`mode:debug`和`mode:release`
### 改进
* 添加FAQ到自动生成的xmake.lua文件,方便用户快速上手
* 支持Android NDK >= r14的版本
* 改进swiftc对warning flags的支持
+* 改进自定义规则:`rule()`
### Bugs修复
diff --git a/tests/projects/console_c/xmake.lua b/tests/projects/console_c/xmake.lua
index 5bb1a2510..05d54fa63 100644
--- a/tests/projects/console_c/xmake.lua
+++ b/tests/projects/console_c/xmake.lua
@@ -1,25 +1,6 @@
--- the debug mode
-if is_mode("debug") then
-
- -- enable the debug symbols
- set_symbols("debug")
- -- disable optimization
- set_optimize("none")
-end
-
--- the release mode
-if is_mode("release") then
-
- -- set the symbols visibility: hidden
- set_symbols("hidden")
-
- -- enable fastest optimization
- set_optimize("fastest")
-
- -- strip all symbols
- set_strip("all")
-end
+-- add debug/release mode
+add_rules("mode:debug", "mode:release")
-- add target
target("console_c")
diff --git a/tests/projects/qt_console/xmake.lua b/tests/projects/qt_console/xmake.lua
index d7151f790..81ce32842 100644
--- a/tests/projects/qt_console/xmake.lua
+++ b/tests/projects/qt_console/xmake.lua
@@ -1,31 +1,12 @@
--- the debug mode
-if is_mode("debug") then
-
- -- enable the debug symbols
- set_symbols("debug")
- -- disable optimization
- set_optimize("none")
-end
-
--- the release mode
-if is_mode("release") then
-
- -- set the symbols visibility: hidden
- set_symbols("hidden")
-
- -- enable fastest optimization
- set_optimize("fastest")
-
- -- strip all symbols
- set_strip("all")
-end
+-- add debug/release mode
+add_rules("mode:debug", "mode:release")
-- add target
target("qt_console")
-- add rules
- add_rules("qt_console")
+ add_rules("qt:console")
-- add files
add_files("src/*.cpp")
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index 5a070fe80..9c8020c38 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -418,7 +418,7 @@ function project._load_targets()
t._RULES = t._RULES or {}
t._ORDERULES = t._ORDERULES or {}
for _, rulename in ipairs(table.wrap(t:get("rules"))) do
- local r = project.rule(rulename) or rule.rule(name)
+ local r = project.rule(rulename) or rule.rule(rulename)
if r then
t._RULES[rulename] = r
for _, deprule in ipairs(r:orderdeps()) do
diff --git a/xmake/rules/mode/xmake.lua b/xmake/rules/mode/xmake.lua
new file mode 100644
index 000000000..6511667c5
--- /dev/null
+++ b/xmake/rules/mode/xmake.lua
@@ -0,0 +1,57 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- define rule: debug mode
+rule("mode:debug")
+ on_load(function (target)
+
+ -- is debug mode now? xmake f -m debug
+ if val("mode") == "debug" then
+
+ -- enable the debug symbols
+ target:set("symbols", "debug")
+
+ -- disable optimization
+ target:set("optimize", "none")
+ end
+ end)
+
+-- define rule: release mode
+rule("mode:release")
+ on_load(function (target)
+
+ -- is release mode now? xmake f -m release
+ if val("mode") == "release" then
+
+ -- set the symbols visibility: hidden
+ target:set("symbols", "hidden")
+
+ -- enable fastest optimization
+ target:set("optimize", "fastest")
+
+ -- strip all symbols
+ target:set("strip", "all")
+ end
+ end)
+
diff --git a/xmake/rules/qt_console/xmake.lua b/xmake/rules/qt/console/xmake.lua
index 8d6de96c2..8d6de96c2 100644
--- a/xmake/rules/qt_console/xmake.lua
+++ b/xmake/rules/qt/console/xmake.lua