diff options
| author | ruki <[email protected]> | 2018-04-15 15:38:40 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-04-15 15:38:40 +0800 |
| commit | dfb2e572d6ce2675c0a4925f4dee7dd483365ce8 (patch) | |
| tree | 70a6d65223f3dc47eef097984218553ff4daf465 | |
| parent | c2534e6c6bee1c54e0dbd7f54d06444d1835c69c (diff) | |
improve find qt
| -rw-r--r-- | xmake/modules/detect/sdks/find_qt.lua | 72 | ||||
| -rw-r--r-- | xmake/rules/qt/console/load.lua | 29 |
2 files changed, 60 insertions, 41 deletions
diff --git a/xmake/modules/detect/sdks/find_qt.lua b/xmake/modules/detect/sdks/find_qt.lua index 0eb856994..51aefbf63 100644 --- a/xmake/modules/detect/sdks/find_qt.lua +++ b/xmake/modules/detect/sdks/find_qt.lua @@ -23,7 +23,10 @@ -- -- imports +import("lib.detect.cache") import("lib.detect.find_file") +import("core.base.option") +import("core.project.config") -- find qt sdk directory function _find_sdkdir() @@ -45,22 +48,7 @@ function _find_sdkdir() 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("~/Qt/5.10.1/clang_64") --- --- @endcode --- -function main(sdkdir, opt) - - -- init arguments - opt = opt or {} +function _find_qt(sdkdir) -- find qt directory if not sdkdir or not os.isdir(sdkdir) then @@ -87,3 +75,55 @@ function main(sdkdir, opt) -- get toolchains return {sdkdir = sdkdir, bindir = bindir, linkdirs = linkdirs, includedirs = includedirs} end + +-- find qt sdk toolchains +-- +-- @param sdkdir the qt sdk directory +-- @param opt the argument options, .e.g {verbose = true, force = false} +-- +-- @return the qt sdk toolchains. .e.g {sdkdir = ..., bindir = .., linkdirs = ..., includedirs = ..., .. } +-- +-- @code +-- +-- local toolchains = find_qt("~/Qt/5.10.1/clang_64") +-- +-- @endcode +-- +function main(sdkdir, opt) + + -- init arguments + opt = opt or {} + + -- attempt to load cache first + local key = "detect.sdks.find_qt." .. (sdkdir or "") + local cacheinfo = cache.load(key) + if not opt.force and cacheinfo.qt then + return cacheinfo.qt + end + + -- find qt + local qt = _find_qt(sdkdir or config.get("qt_dir")) + if qt then + + -- save sdk directory to config + config.set("qt_dir", qt.sdkdir) + + -- trace + if opt.verbose or option.get("verbose") then + cprint("checking for the Qt SDK directory ... ${green}%s", qt.sdkdir) + end + else + + -- trace + if opt.verbose or option.get("verbose") then + cprint("checking for the Qt SDK directory ... ${red}no") + end + end + + -- save to cache + cacheinfo.qt = qt or false + cache.save(key, cacheinfo) + + -- ok? + return qt +end diff --git a/xmake/rules/qt/console/load.lua b/xmake/rules/qt/console/load.lua index d93f5e425..8d752b9cd 100644 --- a/xmake/rules/qt/console/load.lua +++ b/xmake/rules/qt/console/load.lua @@ -26,35 +26,11 @@ import("core.project.config") import("detect.sdks.find_qt") --- check the qt sdk directory -function check_qt() - - -- get the qt sdk - local qt_sdkdir = config.get("qt_sdkdir") - if not qt_sdkdir then - - -- check ok? update it - local qt = find_qt() - if qt then - - -- save it - config.set("qt_sdkdir", qt.sdkdir) - - -- trace - cprint("checking for the Qt SDK directory ... ${green}%s", qt.sdkdir) - else - - -- trace - cprint("checking for the Qt SDK directory ... ${red}no") - end - end -end - -- the main entry function main(target) -- check qt sdk - check_qt() + local qt = assert(find_qt(nil, {verbose = true}), "Qt SDK not found!") -- set kind: binary target:set("kind", "binary") @@ -76,4 +52,7 @@ function main(target) -- 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 framework directories + target:add("frameworkdirs", qt.libdir) end |
