3861cd01af867f5c679206fc3e0cdaaeb1e3b85e
[scm/bb/tizen-distro.git] / meta-qt5 / classes / qmake5_base.bbclass
1 # This is useful for target recipes to reference native mkspecs
2 QMAKE_MKSPEC_PATH_NATIVE = "${STAGING_LIBDIR_NATIVE}/${QT_DIR_NAME}"
3 QMAKE_MKSPEC_PATH_TARGET = "${STAGING_LIBDIR}/${QT_DIR_NAME}"
4
5 QMAKE_MKSPEC_PATH = "${QMAKE_MKSPEC_PATH_TARGET}"
6 QMAKE_MKSPEC_PATH_class-native = "${QMAKE_MKSPEC_PATH_NATIVE}"
7 QMAKE_MKSPEC_PATH_class-nativesdk = "${QMAKE_MKSPEC_PATH_NATIVE}"
8
9 # hardcode linux, because that's what 0001-Add-linux-oe-g-platform.patch adds
10 OE_QMAKE_PLATFORM_NATIVE = "linux-oe-g++"
11 OE_QMAKE_PLATFORM = "linux-oe-g++"
12
13 # Add -d to show debug output from every qmake call, but it prints *a lot*, better to add it only to debugged recipe
14 OE_QMAKE_DEBUG_OUTPUT ?= ""
15
16 # Paths in .prl files contain SYSROOT value
17 SSTATE_SCAN_FILES += "*.pri *.prl"
18
19 # drop default -e and add needed OE_QMAKE vars explicitly
20 # the problem is that when generated Makefile has:
21 # CFLAGS = -pipe $(OE_QMAKE_CFLAGS) -O2 -pthread -D_REENTRANT -Wall -W -fPIC $(DEFINES)
22 # then OE_QMAKE_CFLAGS are exported and used correctly, but then whole CFLAGS is overwritten from env (and -fPIC lost and build fails)
23 EXTRA_OEMAKE = " \
24     MAKEFLAGS='${PARALLEL_MAKE}' \
25     OE_QMAKE_COMPILER='${OE_QMAKE_COMPILER}' \
26     OE_QMAKE_CC='${OE_QMAKE_CC}' \
27     OE_QMAKE_CXX='${OE_QMAKE_CXX}' \
28     OE_QMAKE_CFLAGS='${OE_QMAKE_CFLAGS}' \
29     OE_QMAKE_CXXFLAGS='${OE_QMAKE_CXXFLAGS}' \
30     OE_QMAKE_LINK='${OE_QMAKE_LINK}' \
31     OE_QMAKE_LDFLAGS='${OE_QMAKE_LDFLAGS}' \
32     OE_QMAKE_AR='${OE_QMAKE_AR}' \
33     OE_QMAKE_STRIP='${OE_QMAKE_STRIP}' \
34     OE_QMAKE_WAYLAND_SCANNER='${OE_QMAKE_WAYLAND_SCANNER}' \
35 "
36
37 OE_QMAKESPEC = "${QMAKE_MKSPEC_PATH_NATIVE}/mkspecs/${OE_QMAKE_PLATFORM_NATIVE}"
38 OE_XQMAKESPEC = "${QMAKE_MKSPEC_PATH}/mkspecs/${OE_QMAKE_PLATFORM}"
39 OE_QMAKE_QMAKE = "${STAGING_BINDIR_NATIVE}/${QT_DIR_NAME}/qmake"
40 OE_QMAKE_COMPILER = "${CC}"
41 OE_QMAKE_CC = "${CC}"
42 OE_QMAKE_CFLAGS = "${CFLAGS}"
43 OE_QMAKE_CXX = "${CXX}"
44 OE_QMAKE_CXXFLAGS = "${CXXFLAGS}"
45 OE_QMAKE_LINK = "${CXX}"
46 OE_QMAKE_LDFLAGS = "${LDFLAGS}"
47 OE_QMAKE_AR = "${AR}"
48 OE_QMAKE_STRIP = "echo"
49 OE_QMAKE_WAYLAND_SCANNER = "${STAGING_BINDIR_NATIVE}/wayland-scanner"
50
51 # this one needs to be exported, because qmake reads it from shell env
52 export QT_CONF_PATH = "${WORKDIR}/qt.conf"
53
54 inherit qmake5_paths
55
56 do_generate_qt_config_file() {
57     cat > ${QT_CONF_PATH} <<EOF
58 [Paths]
59 Prefix = ${OE_QMAKE_PATH_PREFIX}
60 Headers = ${OE_QMAKE_PATH_HEADERS}
61 Libraries = ${OE_QMAKE_PATH_LIBS}
62 ArchData = ${OE_QMAKE_PATH_ARCHDATA}
63 Data = ${OE_QMAKE_PATH_DATA}
64 Binaries = ${OE_QMAKE_PATH_BINS}
65 LibraryExecutables = ${OE_QMAKE_PATH_LIBEXECS}
66 Plugins = ${OE_QMAKE_PATH_PLUGINS}
67 Imports = ${OE_QMAKE_PATH_IMPORTS}
68 Qml2Imports = ${OE_QMAKE_PATH_QML}
69 Translations = ${OE_QMAKE_PATH_TRANSLATIONS}
70 Documentation = ${OE_QMAKE_PATH_DOCS}
71 Settings = ${OE_QMAKE_PATH_SETTINGS}
72 Examples = ${OE_QMAKE_PATH_EXAMPLES}
73 Tests = ${OE_QMAKE_PATH_TESTS}
74 HostBinaries = ${OE_QMAKE_PATH_HOST_BINS}
75 HostData = ${OE_QMAKE_PATH_HOST_DATA}
76 HostLibraries = ${OE_QMAKE_PATH_HOST_LIBS}
77 HostSpec = ${OE_QMAKESPEC}
78 TartgetSpec = ${OE_XQMAKESPEC} 
79 ExternalHostBinaries = ${OE_QMAKE_PATH_EXTERNAL_HOST_BINS}
80 Sysroot = ${STAGING_DIR_TARGET}
81 EOF
82 }
83 #
84 # Allows to override following values (as in version 5.0.1)
85 # Prefix The default prefix for all paths.
86 # Documentation The location for documentation upon install.
87 # Headers The location for all headers.
88 # Libraries The location of installed libraries.
89 # LibraryExecutables The location of installed executables required by libraries at runtime.
90 # Binaries The location of installed Qt binaries (tools and applications).
91 # Plugins The location of installed Qt plugins.
92 # Imports The location of installed QML extensions to import (QML 1.x).
93 # Qml2Imports The location of installed QML extensions to import (QML 2.x).
94 # ArchData The location of general architecture-dependent Qt data.
95 # Data The location of general architecture-independent Qt data.
96 # Translations The location of translation information for Qt strings.
97 # Examples The location for examples upon install.
98 # Tests The location of installed Qt testcases.
99 # Settings The location for Qt settings. Not applicable on Windows.
100
101 # For bootstrapped
102 # Sysroot The location of target sysroot
103 # HostPrefix The prefix for host tools when cross compiling (building tools for both systems)
104 # HostBinaries The location where to install host tools
105 # HostData The location where to install host data
106 # ExternalHostBinaries The location where we already have host tools (when cross compiling, but reusing existing tools)
107 # TargetSpec The location where to install target mkspec
108 # HostSpec The location where to install host mkspec
109
110 # qmake works fine with separate B, use it by default
111 SEPB = "${WORKDIR}/build"
112 B = "${SEPB}"
113
114 CONFIGURESTAMPFILE = "${WORKDIR}/qmake5_base_configure.sstate"
115
116 qmake5_base_preconfigure() {
117         if [ -n "${CONFIGURESTAMPFILE}" -a -e "${CONFIGURESTAMPFILE}" ]; then
118                 if [ "`cat ${CONFIGURESTAMPFILE}`" != "${BB_TASKHASH}" -a "${S}" != "${B}" ]; then
119                         echo "Previously configured separate build directory detected, cleaning ${B}"
120                         rm -rf ${B}
121                         mkdir ${B}
122                 fi
123         fi
124 }
125
126 qmake5_base_postconfigure(){
127         if [ -n "${CONFIGURESTAMPFILE}" ]; then
128                 echo ${BB_TASKHASH} > ${CONFIGURESTAMPFILE}
129         fi
130 }
131
132 EXTRAQCONFFUNCS ??= ""
133
134 do_configure[prefuncs] += "qmake5_base_preconfigure ${EXTRAQCONFFUNCS}"
135 do_configure[postfuncs] += "qmake5_base_postconfigure"
136
137 addtask generate_qt_config_file after do_patch before do_configure
138
139 qmake5_base_do_configure () {
140     if [ -z "${QMAKE_PROFILES}" ]; then
141         PROFILES="`ls ${S}/*.pro`"
142     else
143         PROFILES="${QMAKE_PROFILES}"
144         bbnote "qmake using profiles: '${QMAKE_PROFILES}'"
145     fi
146
147     if [ ! -z "${EXTRA_QMAKEVARS_POST}" ]; then
148         AFTER="-after"
149         QMAKE_VARSUBST_POST="${EXTRA_QMAKEVARS_POST}"
150         bbnote "qmake postvar substitution: '${EXTRA_QMAKEVARS_POST}'"
151     fi
152
153     if [ ! -z "${EXTRA_QMAKEVARS_PRE}" ]; then
154         QMAKE_VARSUBST_PRE="${EXTRA_QMAKEVARS_PRE}"
155         bbnote "qmake prevar substitution: '${EXTRA_QMAKEVARS_PRE}'"
156     fi
157
158     # for config.tests to read this
159     export QMAKE_MAKE_ARGS="${EXTRA_OEMAKE}"
160
161     CMD="${OE_QMAKE_QMAKE} -makefile -o Makefile ${OE_QMAKE_DEBUG_OUTPUT} -r $QMAKE_VARSUBST_PRE $AFTER $PROFILES $QMAKE_VARSUBST_POST"
162     ${OE_QMAKE_QMAKE} -makefile -o Makefile ${OE_QMAKE_DEBUG_OUTPUT} -r $QMAKE_VARSUBST_PRE $AFTER $PROFILES $QMAKE_VARSUBST_POST || die "Error calling $CMD"
163 }
164
165 qmake5_base_do_install() {
166     # Fix install paths for all
167     find -name "Makefile*" | xargs sed -i "s,(INSTALL_ROOT)${STAGING_DIR_TARGET},(INSTALL_ROOT),g"
168
169     oe_runmake install INSTALL_ROOT=${D}
170
171     # everything except HostData and HostBinaries is prefixed with sysroot value,
172     # but we cannot remove sysroot override, because that's useful for pkg-config etc
173     # In some cases like QtQmlDevTools in qtdeclarative, the sed above does not work,
174     # fix them manually
175     if [ -d ${D}${STAGING_DIR_TARGET} ] ; then
176         echo "Some files are installed in wrong directory ${D}${STAGING_DIR_TARGET}"
177         cp -ra ${D}${STAGING_DIR_TARGET}/* ${D}
178         rm -rf ${D}${STAGING_DIR_TARGET}
179         # remove empty dirs
180         TMP=`dirname ${D}/${STAGING_DIR_TARGET}`
181         while test ${TMP} != ${D}; do
182             rmdir ${TMP}
183             TMP=`dirname ${TMP}`;
184         done
185     fi
186 }