diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index c9fe25b7de14..f1d75e5c9d16 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -479,7 +479,11 @@ be passed to [shared and static libraries](#library). - `_pch` precompiled header file to use for the given language - `_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 @@ -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 @@ -1035,8 +1040,12 @@ 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 @@ -1044,7 +1053,11 @@ The keyword arguments for this are the same as for 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. diff --git a/docs/markdown/snippets/target_type_dict.md b/docs/markdown/snippets/target_type_dict.md new file mode 100644 index 000000000000..6212ab09fb29 --- /dev/null +++ b/docs/markdown/snippets/target_type_dict.md @@ -0,0 +1,26 @@ +## Dictionary for `name_prefix`, `name_suffix` and `_args` + +`name_prefix`, `name_suffix` and `_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) +```