qmake5_base.bbclass 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. # hardcode linux, because that's what 0001-Add-linux-oe-g-platform.patch adds
  2. XPLATFORM:toolchain-clang = "linux-oe-clang"
  3. XPLATFORM ?= "linux-oe-g++"
  4. OE_QMAKE_PLATFORM_NATIVE = "${XPLATFORM}"
  5. OE_QMAKE_PLATFORM = "${XPLATFORM}"
  6. # Add -d to show debug output from every qmake call, but it prints *a lot*, better to add it only to debugged recipe
  7. OE_QMAKE_DEBUG_OUTPUT ?= ""
  8. # Look through supplied directories recursively by default
  9. OE_QMAKE_RECURSIVE ?= "-r"
  10. # Paths in .prl files contain SYSROOT value
  11. SSTATE_SCAN_FILES += "*.pri *.prl *.prf"
  12. # drop default -e and add needed OE_QMAKE vars explicitly
  13. # the problem is that when generated Makefile has:
  14. # CFLAGS = -pipe $(OE_QMAKE_CFLAGS) -O2 -pthread -D_REENTRANT -Wall -W -fPIC $(DEFINES)
  15. # then OE_QMAKE_CFLAGS are exported and used correctly, but then whole CFLAGS is overwritten from env (and -fPIC lost and build fails)
  16. EXTRA_OEMAKE = " \
  17. MAKEFLAGS='${PARALLEL_MAKE}' \
  18. OE_QMAKE_CC='${OE_QMAKE_CC}' \
  19. OE_QMAKE_CXX='${OE_QMAKE_CXX}' \
  20. OE_QMAKE_CFLAGS='${OE_QMAKE_CFLAGS}' \
  21. OE_QMAKE_CXXFLAGS='${OE_QMAKE_CXXFLAGS}' \
  22. OE_QMAKE_LINK='${OE_QMAKE_LINK}' \
  23. OE_QMAKE_LDFLAGS='${OE_QMAKE_LDFLAGS}' \
  24. OE_QMAKE_AR='${OE_QMAKE_AR}' \
  25. OE_QMAKE_OBJCOPY='${OE_QMAKE_OBJCOPY}' \
  26. OE_QMAKE_STRIP='${OE_QMAKE_STRIP}' \
  27. OE_QMAKE_INCDIR_QT='${STAGING_DIR_TARGET}/${OE_QMAKE_PATH_HEADERS}' \
  28. "
  29. OE_QMAKE_QMAKE = "${OE_QMAKE_PATH_EXTERNAL_HOST_BINS}/qmake"
  30. export OE_QMAKE_CC = "${CC}"
  31. export OE_QMAKE_CFLAGS = "${CFLAGS}"
  32. export OE_QMAKE_CXX = "${CXX}"
  33. export OE_QMAKE_CXXFLAGS = "${CXXFLAGS}"
  34. export OE_QMAKE_LINK = "${CXX}"
  35. export OE_QMAKE_LDFLAGS = "${LDFLAGS}"
  36. export OE_QMAKE_AR = "${AR}"
  37. export OE_QMAKE_OBJCOPY = "${OBJCOPY}"
  38. export OE_QMAKE_STRIP = "echo"
  39. # qmake reads if from shell environment
  40. export OE_QMAKE_QTCONF_PATH = "${WORKDIR}/qt.conf"
  41. inherit qmake5_paths
  42. generate_target_qt_config_file() {
  43. qtconf="$1"
  44. cat > "${qtconf}" <<EOF
  45. [Paths]
  46. Prefix = ${OE_QMAKE_PATH_PREFIX}
  47. Headers = ${OE_QMAKE_PATH_HEADERS}
  48. Libraries = ${OE_QMAKE_PATH_LIBS}
  49. ArchData = ${OE_QMAKE_PATH_ARCHDATA}
  50. Data = ${OE_QMAKE_PATH_DATA}
  51. Binaries = ${OE_QMAKE_PATH_BINS}
  52. LibraryExecutables = ${OE_QMAKE_PATH_LIBEXECS}
  53. Plugins = ${OE_QMAKE_PATH_PLUGINS}
  54. Qml2Imports = ${OE_QMAKE_PATH_QML}
  55. Translations = ${OE_QMAKE_PATH_TRANSLATIONS}
  56. Documentation = ${OE_QMAKE_PATH_DOCS}
  57. Settings = ${OE_QMAKE_PATH_SETTINGS}
  58. Examples = ${OE_QMAKE_PATH_EXAMPLES}
  59. Tests = ${OE_QMAKE_PATH_TESTS}
  60. HostBinaries = ${OE_QMAKE_PATH_BINS}
  61. HostData = ${OE_QMAKE_PATH_ARCHDATA}
  62. HostLibraries = ${OE_QMAKE_PATH_LIBS}
  63. HostSpec = ${OE_QMAKE_PLATFORM}
  64. TargetSpec = ${OE_QMAKE_PLATFORM}
  65. ExternalHostBinaries = ${OE_QMAKE_PATH_BINS}
  66. Sysroot =
  67. EOF
  68. }
  69. do_generate_qt_config_file() {
  70. generate_qt_config_file_paths
  71. generate_qt_config_file_effective_paths
  72. }
  73. generate_qt_config_file_paths() {
  74. cat > ${OE_QMAKE_QTCONF_PATH} <<EOF
  75. [Paths]
  76. Prefix = ${OE_QMAKE_PATH_PREFIX}
  77. Headers = ${OE_QMAKE_PATH_HEADERS}
  78. Libraries = ${OE_QMAKE_PATH_LIBS}
  79. ArchData = ${OE_QMAKE_PATH_ARCHDATA}
  80. Data = ${OE_QMAKE_PATH_DATA}
  81. Binaries = ${OE_QMAKE_PATH_BINS}
  82. LibraryExecutables = ${OE_QMAKE_PATH_LIBEXECS}
  83. Plugins = ${OE_QMAKE_PATH_PLUGINS}
  84. Qml2Imports = ${OE_QMAKE_PATH_QML}
  85. Translations = ${OE_QMAKE_PATH_TRANSLATIONS}
  86. Documentation = ${OE_QMAKE_PATH_DOCS}
  87. Settings = ${OE_QMAKE_PATH_SETTINGS}
  88. Examples = ${OE_QMAKE_PATH_EXAMPLES}
  89. Tests = ${OE_QMAKE_PATH_TESTS}
  90. HostBinaries = ${OE_QMAKE_PATH_HOST_BINS}
  91. HostData = ${OE_QMAKE_PATH_HOST_DATA}
  92. HostLibraries = ${OE_QMAKE_PATH_HOST_LIBS}
  93. HostSpec = ${OE_QMAKE_PLATFORM_NATIVE}
  94. TargetSpec = ${OE_QMAKE_PLATFORM}
  95. ExternalHostBinaries = ${OE_QMAKE_PATH_EXTERNAL_HOST_BINS}
  96. Sysroot = ${STAGING_DIR_TARGET}
  97. EOF
  98. }
  99. generate_qt_config_file_effective_paths() {
  100. cat >> ${OE_QMAKE_QTCONF_PATH} <<EOF
  101. [EffectivePaths]
  102. HostBinaries = ${OE_QMAKE_PATH_EXTERNAL_HOST_BINS}
  103. HostLibraries = ${STAGING_LIBDIR_NATIVE}
  104. HostData = ${OE_QMAKE_PATH_HOST_DATA}
  105. HostPrefix = ${STAGING_DIR_NATIVE}
  106. EOF
  107. }
  108. #
  109. # Allows to override following values (as in version 5.0.1)
  110. # Prefix The default prefix for all paths.
  111. # Documentation The location for documentation upon install.
  112. # Headers The location for all headers.
  113. # Libraries The location of installed libraries.
  114. # LibraryExecutables The location of installed executables required by libraries at runtime.
  115. # Binaries The location of installed Qt binaries (tools and applications).
  116. # Plugins The location of installed Qt plugins.
  117. # Imports The location of installed QML extensions to import (QML 1.x).
  118. # Qml2Imports The location of installed QML extensions to import (QML 2.x).
  119. # ArchData The location of general architecture-dependent Qt data.
  120. # Data The location of general architecture-independent Qt data.
  121. # Translations The location of translation information for Qt strings.
  122. # Examples The location for examples upon install.
  123. # Tests The location of installed Qt testcases.
  124. # Settings The location for Qt settings. Not applicable on Windows.
  125. # For bootstrapped
  126. # Sysroot The location of target sysroot
  127. # HostPrefix The prefix for host tools when cross compiling (building tools for both systems)
  128. # HostBinaries The location where to install host tools
  129. # HostData The location where to install host data
  130. # ExternalHostBinaries The location where we already have host tools (when cross compiling, but reusing existing tools)
  131. # TargetSpec The location where to install target mkspec
  132. # HostSpec The location where to install host mkspec
  133. # qmake works fine with separate B, use it by default
  134. SEPB = "${WORKDIR}/build"
  135. B = "${SEPB}"
  136. CONFIGURESTAMPFILE = "${WORKDIR}/qmake5_base_configure.sstate"
  137. qmake5_base_preconfigure() {
  138. if [ -n "${CONFIGURESTAMPFILE}" -a -e "${CONFIGURESTAMPFILE}" ]; then
  139. if [ "`cat ${CONFIGURESTAMPFILE}`" != "${BB_TASKHASH}" -a "${S}" != "${B}" ]; then
  140. echo "Previously configured separate build directory detected, cleaning ${B}"
  141. rm -rf ${B}
  142. mkdir ${B}
  143. fi
  144. fi
  145. }
  146. qmake5_base_postconfigure(){
  147. if [ -n "${CONFIGURESTAMPFILE}" ]; then
  148. echo ${BB_TASKHASH} > ${CONFIGURESTAMPFILE}
  149. fi
  150. }
  151. EXTRAQCONFFUNCS ??= ""
  152. do_configure[prefuncs] += "qmake5_base_preconfigure ${EXTRAQCONFFUNCS}"
  153. do_configure[postfuncs] += "qmake5_base_postconfigure"
  154. addtask generate_qt_config_file after do_patch before do_configure
  155. qmake5_base_do_configure () {
  156. if [ -z "${QMAKE_PROFILES}" ]; then
  157. PROFILES="`ls ${S}/*.pro`"
  158. else
  159. PROFILES="${QMAKE_PROFILES}"
  160. bbnote "qmake using profiles: '${QMAKE_PROFILES}'"
  161. fi
  162. if [ ! -z "${EXTRA_QMAKEVARS_POST}" ]; then
  163. AFTER="-after"
  164. QMAKE_VARSUBST_POST="${EXTRA_QMAKEVARS_POST}"
  165. bbnote "qmake postvar substitution: '${EXTRA_QMAKEVARS_POST}'"
  166. fi
  167. if [ ! -z "${EXTRA_QMAKEVARS_PRE}" ]; then
  168. QMAKE_VARSUBST_PRE="${EXTRA_QMAKEVARS_PRE}"
  169. bbnote "qmake prevar substitution: '${EXTRA_QMAKEVARS_PRE}'"
  170. fi
  171. if [ ! -z "${EXTRA_QMAKEVARS_CONFIGURE}" ]; then
  172. QMAKE_VARSUBST_CONFIGURE="${EXTRA_QMAKEVARS_CONFIGURE}"
  173. bbnote "qmake configure substitution: '${EXTRA_QMAKEVARS_CONFIGURE}'"
  174. fi
  175. # for config.tests to read this
  176. export QMAKE_MAKE_ARGS="${EXTRA_OEMAKE}"
  177. CMD="${OE_QMAKE_QMAKE} -makefile -o Makefile ${OE_QMAKE_DEBUG_OUTPUT} ${OE_QMAKE_RECURSIVE} $QMAKE_VARSUBST_PRE $AFTER $PROFILES $QMAKE_VARSUBST_POST -- $QMAKE_VARSUBST_CONFIGURE"
  178. ${OE_QMAKE_QMAKE} -makefile -o Makefile ${OE_QMAKE_DEBUG_OUTPUT} ${OE_QMAKE_RECURSIVE} $QMAKE_VARSUBST_PRE $AFTER $PROFILES $QMAKE_VARSUBST_POST -- $QMAKE_VARSUBST_CONFIGURE || die "Error calling $CMD"
  179. }
  180. qmake5_base_native_do_install() {
  181. oe_runmake install INSTALL_ROOT=${D}
  182. find "${D}" -ignore_readdir_race -name "*.la" -delete
  183. if ls ${D}${libdir}/pkgconfig/Qt5*.pc >/dev/null 2>/dev/null; then
  184. sed -i "s@-L${STAGING_LIBDIR}@-L\${libdir}@g" ${D}${libdir}/pkgconfig/Qt5*.pc
  185. fi
  186. }
  187. qmake5_base_fix_install() {
  188. STAGING_PATH=$1
  189. if [ -d ${D}${STAGING_PATH} ] ; then
  190. echo "Some files are installed in wrong directory ${D}${STAGING_PATH}"
  191. cp -ra ${D}${STAGING_PATH}/* ${D}
  192. rm -rf ${D}${STAGING_PATH}
  193. # remove empty dirs
  194. TMP=`dirname ${D}${STAGING_PATH}`
  195. while test ${TMP} != ${D}; do
  196. rmdir ${TMP}
  197. TMP=`dirname ${TMP}`;
  198. done
  199. fi
  200. }
  201. qmake5_base_do_install() {
  202. # Fix install paths for all
  203. find . -name "Makefile*" | xargs -r sed -i "s,(INSTALL_ROOT)${STAGING_DIR_TARGET},(INSTALL_ROOT),g"
  204. find . -name "Makefile*" | xargs -r sed -i "s,(INSTALL_ROOT)${STAGING_DIR_HOST},(INSTALL_ROOT),g"
  205. find . -name "Makefile*" | xargs -r sed -i "s,(INSTALL_ROOT)${STAGING_DIR_NATIVE},(INSTALL_ROOT),g"
  206. oe_runmake install INSTALL_ROOT=${D}
  207. # everything except HostData and HostBinaries is prefixed with sysroot value,
  208. # but we cannot remove sysroot override, because that's useful for pkg-config etc
  209. # concurrent builds may cause qmake to regenerate Makefiles and override the above
  210. # sed changes. If that happens, move files manually to correct location.
  211. qmake5_base_fix_install ${STAGING_DIR_TARGET}
  212. qmake5_base_fix_install ${STAGING_DIR_HOST}
  213. qmake5_base_fix_install ${STAGING_DIR_NATIVE}
  214. # Replace host paths with qmake built-in properties
  215. find ${D} \( -name "*.pri" -or -name "*.prl" \) -exec \
  216. sed -i -e 's|${STAGING_DIR_NATIVE}|$$[QT_HOST_PREFIX/get]|g' \
  217. -e 's|${STAGING_DIR_HOST}|$$[QT_SYSROOT]|g' {} \
  218. -e '/QMAKE_PRL_BUILD_DIR/d' {} \;
  219. # Replace host paths with pkg-config built-in variable
  220. find ${D} -name "*.pc" -exec \
  221. sed -i -e 's|prefix=${STAGING_DIR_HOST}|prefix=|g' \
  222. -e 's|${STAGING_DIR_HOST}|${pc_sysrootdir}|g' {} \;
  223. # Replace resolved lib path with the lib name
  224. find ${D} -name "*.cmake" -exec \
  225. sed -i -e 's@/[^;]*/lib\([^;]*\)\.\(so\|a\)@\1@g' {} \;
  226. }