summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-04-17 22:40:53 +0800
committerruki <[email protected]>2018-04-17 10:05:23 +0800
commitacf8310347d557a731ded14acd283a073129bf29 (patch)
tree4e3664eba4d0d5068c3253f165fcbb2e085cc871
parent4d630e8c0844d946e422ad347aa7708eca412b38 (diff)
add qrc to quickapp
-rw-r--r--xmake/core/project/config.lua2
-rw-r--r--xmake/core/project/target.lua12
-rw-r--r--xmake/rules/qt/load.lua86
-rw-r--r--xmake/rules/qt/xmake.lua148
4 files changed, 154 insertions, 94 deletions
diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua
index e04fad967..9ed77a7f8 100644
--- a/xmake/core/project/config.lua
+++ b/xmake/core/project/config.lua
@@ -140,7 +140,7 @@ function config.buildir()
-- get the absolute path first
if not path.is_absolute(buildir) then
- buildir = path.absolute(buildir, xmake._PROJECT_DIR)
+ buildir = path.absolute(buildir, os.projectdir())
end
-- adjust path for the current directory
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 288b5bed7..1cea91ed2 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -351,9 +351,7 @@ function target:objectdir()
-- the object directory
local objectdir = self:get("objectdir")
if not objectdir then
-
- -- make the default object directory
- objectdir = path.join(config.get("buildir"), ".objs")
+ objectdir = path.join(config.buildir(), ".objs")
end
-- ok?
@@ -364,7 +362,7 @@ end
function target:depfile()
-- the target directory
- local targetdir = self:get("targetdir") or config.get("buildir")
+ local targetdir = self:get("targetdir") or config.buildir()
assert(targetdir and type(targetdir) == "string")
-- make the dependent file path
@@ -380,7 +378,7 @@ end
function target:targetdir()
-- the target directory
- local targetdir = self:get("targetdir") or config.get("buildir")
+ local targetdir = self:get("targetdir") or config.buildir()
assert(targetdir and type(targetdir) == "string")
-- ok?
@@ -408,7 +406,7 @@ end
function target:symbolfile()
-- the target directory
- local targetdir = self:get("targetdir") or config.get("buildir")
+ local targetdir = self:get("targetdir") or config.buildir()
assert(targetdir and type(targetdir) == "string")
-- the symbol file name
@@ -426,7 +424,7 @@ end
-- get header directory
function target:headerdir()
- return self:get("headerdir") or config.get("buildir")
+ return self:get("headerdir") or config.buildir()
end
-- get the source file rule name
diff --git a/xmake/rules/qt/load.lua b/xmake/rules/qt/load.lua
new file mode 100644
index 000000000..c0686c2d8
--- /dev/null
+++ b/xmake/rules/qt/load.lua
@@ -0,0 +1,86 @@
+--!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 load.lua
+--
+
+-- the main entry
+function main(target, opt)
+
+ -- init options
+ opt = opt or {}
+
+ -- check qt sdk
+ local qt = target:data("qt")
+
+ -- set kind
+ if opt.kind then
+ target:set("kind", opt.kind)
+ end
+
+ -- need c++11
+ target:set("languages", "cxx11")
+
+ -- 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")
+
+ -- add frameworks
+ if opt.frameworks then
+ target:add("frameworks", opt.frameworks)
+ end
+
+ -- do frameworks for qt
+ for _, framework in ipairs(target:get("frameworks")) do
+
+ -- translate qt frameworks
+ if framework:startswith("Qt") then
+
+ -- add defines
+ target:add("defines", "QT_" .. framework:sub(3):upper() .. "_LIB")
+
+ -- add includedirs for macosx
+ if is_plat("macosx") then
+ target:add("includedirs", path.join(qt.sdkdir, "lib/" .. framework .. ".framework/Headers"))
+ end
+ end
+ end
+
+ -- add includedirs, linkdirs for macosx
+ if is_plat("macosx") then
+ target:add("frameworkdirs", qt.linkdirs)
+ target:add("frameworks", "DiskArbitration", "IOKit")
+ target:add("includedirs", path.join(qt.sdkdir, "mkspecs/macx-clang"))
+ target:add("rpathdirs", "@executable_path/Frameworks", qt.linkdirs)
+ end
+end
+
diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua
index e92ad2aa8..c386a5ea6 100644
--- a/xmake/rules/qt/xmake.lua
+++ b/xmake/rules/qt/xmake.lua
@@ -22,136 +22,112 @@
-- @file xmake.lua
--
--- define rule: base
-rule("qt:base")
+-- define rule: environment
+rule("qt:env")
-- on load
on_load(function (target)
-
- -- imports
- import("core.project.config")
import("detect.sdks.find_qt")
-
- -- check qt sdk
- local qt = assert(find_qt(nil, {verbose = true}), "Qt SDK not found!")
-
- -- set kind: binary
- target:set("kind", "binary")
-
- -- need c++11
- target:set("languages", "cxx11")
-
- -- 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")
-
- -- add frameworks: QtCore
- target:add("frameworks", "QtCore")
-
- -- do frameworks for qt
- for _, framework in ipairs(target:get("frameworks")) do
-
- -- translate qt frameworks
- if framework:startswith("Qt") then
-
- -- add defines
- target:add("defines", "QT_" .. framework:sub(3):upper() .. "_LIB")
-
- -- add includedirs for macosx
- if is_plat("macosx") then
- target:add("includedirs", path.join(qt.sdkdir, "lib/" .. framework .. ".framework/Headers"))
- end
- end
- end
-
- -- add includedirs, linkdirs for macosx
- if is_plat("macosx") then
- target:add("frameworkdirs", qt.linkdirs)
- target:add("frameworks", "DiskArbitration", "IOKit")
- target:add("includedirs", path.join(qt.sdkdir, "mkspecs/macx-clang"))
- target:add("rpathdirs", "@executable_path/Frameworks", qt.linkdirs)
- end
- end)
-
--- define rule: *.qrc
-rule("qt:qrc")
- set_extensions(".qrc")
- on_build_file(function (target, sourcefile)
- print(sourcefile)
+ target:data_set("qt", assert(find_qt(nil, {verbose = true}), "Qt SDK not found!"))
end)
-- define rule: qt static library
rule("qt:static")
- -- add base rule
- add_deps("qt:base")
+ -- add rule: qt environment
+ add_deps("qt:env")
-- on load
on_load(function (target)
- target:set("kind", "static")
+ import("load")(target, {kind = "static", frameworks = {"QtCore"}})
end)
-- define rule: qt shared library
rule("qt:shared")
- -- add base rule
- add_deps("qt:base")
+ -- add rule: qt environment
+ add_deps("qt:env")
-- on load
on_load(function (target)
- target:set("kind", "shared")
+ import("load")(target, {kind = "shared", frameworks = {"QtCore"}})
end)
-- define rule: qt console
rule("qt:console")
- -- add base rule
- add_deps("qt:base")
+ -- add rule: qt environment
+ add_deps("qt:env")
-- on load
on_load(function (target)
- target:set("kind", "binary")
+ import("load")(target, {kind = "binary", frameworks = {"QtCore"}})
end)
-- define rule: qt widget application
rule("qt:widgetapp")
- -- add base rule
- add_deps("qt:base")
+ -- add rule: qt environment
+ add_deps("qt:env")
+
+ -- on load
+ on_load(function (target)
+ import("load")(target, {kind = "binary", frameworks = {"QtGui", "QtCore"}})
+ end)
+
+-- define rule: *.qrc
+rule("qt:qrc")
+
+ -- add rule: qt environment
+ add_deps("qt:env")
+
+ -- set extensions
+ set_extensions(".qrc")
-- on load
on_load(function (target)
+
+ -- get rcc
+ local rcc = path.join(target:data("qt").bindir, is_host("windows") and "rcc.exe" or "rcc")
+ assert(rcc and os.isexec(rcc), "rcc not found!")
+
+ -- save rcc
+ target:data_set("rcc", rcc)
+ end)
+
+ -- on build file
+ on_build_file(function (target, sourcefile_qrc)
- -- set kind: binary
- target:set("kind", "binary")
+ -- imports
+ import("core.base.option")
+ import("core.project.config")
+
+ -- get rcc
+ local rcc = target:data("rcc")
+
+ -- get c++ sourcefile for qrc
+ local sourcefile_cpp = path.join(config.buildir(), ".qt", "qrc", target:name(), path.basename(sourcefile_qrc) .. ".cpp")
+ local sourcefile_dir = path.directory(sourcefile_cpp)
+ if not os.isdir(sourcefile_dir) then
+ os.mkdir(sourcefile_dir)
+ end
+
+ -- trace
+ if option.get("verbose") then
+ print("%s -name qml %s -o %s", rcc, sourcefile_qrc, sourcefile_cpp)
+ end
+
+ -- compile qrc
+ os.runv(rcc, {"-name", "qml", sourcefile_qrc, "-o", sourcefile_cpp})
end)
-- define rule: qt quick application
rule("qt:quickapp")
-- add rules
- add_deps("qt:qrc", "qt:base")
+ add_deps("qt:qrc")
-- on load
on_load(function (target)
-
- -- set kind: binary
- target:set("kind", "binary")
-
- -- add frameworks
- target:add("frameworks", "QtQuick", "QtGui")
-
- -- TODO
- -- import("load")(target, {kind = "binary", frameworks = {"QtQuick", "QtGui", "QtCore"}})
+ import("load")(target, {kind = "binary", frameworks = {"QtQuick", "QtGui", "QtQml", "QtNetwork", "QtCore"}})
end)