From d8a540a7e74e224d0a19dec874628a69766bcd98 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 13 Apr 2018 22:39:50 +0800 Subject: add debug and release rules --- CHANGELOG.md | 4 +++ tests/projects/console_c/xmake.lua | 23 ++------------- tests/projects/qt_console/xmake.lua | 25 ++-------------- xmake/core/project/project.lua | 2 +- xmake/rules/mode/xmake.lua | 57 +++++++++++++++++++++++++++++++++++++ xmake/rules/qt/console/xmake.lua | 39 +++++++++++++++++++++++++ xmake/rules/qt_console/xmake.lua | 39 ------------------------- 7 files changed, 106 insertions(+), 83 deletions(-) create mode 100644 xmake/rules/mode/xmake.lua create mode 100644 xmake/rules/qt/console/xmake.lua delete mode 100644 xmake/rules/qt_console/xmake.lua 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 new file mode 100644 index 000000000..8d6de96c2 --- /dev/null +++ b/xmake/rules/qt/console/xmake.lua @@ -0,0 +1,39 @@ +--!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 +rule("qt_console_super") + set_kind("binary") + on_build(function (target, sourcefile) + print("TODO") + end) + +-- define rule +rule("qt_console") + set_kind("binary") + add_deps("qt_console_super") + on_build(function (target, sourcefile) + print("TODO") + end) + diff --git a/xmake/rules/qt_console/xmake.lua b/xmake/rules/qt_console/xmake.lua deleted file mode 100644 index 8d6de96c2..000000000 --- a/xmake/rules/qt_console/xmake.lua +++ /dev/null @@ -1,39 +0,0 @@ ---!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 -rule("qt_console_super") - set_kind("binary") - on_build(function (target, sourcefile) - print("TODO") - end) - --- define rule -rule("qt_console") - set_kind("binary") - add_deps("qt_console_super") - on_build(function (target, sourcefile) - print("TODO") - end) - -- cgit v1.3.1