Insert the Qt major version (5) in the library names
[qt:qtbase.git] / mkspecs / features / qt_functions.prf
1 defineReplace(qtPlatformTargetSuffix) {
2     CONFIG(debug, debug|release) {
3         !debug_and_release|build_pass {
4            mac:return(_debug)
5            win32:return(d)
6         }
7     }
8     return()
9 }
10
11 defineReplace(qtLibraryTarget) {
12    unset(LIBRARY_NAME)
13    LIBRARY_NAME = $$1
14    mac:!static:contains(QT_CONFIG, qt_framework) {
15       QMAKE_FRAMEWORK_BUNDLE_NAME = $$LIBRARY_NAME
16       export(QMAKE_FRAMEWORK_BUNDLE_NAME)
17    } else {
18        # insert the major version in the library name
19        # unless it's a framework build
20        MAJOR_VERSION = $$section(VERSION, ., 0, 0)
21        LIBRARY_NAME ~= s,^Qt,Qt$$MAJOR_VERSION,
22    }
23    unset(LIBRARY_SUFFIX)
24    contains(TEMPLATE, .*lib):LIBRARY_SUFFIX = $$qtPlatformTargetSuffix()
25    isEmpty(LIBRARY_SUFFIX):return($$LIBRARY_NAME)
26    else:return($$member(LIBRARY_NAME, 0)$$LIBRARY_SUFFIX)
27 }
28
29 defineTest(qtAddLibrary) {
30     warning("qtAddLibrary() is deprecated. Use qtAddModule() or QT+= instead.")
31
32     # Reverse-engineer the module name from the library name.
33     for(var, $$list($$find($$list($$enumerate_vars()), ^QT\\.[^.]+\\.name$))) {
34         isEqual($$var, $$1) {
35             var ~= s,^QT\\.([^.]+)\\.name$,\\1,
36             qtAddModule($$var, , LIBS):return(true):break()
37             return(false):break() # Yes, the break is insanity. But necessary.
38         }
39     }
40     error("No module matching library '$$1' found.")
41 }
42
43 # target variable, flag source variable
44 defineTest(qtProcessModuleFlags) {
45     for(flag, $$2) {
46         contains(flag, ^-.*): \
47             $$1 -= $$replace(flag, ^-, )
48         else: \
49             $$1 += $$flag
50     }
51     export($$1)
52 }
53
54 # qt module, UsePrivate flag, libs variable
55 defineTest(qtAddModule) {
56     MODULE_NAME = $$eval(QT.$${1}.name)
57     MODULE_INCLUDES = $$eval(QT.$${1}.includes)
58     MODULE_LIBS = $$eval(QT.$${1}.libs)
59     MODULE_CONFIG = $$eval(QT.$${1}.module_config)
60     MODULE_MAJOR_VERSION = $$eval(QT.$${1}.MAJOR_VERSION)
61
62     qtProcessModuleFlags(CONFIG, QT.$${1}.CONFIG)
63     qtProcessModuleFlags(DEFINES, QT.$${1}.DEFINES)
64
65     MODULE_INCLUDES -= $$QMAKE_DEFAULT_INCDIRS
66     MODULE_LIBS -= $$QMAKE_DEFAULT_LIBDIRS
67
68     INCLUDEPATH *= $$MODULE_INCLUDES
69     auto_use_privates|isEqual(2, UsePrivate) { # Tests function parameter 2 ($$2) being equal to 'UsePrivate'
70         INCLUDEPATH += $$eval(QT.$${1}.private_includes)
71     }
72
73     unset(LINKAGE)
74     mac {
75         contains(MODULE_CONFIG, lib_bundle) {
76           FRAMEWORK_INCLUDE = $${MODULE_LIBS}/$${MODULE_NAME}.framework/Headers
77           !qt_no_framework_direct_includes:exists($$FRAMEWORK_INCLUDE) {
78                INCLUDEPATH *= $$FRAMEWORK_INCLUDE
79                LINKAGE = -F$${MODULE_LIBS}
80           } else {
81                QMAKE_FRAMEWORKPATH *= $${MODULE_LIBS}
82           }
83           LINKAGE += -framework $${MODULE_NAME}$${QT_LIBINFIX}
84         }
85     }
86
87     # Re-insert the major version in the library name (cf qtLibraryTarget above)
88     # unless it's a framework build
89     !mac|!contains(MODULE_CONFIG, lib_bundle): \
90         MODULE_NAME ~= s,^Qt,Qt$$MODULE_MAJOR_VERSION,
91
92     win32 {
93         # Make sure the version number isn't appended again to the lib name
94         ver_var    = QMAKE_$${upper($$MODULE_NAME$$QT_LIBINFIX)}_VERSION_OVERRIDE
95         dver_var   = QMAKE_$${upper($$MODULE_NAME$$QT_LIBINFIX)}D_VERSION_OVERRIDE
96         $$ver_var  = 0
97         $$dver_var = 0
98         export($$ver_var)
99         export($$dver_var)
100     }
101
102     isEmpty(LINKAGE) {
103        !isEmpty(MODULE_LIBS): LINKAGE = -L$$MODULE_LIBS
104        lib =
105        if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
106            win32: lib = -l$${MODULE_NAME}$${QT_LIBINFIX}d
107            mac: lib = -l$${MODULE_NAME}$${QT_LIBINFIX}_debug
108        }
109        isEmpty(lib): lib = -l$${MODULE_NAME}$${QT_LIBINFIX}
110        LINKAGE += $$lib
111
112        contains(QT_CONFIG, rpath) {
113            rpath = $$eval(QT.$${1}.rpath)
114            isEmpty(rpath): rpath = $$MODULE_LIBS
115            QMAKE_RPATHDIR *= $$rpath
116        }
117
118        # Make sure we can link to uninstalled libraries
119        unix:!mac:!isEmpty(QT.$${1}.libs) { # Use unmodified path, so /usr/lib also works
120             for(rpl, QT.$${1}.rpath_link): \
121                 QMAKE_LFLAGS *= -Wl,-rpath-link,$$rpl
122             !auto_use_privates:!isEqual(2, UsePrivate): \
123                 for(rpl, QT.$${1}.rpath_link_private): \
124                     QMAKE_LFLAGS *= -Wl,-rpath-link,$$rpl
125        }
126     }
127     # Only link to this module if a libs directory is set, else this is just a module
128     # to give access to sources or include files, and not for linking.
129     !isEmpty(QT.$${1}.libs) { # Use unmodified path, so /usr/lib also works
130         !isEmpty(QMAKE_LSB) {
131             !isEmpty(MODULE_LIBS): QMAKE_LFLAGS *= --lsb-libpath=$$MODULE_LIBS
132             QMAKE_LIBDIR *= /opt/lsb/lib
133             QMAKE_LFLAGS *= --lsb-shared-libs=$${MODULE_NAME}$${QT_LIBINFIX}
134         }
135         $$3 += $$LINKAGE
136     }
137     export($$3)
138     export(INCLUDEPATH)
139     export(QMAKE_FRAMEWORKPATH)
140     export(QMAKE_LFLAGS)
141     export(QMAKE_LIBDIR)
142     export(QMAKE_RPATHDIR)
143     return(true)
144 }
145
146 # qt variable, libs variable
147 defineTest(qtAddModules) {
148     # Figure out from which modules we're wanting to use the private headers
149     NEWQT =
150     for(QTLIB, $$1) {
151         QTLIBRAW = $$replace(QTLIB, -private$, )
152         !isEqual(QTLIBRAW, $$QTLIB) {
153             want_var = QT.$${QTLIBRAW}.want_private
154             $$want_var = UsePrivate
155             using_privates = true
156             NEWQT += $$eval(QT.$${QTLIBRAW}.private_depends)
157         }
158         NEWQT += $$QTLIBRAW
159         contains(QT.$${QTLIBRAW}.CONFIG, auto_use_privates): CONFIG += auto_use_privates
160     }
161     # Topological resolution of modules based on their QT.<module>.depends variable
162     $$1 = $$resolve_depends(NEWQT, "QT.")
163     # Finally actually add the modules
164     unset(BAD_QT)
165     for(QTLIB, $$1) {
166         QTLIBNAME = $$eval(QT.$${QTLIB}.name)
167         isEmpty(QTLIBNAME) {
168             BAD_QT += $$QTLIB
169             next()
170         }
171
172         target_qt:isEqual(TARGET, $$QTLIBNAME) {
173             warning("$$TARGET cannot have a $$1 of $$QTLIB")
174             next()
175         }
176
177         qtAddModule($$QTLIB, $$eval(QT.$${QTLIB}.want_private), $$2)
178     }
179     !isEmpty(BAD_QT):error("Unknown module(s) in $$1: $$BAD_QT")
180
181     export(using_privates)
182 }
183
184 # variable, default
185 defineTest(qtPrepareTool) {
186     $$1 = $$eval(QT_TOOL.$${2}.command)
187     isEmpty($$1) {
188         $$1 = $$[QT_HOST_BINS/get]/$$2
189         contains(QMAKE_HOST.os, Windows):!contains($$1, .*\\.(exe|bat)$) {
190             exists($$eval($$1).bat) {
191                 $$1 = $$eval($$1).bat
192             } else {
193                 $$1 = $$eval($$1).exe
194             }
195         } else:contains(QMAKE_HOST.os, Darwin) {
196             BUNDLENAME = $$eval($$1).app/Contents/MacOS/$$2
197             exists($$BUNDLENAME) {
198                 $$1 = $$BUNDLENAME
199             }
200         }
201         $$1 = $$shell_path($$eval($$1))
202     }
203     export($$1)
204 }
205
206 defineTest(qtAddToolEnv) {
207     for(env, 2) {
208         value = $$eval($${env}.value)
209         !isEmpty(value) {
210             name = $$eval($${env}.name)
211             equals(QMAKE_DIR_SEP, /) {
212                 contains($${env}.CONFIG, prepend): infix = \${$$name:+:\$$$name}
213                 else: infix =
214                 val = "$$name=$$join(value, :)$$infix"
215             } else {
216                 # Escape closing parens when expanding the variable, otherwise cmd confuses itself.
217                 contains($${env}.CONFIG, prepend): infix = ;%$$name:)=^)%
218                 else: infix =
219                 val = "(set $$name=$$join(value, ;)$$infix) &"
220             }
221             contains(MAKEFILE_GENERATOR, MS.*): val ~= s,%,%%,g
222             else: val ~= s,\\\$,\$\$,g
223             $$1 = "$$val $$eval($$1)"
224         }
225     }
226     export($$1)
227 }
228
229 defineTest(qtAddTargetEnv) {
230     deps = $$resolve_depends(QT, "QT.")
231     !isEmpty(deps) {
232         for(dep, deps) {
233             deppath += $$shell_path($$eval(QT.$${dep}.libs))
234             for(rpath, QT.$${dep}.rpath_link): \
235                 deppath += $$shell_path($$rpath)
236         }
237         equals(QMAKE_HOST.os, Windows) {
238             deppath.name = PATH
239         } else:contains(QMAKE_HOST.os, Linux|FreeBSD) {
240             deppath.name = LD_LIBRARY_PATH
241         } else:equals(QMAKE_HOST.os, Darwin) {
242             contains(QT_CONFIG, qt_framework): \
243                 deppath.name = DYLD_FRAMEWORK_PATH
244             else: \
245                 deppath.name = DYLD_LIBRARY_PATH
246         } else {
247             error("Operating system not supported.")
248         }
249         deppath.value = $$unique(deppath)
250         deppath.CONFIG = prepend
251
252         pluginpath.value =
253         for(qmod, QMAKEMODULES) {
254             qmod = $$section(qmod, /, 0, -3)/plugins
255             exists($$qmod): pluginpath.value += $$shell_path($$qmod)
256         }
257         pluginpath.name = QT_PLUGIN_PATH
258
259         QT_TOOL_ENV += deppath pluginpath
260     }
261     qtAddToolEnv($$1, $$QT_TOOL_ENV)
262 }
263
264 defineReplace(pkgConfigExecutable) {
265     isEmpty(PKG_CONFIG) {
266         PKG_CONFIG = pkg-config
267
268         !isEmpty(PKG_CONFIG_SYSROOT_DIR) {
269             win32:isEmpty(MINGW_IN_SHELL):PKG_CONFIG = set PKG_CONFIG_SYSROOT_DIR=$$PKG_CONFIG_SYSROOT_DIR& $$PKG_CONFIG
270             else:PKG_CONFIG = PKG_CONFIG_SYSROOT_DIR=\"$$PKG_CONFIG_SYSROOT_DIR\" $$PKG_CONFIG
271         }
272
273         !isEmpty(PKG_CONFIG_LIBDIR) {
274             win32:isEmpty(MINGW_IN_SHELL):PKG_CONFIG = set PKG_CONFIG_LIBDIR=$$PKG_CONFIG_LIBDIR& $$PKG_CONFIG
275             else:PKG_CONFIG = PKG_CONFIG_LIBDIR=\"$$PKG_CONFIG_LIBDIR\" $$PKG_CONFIG
276         }
277     }
278
279     return($$PKG_CONFIG)
280 }
281
282 defineTest(packagesExist) {
283     # this can't be done in global scope here because qt_functions is loaded
284     # before the .pro is parsed, so if the .pro set PKG_CONFIG, we wouldn't know it
285     # yet. oops.
286
287     pkg_config = $$pkgConfigExecutable()
288
289     for(package, ARGS) {
290         !system($$pkg_config --exists $$package):return(false)
291     }
292
293     return(true)
294 }
295
296 # Prepares target that will iterate through all subdirs (except those
297 # with no_default_target or no_{name_of_target}_target. The prepared
298 # target must still be manually added to QMAKE_EXTRA_TARGETS.
299 defineTest(prepareRecursiveTarget) {
300     target = $$1
301     no_$${target}_target: return()
302
303     for(subdir, SUBDIRS) {
304         subdir_config = $$eval($${subdir}.CONFIG)
305         contains(subdir_config, no_default_target): next()
306         contains(subdir_config, no_$${target}_target): next()
307
308         $${target}.recurse += $$subdir
309     }
310
311     # Set up the recurse target only when there
312     # is something to recurse into.
313     isEmpty($${target}.recurse): return()
314
315     $${target}.CONFIG = recursive
316     $${target}.recurse_target = $${target}
317
318     export($${target}.recurse)
319     export($${target}.CONFIG)
320     export($${target}.recurse_target)
321 }