summaryrefslogtreecommitdiff
path: root/xmake/rules/qt/load.lua
blob: 855f01cbbf94719cee0f14008e3cc42130f244d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--!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
--

-- make link for framework
function _link(framework, major)
    if major and framework:startswith("Qt") then
        framework = "Qt" .. major .. framework:sub(3) .. (is_mode("debug") and "d" or "")
    end
    return framework
end

-- the main entry
function main(target, opt)

    -- init options
    opt = opt or {}

    -- get qt sdk
    local qt = target:data("qt")

    -- get major version
    local major = nil
    if qt.sdkver then
        major = qt.sdkver:split('%.')[1]
    end

    -- set kind
    if opt.kind then
        target:set("kind", opt.kind)
    end

    -- add -fPIC
    target:add("cxflags", "-fPIC")
    target:add("mxflags", "-fPIC")
    target:add("asflags", "-fPIC")

    -- 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 
            if is_plat("macosx") then
                target:add("includedirs", path.join(qt.sdkdir, "lib/" .. framework .. ".framework/Headers"))
            else 
                target:add("links", _link(framework, major))
                target:add("includedirs", path.join(qt.sdkdir, "include/" .. framework))
            end
        end
    end

    -- add includedirs, linkdirs 
    if is_plat("macosx") then
        target:add("frameworks", "DiskArbitration", "IOKit")
        target:add("frameworkdirs", qt.linkdirs)
        target:add("includedirs", path.join(qt.sdkdir, "mkspecs/macx-clang"))
        target:add("linkdirs", qt.linkdirs)
        target:add("rpathdirs", "@executable_path/Frameworks", qt.linkdirs)
    elseif is_plat("linux") then
        target:set("frameworks", nil)
        target:add("includedirs", path.join(qt.sdkdir, "include"))
        target:add("includedirs", path.join(qt.sdkdir, "mkspecs/linux-g++"))
        target:add("rpathdirs", qt.linkdirs)
        target:add("linkdirs", qt.linkdirs)
    elseif is_plat("windows") then
        target:set("frameworks", nil)
        target:add("includedirs", path.join(qt.sdkdir, "include"))
        target:add("includedirs", path.join(qt.sdkdir, "mkspecs/win32-msvc"))
        target:add("linkdirs", qt.linkdirs)
    elseif is_plat("mingw") then
        target:set("frameworks", nil)
        target:add("includedirs", path.join(qt.sdkdir, "include"))
        target:add("includedirs", path.join(qt.sdkdir, "mkspecs/win32-g++"))
        target:add("linkdirs", qt.linkdirs)
        target:add("links", "mingw32")
    end
end