| 1 |
--- |
| 2 |
title: Release 0.51.0 |
| 3 |
short-description: Release notes for 0.51.0 |
| 4 |
... |
| 5 |
|
| 6 |
# New features |
| 7 |
|
| 8 |
## (C) Preprocessor flag handling |
| 9 |
|
| 10 |
Meson previously stored `CPPFLAGS` and per-language compilation flags |
| 11 |
separately. (That latter would come from `CFLAGS`, `CXXFLAGS`, etc., |
| 12 |
along with `<lang>_args` options whether specified no the command-line |
| 13 |
interface (`-D..`), `meson.build` (`default_options`), or cross file |
| 14 |
(`[properties]`).) This was mostly unobservable, except for certain |
| 15 |
preprocessor-only checks like `check_header` would only use the |
| 16 |
preprocessor flags, leading to confusion if some `-isystem` was in |
| 17 |
`CFLAGS` but not `CPPFLAGS`. Now, they are lumped together, and |
| 18 |
`CPPFLAGS`, for the languages which are deemed to care to about, is |
| 19 |
just another source of compilation flags along with the others already |
| 20 |
listed. |
| 21 |
|
| 22 |
## Sanity checking compilers with user flags |
| 23 |
|
| 24 |
Sanity checks previously only used user-specified flags for cross |
| 25 |
compilers, but now do in all cases. |
| 26 |
|
| 27 |
All compilers Meson might decide to use for the build are "sanity |
| 28 |
checked" before other tests are run. This usually involves building |
| 29 |
simple executable and trying to run it. Previously user flags |
| 30 |
(compilation and/or linking flags) were used for sanity checking cross |
| 31 |
compilers, but not native compilers. This is because such flags might |
| 32 |
be essential for a cross binary to succeed, but usually aren't for a |
| 33 |
native compiler. |
| 34 |
|
| 35 |
In recent releases, there has been an effort to minimize the |
| 36 |
special-casing of cross or native builds so as to make building more |
| 37 |
predictable in less-tested cases. Since this the user flags are |
| 38 |
necessary for cross, but not harmful for native, it makes more sense |
| 39 |
to use them in all sanity checks than use them in no sanity checks, so |
| 40 |
this is what we now do. |
| 41 |
|
| 42 |
## New `sourceset` module |
| 43 |
|
| 44 |
A new module, `sourceset`, was added to help building many binaries |
| 45 |
from the same source files. Source sets associate source files and |
| 46 |
dependencies to keys in a `configuration_data` object or a dictionary; |
| 47 |
they then take multiple `configuration_data` objects or dictionaries, |
| 48 |
and compute the set of source files and dependencies for each of those |
| 49 |
configurations. |
| 50 |
|
| 51 |
## n_debug=if-release and buildtype=plain means no asserts |
| 52 |
|
| 53 |
Previously if this combination was used then assertions were enabled, |
| 54 |
which is fairly surprising behavior. |
| 55 |
|
| 56 |
## `target_type` in `build_targets` accepts the value 'shared_module' |
| 57 |
|
| 58 |
The `target_type` keyword argument in `build_target()` now accepts the |
| 59 |
value `'shared_module'`. |
| 60 |
|
| 61 |
The statement |
| 62 |
|
| 63 |
```meson |
| 64 |
build_target(..., target_type: 'shared_module') |
| 65 |
``` |
| 66 |
|
| 67 |
is equivalent to this: |
| 68 |
|
| 69 |
```meson |
| 70 |
shared_module(...) |
| 71 |
``` |
| 72 |
|
| 73 |
## New modules kwarg for python.find_installation |
| 74 |
|
| 75 |
This mirrors the modules argument that some kinds of dependencies |
| 76 |
(such as qt, llvm, and cmake based dependencies) take, allowing you to |
| 77 |
check that a particular module is available when getting a python |
| 78 |
version. |
| 79 |
|
| 80 |
```meson |
| 81 |
py = import('python').find_installation('python3', modules : ['numpy']) |
| 82 |
``` |
| 83 |
|
| 84 |
## Support for the Intel Compiler on Windows (ICL) |
| 85 |
|
| 86 |
Support has been added for ICL.EXE and ifort on windows. The support |
| 87 |
should be on part with ICC support on Linux/MacOS. The ICL C/C++ |
| 88 |
compiler behaves like Microsoft's CL.EXE rather than GCC/Clang like |
| 89 |
ICC does, and has a different id, `intel-cl` to differentiate it. |
| 90 |
|
| 91 |
```meson |
| 92 |
cc = meson.get_compiler('c') |
| 93 |
if cc.get_id == 'intel-cl' |
| 94 |
add_project_argument('/Qfoobar:yes', language : 'c') |
| 95 |
endif |
| 96 |
``` |
| 97 |
|
| 98 |
## Added basic support for the Xtensa CPU toolchain |
| 99 |
|
| 100 |
You can now use `xt-xcc`, `xt-xc++`, `xt-nm`, etc... on your cross |
| 101 |
compilation file and Meson won't complain about an unknown toolchain. |
| 102 |
|
| 103 |
|
| 104 |
## Dependency objects now have a get_variable method |
| 105 |
|
| 106 |
This is a generic replacement for type specific variable getters such as |
| 107 |
`ConfigToolDependency.get_configtool_variable` and |
| 108 |
`PkgConfigDependency.get_pkgconfig_variable`, and is the only way to query |
| 109 |
such variables from cmake dependencies. |
| 110 |
|
| 111 |
This method allows you to get variables without knowing the kind of |
| 112 |
dependency you have. |
| 113 |
|
| 114 |
```meson |
| 115 |
dep = dependency('could_be_cmake_or_pkgconfig') |
| 116 |
# cmake returns 'YES', pkg-config returns 'ON' |
| 117 |
if ['YES', 'ON'].contains(dep.get_variable(pkgconfig : 'var-name', cmake : 'COP_VAR_NAME', default_value : 'NO')) |
| 118 |
error('Cannot build your project when dep is built with var-name support') |
| 119 |
endif |
| 120 |
``` |
| 121 |
|
| 122 |
## CMake prefix path overrides |
| 123 |
|
| 124 |
When using pkg-config as a dependency resolver we can pass |
| 125 |
`-Dpkg_config_path=$somepath` to extend or overwrite where pkg-config |
| 126 |
will search for dependencies. Now cmake can do the same, as long as |
| 127 |
the dependency uses a ${Name}Config.cmake file (not a |
| 128 |
Find{$Name}.cmake file), by passing |
| 129 |
`-Dcmake_prefix_path=list,of,paths`. It is important that point this |
| 130 |
at the prefix that the dependency is installed into, not the cmake |
| 131 |
path. |
| 132 |
|
| 133 |
If you have installed something to `/tmp/dep`, which has a layout like: |
| 134 |
``` |
| 135 |
/tmp/dep/lib/cmake |
| 136 |
/tmp/dep/bin |
| 137 |
``` |
| 138 |
|
| 139 |
then invoke Meson as `meson setup builddir/ -Dcmake_prefix_path=/tmp/dep` |
| 140 |
|
| 141 |
## Tests that should fail but did not are now errors |
| 142 |
|
| 143 |
You can tag a test as needing to fail like this: |
| 144 |
|
| 145 |
```meson |
| 146 |
test('shouldfail', exe, should_fail: true) |
| 147 |
``` |
| 148 |
|
| 149 |
If the test passes the problem is reported in the error logs but due |
| 150 |
to a bug it was not reported in the test runner's exit code. Starting |
| 151 |
from this release the unexpected passes are properly reported in the |
| 152 |
test runner's exit code. This means that test runs that were passing |
| 153 |
in earlier versions of Meson will report failures with the current |
| 154 |
version. This is a good thing, though, since it reveals an error in |
| 155 |
your test suite that has, until now, gone unnoticed. |
| 156 |
|
| 157 |
## New target keyword argument: `link_language` |
| 158 |
|
| 159 |
There may be situations for which the user wishes to manually specify |
| 160 |
the linking language. For example, a C++ target may link C, Fortran, |
| 161 |
etc. and perhaps the automatic detection in Meson does not pick the |
| 162 |
desired compiler. The user can manually choose the linker by language |
| 163 |
per-target like this example of a target where one wishes to link with |
| 164 |
the Fortran compiler: |
| 165 |
|
| 166 |
```meson |
| 167 |
executable(..., link_language : 'fortran') |
| 168 |
``` |
| 169 |
|
| 170 |
A specific case this option fixes is where for example the main |
| 171 |
program is Fortran that calls C and/or C++ code. The automatic |
| 172 |
language detection of Meson prioritizes C/C++, and so an compile-time |
| 173 |
error results like `undefined reference to main`, because the linker |
| 174 |
is C or C++ instead of Fortran, which is fixed by this per-target |
| 175 |
override. |
| 176 |
|
| 177 |
## New module to parse kconfig output files |
| 178 |
|
| 179 |
The new module `unstable-kconfig` adds the ability to parse and use |
| 180 |
kconfig output files from `meson.build`. |
| 181 |
|
| 182 |
|
| 183 |
## Add new `meson subprojects foreach` command |
| 184 |
|
| 185 |
`meson subprojects` has learned a new `foreach` command which accepts |
| 186 |
a command with arguments and executes it in each subproject directory. |
| 187 |
|
| 188 |
For example this can be useful to check the status of subprojects |
| 189 |
(e.g. with `git status` or `git diff`) before performing other actions |
| 190 |
on them. |
| 191 |
|
| 192 |
|
| 193 |
## Added c17 and c18 as c_std values for recent GCC and Clang Versions |
| 194 |
|
| 195 |
For gcc version 8.0 and later, the values c17, c18, gnu17, and gnu18 |
| 196 |
were added to the accepted values for built-in compiler option c_std. |
| 197 |
|
| 198 |
For Clang version 10.0 and later on Apple OSX (Darwin), and for |
| 199 |
version 7.0 and later on other platforms, the values c17 and gnu17 |
| 200 |
were added as c_std values. |
| 201 |
|
| 202 |
## gpgme dependency now supports gpgme-config |
| 203 |
|
| 204 |
Previously, we could only detect GPGME with custom invocations of |
| 205 |
`gpgme-config` or when the GPGME version was recent enough (>=1.13.0) |
| 206 |
to install pkg-config files. Now we added support to Meson allowing us |
| 207 |
to use `dependency('gpgme')` and fall back on `gpgme-config` parsing. |
| 208 |
|
| 209 |
## Can link against custom targets |
| 210 |
|
| 211 |
The output of `custom_target` and `custom_target[i]` can be used in |
| 212 |
`link_with` and `link_whole` keyword arguments. This is useful for |
| 213 |
integrating custom code generator steps, but note that there are many |
| 214 |
limitations: |
| 215 |
|
| 216 |
- Meson cannot know about link dependencies of the custom target. If |
| 217 |
the target requires further link libraries, you need to add them manually |
| 218 |
|
| 219 |
- The user is responsible for ensuring that the code produced by |
| 220 |
different toolchains are compatible. |
| 221 |
|
| 222 |
- `custom_target` may only be used when it has a single output file. |
| 223 |
Use `custom_target[i]` when dealing with multiple output files. |
| 224 |
|
| 225 |
- The output file must have the correct file name extension. |
| 226 |
|
| 227 |
|
| 228 |
## Removed the deprecated `--target-files` API |
| 229 |
|
| 230 |
The `--target-files` introspection API is now no longer available. The same |
| 231 |
information can be queried with the `--targets` API introduced in 0.50.0. |
| 232 |
|
| 233 |
## Generators have a new `depends` keyword argument |
| 234 |
|
| 235 |
Generators can now specify extra dependencies with the `depends` |
| 236 |
keyword argument. It matches the behaviour of the same argument in |
| 237 |
other functions and specifies that the given targets must be built |
| 238 |
before the generator can be run. This is used in cases such as this |
| 239 |
one where you need to tell a generator to indirectly invoke a |
| 240 |
different program. |
| 241 |
|
| 242 |
```meson |
| 243 |
exe = executable(...) |
| 244 |
cg = generator(program_runner, |
| 245 |
output: ['@[email protected]'], |
| 246 |
arguments: ['--use-tool=' + exe.full_path(), '@INPUT@', '@OUTPUT@'], |
| 247 |
depends: exe) |
| 248 |
``` |
| 249 |
|
| 250 |
## Specifying options per mer machine |
| 251 |
|
| 252 |
Previously, no cross builds were controllable from the command line. |
| 253 |
Machine-specific options like the pkg-config path and compiler options |
| 254 |
only affected native targets, that is to say all targets in native |
| 255 |
builds, and `native: true` targets in cross builds. Now, prefix the |
| 256 |
option with `build.` to affect build machine targets, and leave it |
| 257 |
unprefixed to affect host machine targets. |
| 258 |
|
| 259 |
For those trying to ensure native and cross builds to the same |
| 260 |
platform produced the same result, the old way was frustrating because |
| 261 |
very different invocations were needed to affect the same targets, if |
| 262 |
it was possible at all. Now, the same command line arguments affect |
| 263 |
the same targets everywhere --- Meson is closer to ignoring whether |
| 264 |
the "overall" build is native or cross, and just caring about whether |
| 265 |
individual targets are for the build or host machines. |
| 266 |
|
| 267 |
|
| 268 |
## subproject.get_variable() now accepts a `fallback` argument |
| 269 |
|
| 270 |
Similar to `get_variable`, a fallback argument can now be passed to |
| 271 |
`subproject.get_variable()`, it will be returned if the requested |
| 272 |
variable name did not exist. |
| 273 |
|
| 274 |
``` meson |
| 275 |
var = subproject.get_variable('does-not-exist', 'fallback-value') |
| 276 |
``` |
| 277 |
|
| 278 |
## Add keyword `static` to `find_library` |
| 279 |
|
| 280 |
`find_library` has learned the `static` keyword. They keyword must be |
| 281 |
a boolean, where `true` only searches for static libraries and `false` |
| 282 |
only searches for dynamic/shared. Leaving the keyword unset will keep |
| 283 |
the old behavior of first searching for dynamic and then falling back |
| 284 |
to static. |
| 285 |
|
| 286 |
## Fortran `include` statements recursively parsed |
| 287 |
|
| 288 |
While non-standard and generally not recommended, some legacy Fortran |
| 289 |
programs use `include` directives to inject code inline. Since v0.51, |
| 290 |
Meson can handle Fortran `include` directives recursively. |
| 291 |
|
| 292 |
DO NOT list `include` files as sources for a target, as in general |
| 293 |
their syntax is not correct as a standalone target. In general |
| 294 |
`include` files are meant to be injected inline as if they were copy |
| 295 |
and pasted into the source file. |
| 296 |
|
| 297 |
`include` was never standard and was superseded by Fortran 90 `module`. |
| 298 |
|
| 299 |
The `include` file is only recognized by Meson if it has a Fortran |
| 300 |
file suffix, such as `.f` `.F` `.f90` `.F90` or similar. This is to |
| 301 |
avoid deeply nested scanning of large external legacy C libraries that |
| 302 |
only interface to Fortran by `include biglib.h` or similar. |
| 303 |
|
| 304 |
## CMake subprojects |
| 305 |
|
| 306 |
Meson can now directly consume CMake based subprojects with the |
| 307 |
CMake module. |
| 308 |
|
| 309 |
Using CMake subprojects is similar to using the "normal" Meson |
| 310 |
subprojects. They also have to be located in the `subprojects` |
| 311 |
directory. |
| 312 |
|
| 313 |
Example: |
| 314 |
|
| 315 |
```cmake |
| 316 |
add_library(cm_lib SHARED ${SOURCES}) |
| 317 |
``` |
| 318 |
|
| 319 |
```meson |
| 320 |
cmake = import('cmake') |
| 321 |
|
| 322 |
# Configure the CMake project |
| 323 |
sub_proj = cmake.subproject('libsimple_cmake') |
| 324 |
|
| 325 |
# Fetch the dependency object |
| 326 |
cm_lib = sub_proj.dependency('cm_lib') |
| 327 |
|
| 328 |
executable('exe1', ['sources'], dependencies: [cm_lib]) |
| 329 |
``` |
| 330 |
|
| 331 |
It should be noted that not all projects are guaranteed to work. The |
| 332 |
safest approach would still be to create a `meson.build` for the |
| 333 |
subprojects in question. |
| 334 |
|
| 335 |
## Multiple cross files can be specified |
| 336 |
|
| 337 |
`--cross-file` can be passed multiple times, with the configuration files overlaying the same way as `--native-file`. |