Skip to content

Commit

Permalink
cmake: configure_package_config_file can now take a dict
Browse files Browse the repository at this point in the history
  • Loading branch information
Tachi107 authored and eli-schwartz committed Feb 27, 2022
1 parent c42a3fd commit fcca265
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/markdown/CMake-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ the `configuration` parameter.
* `input`: the template file where that will be treated for variable substitutions contained in `configuration`.
* `install_dir`: optional installation directory, it defaults to `$(libdir)/cmake/$(name)`.
* `configuration`: a `configuration_data` object that will be used for variable substitution in the template file.
*Since 0.62.0* it can take a dictionary instead.


Example:
Expand Down
5 changes: 5 additions & 0 deletions docs/markdown/snippets/cmake_configure_package_config_dict.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## cmake.configure_package_config_file can now take a dict

The `configuration` kwarg of the `configure_package_config_file()` function
from the `cmake` module can now take a dict object, just like the regular
`configure_file()` function.
7 changes: 5 additions & 2 deletions mesonbuild/modules/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class WriteBasicPackageVersionFile(TypedDict):

class ConfigurePackageConfigFile(TypedDict):

configuration: build.ConfigurationData
configuration: T.Union[build.ConfigurationData, dict]
input: T.Union[str, mesonlib.File]
install_dir: T.Optional[str]
name: str
Expand Down Expand Up @@ -347,7 +347,7 @@ def create_package_file(self, infile, outfile, PACKAGE_RELATIVE_PATH, extra, con
@noPosargs
@typed_kwargs(
'cmake.configure_package_config_file',
KwargInfo('configuration', build.ConfigurationData, required=True),
KwargInfo('configuration', (build.ConfigurationData, dict), required=True),
KwargInfo('input',
(str, mesonlib.File, ContainerTypeInfo(list, mesonlib.File)), required=True,
validator=lambda x: 'requires exactly one file' if isinstance(x, list) and len(x) != 1 else None,
Expand All @@ -372,6 +372,9 @@ def configure_package_config_file(self, state, args, kwargs: 'ConfigurePackageCo
install_dir = os.path.join(state.environment.coredata.get_option(mesonlib.OptionKey('libdir')), 'cmake', name)

conf = kwargs['configuration']
if isinstance(conf, dict):
FeatureNew.single_use('cmake.configure_package_config_file dict as configuration', '0.62.0', state.subproject, location=state.current_node)
conf = build.ConfigurationData(conf)

prefix = state.environment.coredata.get_option(mesonlib.OptionKey('prefix'))
abs_install_dir = install_dir
Expand Down
4 changes: 1 addition & 3 deletions test cases/cmake/20 cmake file/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ project(

cmake = import('cmake')

cmake_conf = configuration_data()
cmake_conf.set_quoted('foo', 'bar')
cmake.configure_package_config_file(
name : 'foolib',
input : 'foolib.cmake.in',
install_dir : get_option('libdir') / 'cmake',
configuration : cmake_conf,
configuration : {'foo': '"bar"'},
)

0 comments on commit fcca265

Please sign in to comment.