blob: da58cb4bec6ac5ec3be535a2bc1737b48a6899b7 [file] [log] [blame]
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001inherit python3native meson-routines
Brad Bishop316dfdd2018-06-25 12:45:53 -04002
Patrick Williams213cb262021-08-07 19:21:33 -05003DEPENDS:append = " meson-native ninja-native"
Brad Bishop316dfdd2018-06-25 12:45:53 -04004
5# As Meson enforces out-of-tree builds we can just use cleandirs
6B = "${WORKDIR}/build"
7do_configure[cleandirs] = "${B}"
8
9# Where the meson.build build configuration is
10MESON_SOURCEPATH = "${S}"
11
12def noprefix(var, d):
13 return d.getVar(var).replace(d.getVar('prefix') + '/', '', 1)
14
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050015MESON_BUILDTYPE ?= "${@oe.utils.vartrue('DEBUG_BUILD', 'debug', 'plain', d)}"
16MESON_BUILDTYPE[vardeps] += "DEBUG_BUILD"
Brad Bishop316dfdd2018-06-25 12:45:53 -040017MESONOPTS = " --prefix ${prefix} \
Andrew Geissler82c905d2020-04-13 13:39:40 -050018 --buildtype ${MESON_BUILDTYPE} \
Brad Bishop316dfdd2018-06-25 12:45:53 -040019 --bindir ${@noprefix('bindir', d)} \
20 --sbindir ${@noprefix('sbindir', d)} \
21 --datadir ${@noprefix('datadir', d)} \
22 --libdir ${@noprefix('libdir', d)} \
23 --libexecdir ${@noprefix('libexecdir', d)} \
24 --includedir ${@noprefix('includedir', d)} \
25 --mandir ${@noprefix('mandir', d)} \
26 --infodir ${@noprefix('infodir', d)} \
27 --sysconfdir ${sysconfdir} \
28 --localstatedir ${localstatedir} \
Andrew Geissler82c905d2020-04-13 13:39:40 -050029 --sharedstatedir ${sharedstatedir} \
Andrew Geissler95ac1b82021-03-31 14:34:31 -050030 --wrap-mode nodownload \
31 --native-file ${WORKDIR}/meson.native"
Brad Bishop316dfdd2018-06-25 12:45:53 -040032
Patrick Williams213cb262021-08-07 19:21:33 -050033EXTRA_OEMESON:append = " ${PACKAGECONFIG_CONFARGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040034
35MESON_CROSS_FILE = ""
Patrick Williams213cb262021-08-07 19:21:33 -050036MESON_CROSS_FILE:class-target = "--cross-file ${WORKDIR}/meson.cross"
37MESON_CROSS_FILE:class-nativesdk = "--cross-file ${WORKDIR}/meson.cross"
Brad Bishop316dfdd2018-06-25 12:45:53 -040038
Brad Bishop316dfdd2018-06-25 12:45:53 -040039addtask write_config before do_configure
Brad Bishop96ff1982019-08-19 13:50:42 -040040do_write_config[vardeps] += "CC CXX LD AR NM STRIP READELF CFLAGS CXXFLAGS LDFLAGS"
Brad Bishop316dfdd2018-06-25 12:45:53 -040041do_write_config() {
42 # This needs to be Py to split the args into single-element lists
43 cat >${WORKDIR}/meson.cross <<EOF
44[binaries]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080045c = ${@meson_array('CC', d)}
46cpp = ${@meson_array('CXX', d)}
47ar = ${@meson_array('AR', d)}
48nm = ${@meson_array('NM', d)}
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080049strip = ${@meson_array('STRIP', d)}
50readelf = ${@meson_array('READELF', d)}
Brad Bishop316dfdd2018-06-25 12:45:53 -040051pkgconfig = 'pkg-config'
Brad Bishop08902b02019-08-20 09:16:51 -040052llvm-config = 'llvm-config${LLVMVERSION}'
Andrew Geissler635e0e42020-08-21 15:58:33 -050053cups-config = 'cups-config'
Andrew Geissler90fd73c2021-03-05 15:25:55 -060054g-ir-scanner = '${STAGING_BINDIR}/g-ir-scanner-wrapper'
55g-ir-compiler = '${STAGING_BINDIR}/g-ir-compiler-wrapper'
Brad Bishop316dfdd2018-06-25 12:45:53 -040056
Andrew Geissler95ac1b82021-03-31 14:34:31 -050057[built-in options]
Brad Bishop96ff1982019-08-19 13:50:42 -040058c_args = ${@meson_array('CFLAGS', d)}
59c_link_args = ${@meson_array('LDFLAGS', d)}
60cpp_args = ${@meson_array('CXXFLAGS', d)}
61cpp_link_args = ${@meson_array('LDFLAGS', d)}
Andrew Geissler95ac1b82021-03-31 14:34:31 -050062
63[properties]
64needs_exe_wrapper = true
Brad Bishop316dfdd2018-06-25 12:45:53 -040065gtkdoc_exe_wrapper = '${B}/gtkdoc-qemuwrapper'
66
67[host_machine]
Andrew Geissler82c905d2020-04-13 13:39:40 -050068system = '${@meson_operating_system('HOST_OS', d)}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080069cpu_family = '${@meson_cpu_family('HOST_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040070cpu = '${HOST_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080071endian = '${@meson_endian('HOST', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040072
73[target_machine]
Andrew Geissler82c905d2020-04-13 13:39:40 -050074system = '${@meson_operating_system('TARGET_OS', d)}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080075cpu_family = '${@meson_cpu_family('TARGET_ARCH', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040076cpu = '${TARGET_ARCH}'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080077endian = '${@meson_endian('TARGET', d)}'
Brad Bishop316dfdd2018-06-25 12:45:53 -040078EOF
Andrew Geissler95ac1b82021-03-31 14:34:31 -050079
80 cat >${WORKDIR}/meson.native <<EOF
81[binaries]
82c = ${@meson_array('BUILD_CC', d)}
83cpp = ${@meson_array('BUILD_CXX', d)}
84ar = ${@meson_array('BUILD_AR', d)}
85nm = ${@meson_array('BUILD_NM', d)}
86strip = ${@meson_array('BUILD_STRIP', d)}
87readelf = ${@meson_array('BUILD_READELF', d)}
88pkgconfig = 'pkg-config-native'
89
90[built-in options]
91c_args = ${@meson_array('BUILD_CFLAGS', d)}
92c_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
93cpp_args = ${@meson_array('BUILD_CXXFLAGS', d)}
94cpp_link_args = ${@meson_array('BUILD_LDFLAGS', d)}
95EOF
Brad Bishop316dfdd2018-06-25 12:45:53 -040096}
97
Andrew Geissler95ac1b82021-03-31 14:34:31 -050098# Tell externalsrc that changes to this file require a reconfigure
Brad Bishop316dfdd2018-06-25 12:45:53 -040099CONFIGURE_FILES = "meson.build"
100
101meson_do_configure() {
Andrew Geissler82c905d2020-04-13 13:39:40 -0500102 # Meson requires this to be 'bfd, 'lld' or 'gold' from 0.53 onwards
103 # https://github.com/mesonbuild/meson/commit/ef9aeb188ea2bc7353e59916c18901cde90fa2b3
104 unset LD
105
Andrew Geisslereff27472021-10-29 15:35:00 -0500106 # sstate.bbclass no longer removes empty directories to avoid a race (see
107 # commit 4f94d929 "sstate/staging: Handle directory creation race issue").
108 # Unfortunately Python apparently treats an empty egg-info directory as if
109 # the version it previously contained still exists and fails if a newer
110 # version is required, which Meson does. To avoid this, make sure there are
111 # no empty egg-info directories from previous versions left behind. Ignore
112 # all errors from rmdir since the egg-info may be a file rather than a
113 # directory.
114 rmdir ${STAGING_LIBDIR_NATIVE}/${PYTHON_DIR}/site-packages/*.egg-info 2>/dev/null || :
115
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800116 # Work around "Meson fails if /tmp is mounted with noexec #2972"
117 mkdir -p "${B}/meson-private/tmp"
118 export TMPDIR="${B}/meson-private/tmp"
119 bbnote Executing meson ${EXTRA_OEMESON}...
Brad Bishop316dfdd2018-06-25 12:45:53 -0400120 if ! meson ${MESONOPTS} "${MESON_SOURCEPATH}" "${B}" ${MESON_CROSS_FILE} ${EXTRA_OEMESON}; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400121 bbfatal_log meson failed
122 fi
123}
124
Andrew Geissler82c905d2020-04-13 13:39:40 -0500125python meson_do_qa_configure() {
126 import re
127 warn_re = re.compile(r"^WARNING: Cross property (.+) is using default value (.+)$", re.MULTILINE)
Andrew Geisslerc182c622020-05-15 14:13:32 -0500128 with open(d.expand("${B}/meson-logs/meson-log.txt")) as logfile:
129 log = logfile.read()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500130 for (prop, value) in warn_re.findall(log):
131 bb.warn("Meson cross property %s used without explicit assignment, defaulting to %s" % (prop, value))
132}
133do_configure[postfuncs] += "meson_do_qa_configure"
134
Brad Bishop316dfdd2018-06-25 12:45:53 -0400135do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
136meson_do_compile() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800137 ninja -v ${PARALLEL_MAKE}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400138}
139
140meson_do_install() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800141 DESTDIR='${D}' ninja -v ${PARALLEL_MAKEINST} install
Brad Bishop316dfdd2018-06-25 12:45:53 -0400142}
143
144EXPORT_FUNCTIONS do_configure do_compile do_install