diff options
| author | ruki <[email protected]> | 2018-04-14 00:03:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-04-14 00:03:06 +0800 |
| commit | 79c1eb71af25e810d421a790b5e9eab463450cfe (patch) | |
| tree | 3598846b0024d6609fd6146ed6df6c0cad862fbe | |
| parent | a8a05178346e5efb902aaef8c55264e130389e00 (diff) | |
add find_qt
| -rw-r--r-- | CHANGELOG.md | 4 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 4 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_qt.lua | 72 | ||||
| -rw-r--r-- | xmake/rules/mode/xmake.lua | 61 | ||||
| -rw-r--r-- | xmake/rules/qt/console/xmake.lua | 35 |
6 files changed, 163 insertions, 17 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d5152e11..696f8cf78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * [#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` +* Add builtin rules: `mode:debug`, `mode:release`, `mode:profile` and `mode:check` * Add `is_mode`, `is_arch` and `is_plat` builtin apis in the custom scripts ### Changes @@ -450,7 +450,7 @@ * [#158](https://github.com/tboox/xmake/issues/158): 增加对Cuda编译环境的支持 * 添加`set_tools`和`add_tools`接口为指定target目标设置编译工具链 -* 添加内建规则:`mode:debug`和`mode:release` +* 添加内建规则:`mode:debug`, `mode:release`, `mode:profile`和`mode:check` * 添加`is_mode`, `is_arch` 和`is_plat`内置接口到自定义脚本域 ### 改进 diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 468e402e0..5806ead1e 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -303,7 +303,7 @@ function option:set(name_or_info, ...) if type(name_or_info) == "string" then local args = ... if args ~= nil then - self._INFO[name_or_info] = table.unique(table.join(...)) + self._INFO[name_or_info] = table.unwrap(table.unique(table.join(...))) else self._INFO[name_or_info] = nil end @@ -318,7 +318,7 @@ end function option:add(name_or_info, ...) if type(name_or_info) == "string" then local info = table.wrap(self._INFO[name_or_info]) - self._INFO[name_or_info] = table.unique(table.join(info, ...)) + self._INFO[name_or_info] = table.unwrap(table.unique(table.join(info, ...))) elseif table.is_dictionary(name_or_info) then for name, info in pairs(table.join(name_or_info, ...)) do self:add(name, info) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 4ecd7ef24..288b5bed7 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -150,7 +150,7 @@ function target:set(name_or_info, ...) if type(name_or_info) == "string" then local args = ... if args ~= nil then - self._INFO[name_or_info] = table.unique(table.join(...)) + self._INFO[name_or_info] = table.unwrap(table.unique(table.join(...))) else self._INFO[name_or_info] = nil end @@ -165,7 +165,7 @@ end function target:add(name_or_info, ...) if type(name_or_info) == "string" then local info = table.wrap(self._INFO[name_or_info]) - self._INFO[name_or_info] = table.unique(table.join(info, ...)) + self._INFO[name_or_info] = table.unwrap(table.unique(table.join(info, ...))) elseif table.is_dictionary(name_or_info) then for name, info in pairs(table.join(name_or_info, ...)) do self:add(name, info) diff --git a/xmake/modules/detect/sdks/find_qt.lua b/xmake/modules/detect/sdks/find_qt.lua new file mode 100644 index 000000000..73f037315 --- /dev/null +++ b/xmake/modules/detect/sdks/find_qt.lua @@ -0,0 +1,72 @@ +--!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 find_qt.lua +-- + +-- imports +import("lib.detect.find_file") + +-- find qt sdk directory +function _find_sdkdir() + + -- init the search directories + local pathes = {} + if os.host() == "macosx" then + table.insert(pathes, "~/Qt") + elseif os.host() == "windows" then + else + table.insert(pathes, "~/Qt") + end + +end + +-- find qt sdk toolchains +-- +-- @param sdkdir the qt sdk directory +-- @param opt the argument options +-- +-- @return the qt sdk toolchains. .e.g {sdkdir = ..., bindir = .., linkdirs = ..., includedirs = ..., .. } +-- +-- @code +-- +-- local toolchains = find_qt("/Developer/NVIDIA/qt-9.1") +-- +-- @endcode +-- +function main(sdkdir, opt) + + -- init arguments + opt = opt or {} + + -- find qt directory + if not sdkdir or not os.isdir(sdkdir) then + sdkdir = _find_sdkdir() + end + + -- not found? + if not sdkdir or not os.isdir(sdkdir) then + return nil + end + + -- get toolchains + return {} +end diff --git a/xmake/rules/mode/xmake.lua b/xmake/rules/mode/xmake.lua index 24765a6f8..ce7d470d1 100644 --- a/xmake/rules/mode/xmake.lua +++ b/xmake/rules/mode/xmake.lua @@ -55,3 +55,64 @@ rule("mode:release") end end) +-- define rule: profile mode +rule("mode:profile") + on_load(function (target) + + -- is profile mode now? xmake f -m profile + if is_mode("profile") then + + -- set the symbols visibility: debug + target:set("symbols", "debug") + + -- enable fastest optimization + target:set("optimize", "fastest") + + -- enable gprof + target:add("cxflags", "-pg") + target:add("mxflags", "-pg") + target:add("ldflags", "-pg") + end + end) + +-- define rule: check mode +rule("mode:check") + on_load(function (target) + + -- is check mode now? xmake f -m check + if is_mode("check") then + + -- enable the debug symbols + target:set("symbols", "debug") + + -- disable optimization + target:set("optimize", "none") + + -- attempt to enable some checkers for pc + if is_mode("check") and is_arch("i386", "x86_64") then + target:add("cxflags", "-fsanitize=address", "-ftrapv") + target:add("mxflags", "-fsanitize=address", "-ftrapv") + target:add("ldflags", "-fsanitize=address") + end + end + end) + +-- define rule: coverage mode +rule("mode:coverage") + on_load(function (target) + + -- is coverage mode now? xmake f -m coverage + if is_mode("coverage") then + + -- enable the debug symbols + target:set("symbols", "debug") + + -- disable optimization + target:set("optimize", "none") + + -- enable coverage + target:add("cxflags", "--coverage") + target:add("mxflags", "--coverage") + target:add("ldflags", "--coverage") + end + end) diff --git a/xmake/rules/qt/console/xmake.lua b/xmake/rules/qt/console/xmake.lua index 8d6de96c2..2c315abf0 100644 --- a/xmake/rules/qt/console/xmake.lua +++ b/xmake/rules/qt/console/xmake.lua @@ -23,17 +23,30 @@ -- -- define rule -rule("qt_console_super") - set_kind("binary") - on_build(function (target, sourcefile) - print("TODO") - end) +rule("qt:console") --- define rule -rule("qt_console") - set_kind("binary") - add_deps("qt_console_super") - on_build(function (target, sourcefile) - print("TODO") + -- on load + on_load(function (target) + + -- set kind: binary + target:set("kind", "binary") + + -- add defines for using core lib + target:add("defines", "QT_CORE_LIB") + + -- add defines for the compile mode + if is_mode("debug") then + target:add("defines", "QT_QML_DEBUG") + elseif is_mode("release") then + target:add("defines", "QT_NO_DEBUG") + elseif is_mode("profile") then + target:add("defines", "QT_QML_DEBUG", "QT_NO_DEBUG") + end + + -- The following define makes your compiler emit warnings if you use + -- any feature of Qt which as been marked deprecated (the exact warnings + -- depend on your compiler). Please consult the documentation of the + -- deprecated API in order to know how to port your code away from it. + target:add("defines", "QT_DEPRECATED_WARNINGS") end) |
