Skip to content

Commit

Permalink
Add documentation for name_prefix, name_suffix and lan_args dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
xclaesse committed Nov 2, 2018
1 parent b6d9416 commit 1e6cd82
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
21 changes: 17 additions & 4 deletions docs/markdown/Reference-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,11 @@ be passed to [shared and static libraries](#library).

- `<languagename>_pch` precompiled header file to use for the given language
- `<languagename>_args` compiler flags to use for the given language;
eg: `cpp_args` for C++
eg: `cpp_args` for C++. Since *0.49.0* it can be a dictionary mapping target
type to an array of args, the value mapped to the current build type will be
used. For example passing `c_args: {'static_library': '-DSTATIC'}` means that
if a static library is built `STATIC` is defined, but not for shared
libraries, executables, etc.
- `build_by_default` causes, when set to true, to have this target be
built by default, that is, when invoking plain `ninja`, the default
value is true for all built target types, since 0.38.0
Expand Down Expand Up @@ -564,6 +568,7 @@ creating the final list.
The returned object also has methods that are documented in the
[object methods section](#build-target-object) below.


### find_library()

This function is deprecated and in the 0.31.0 release it was moved to
Expand Down Expand Up @@ -1035,16 +1040,24 @@ The keyword arguments for this are the same as for
- `name_prefix` the string that will be used as the prefix for the
target output filename by overriding the default (only used for
libraries). By default this is `lib` on all platforms and compilers
except with MSVC shared libraries where it is omitted to follow
convention.
except with MSVCshared libraries where it is omitted to follow
convention. Since *0.49.0* it can be a dictionary mapping target type to a
string, the value mapped to the current build type will be used. For example
passing `name_prefix: {'static_library': 'lib'}` means that if a static
library is built `name_prefix` is `lib`, but for shared library `name_prefix`
is undefined and thus the default value is used.
- `name_suffix` the string that will be used as the suffix for the
target output filename by overriding the default (see also:
[executable()](#executable)). By default, for shared libraries this
is `dylib` on macOS, `dll` on Windows, and `so` everywhere else.
For static libraries, it is `a` everywhere. By convention MSVC
static libraries use the `lib` suffix, but we use `a` to avoid a
potential name clash with shared libraries which also generate
`xxx.lib` import files.
`xxx.lib` import files. Since *0.49.0* it can be a dictionary mapping target
type to a string, the value mapped to the current build type will be used.
For example passing `name_suffix: {'static_library': 'a'}` means that if a
static library is built `name_suffix` is `a`, but for shared library
`name_suffix` is undefined and thus the default value is used.
- `rust_crate_type` specifies the crate type for Rust
libraries. Defaults to `dylib` for shared libraries and `rlib` for
static libraries.
Expand Down
26 changes: 26 additions & 0 deletions docs/markdown/snippets/target_type_dict.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Dictionary for `name_prefix`, `name_suffix` and `<lang>_args`

`name_prefix`, `name_suffix` and `<lang>_args` keyword arguments of functions
like `library()` and `build_target()` now accept a dictionary mapping the target
type to the value. This is used when for example different c_args must be passed
to the static and shared library built by `both_libraries()`.

```meson
cargs = {
'static_library': '-DSTATIC',
'shared_library': '-DSHARED',
'executable': ['-DEXECUTABLE', '-DMY_APP'],
}
namesuffix = {
'static_library': 'a',
'shared_library': 'so',
}
# sources will be built twice with different cflags, the static library will
# have .a extension on all platforms and the shared library will have the .so
# extension on all platforms
both_libraries('foo', sources, c_args: cargs, name_suffix: namesuffix)
# EXECUTABLE and MY_APP will be defined when building sources, and it will use
# the default extension on the current platform because 'executable' is not in
# the namesuffix dictionary
executable('app', c_args: cargs, name_suffix: namesuffix)
```

0 comments on commit 1e6cd82

Please sign in to comment.