This new cmake module allows to generate cmake package files. This may ease the porting for cmake projects that are exporting cmake package informations for other depending projects. The module uses as much as possible the templates provided by the cmake installation (and so cmake needs to be installed).pull/4799/head
parent
267792174c
commit
ceaebf6bac
7 changed files with 334 additions and 0 deletions
@ -0,0 +1,71 @@ |
|||||||
|
# CMake module |
||||||
|
|
||||||
|
This module provides helper tools for generating cmake package files. |
||||||
|
|
||||||
|
|
||||||
|
## Usage |
||||||
|
|
||||||
|
To use this module, just do: **`cmake = import('cmake')`**. The |
||||||
|
following functions will then be available as methods on the object |
||||||
|
with the name `cmake`. You can, of course, replace the name `cmake` |
||||||
|
with anything else. |
||||||
|
|
||||||
|
### cmake.write_basic_package_version_file() |
||||||
|
|
||||||
|
This function is the equivalent of the corresponding [CMake function](https://cmake.org/cmake/help/v3.11/module/CMakePackageConfigHelpers.html#generating-a-package-version-file), |
||||||
|
it generates a `name` package version file. |
||||||
|
|
||||||
|
* `name`: the name of the package. |
||||||
|
* `version`: the version of the generated package file. |
||||||
|
* `compatibility`: a string indicating the kind of compatibility, the accepted values are |
||||||
|
`AnyNewerVersion`, `SameMajorVersion`, `SameMinorVersion` or `ExactVersion`. |
||||||
|
It defaults to `AnyNewerVersion`. Depending on your cmake installation some kind of |
||||||
|
compatibility may not be available. |
||||||
|
* `install_dir`: optional installation directory, it defaults to `$(libdir)/cmake/$(name)` |
||||||
|
|
||||||
|
|
||||||
|
Example: |
||||||
|
|
||||||
|
```meson |
||||||
|
cmake = import('cmake') |
||||||
|
|
||||||
|
cmake.write_basic_package_version_file(name: 'myProject', version: '1.0.0') |
||||||
|
``` |
||||||
|
|
||||||
|
### cmake.configure_package_config_file() |
||||||
|
|
||||||
|
This function is the equivalent of the corresponding [CMake function](https://cmake.org/cmake/help/v3.11/module/CMakePackageConfigHelpers.html#generating-a-package-configuration-file), |
||||||
|
it generates a `name` package configuration file from the `input` template file. Just like the cmake function |
||||||
|
in this file the `@PACKAGE_INIT@` statement will be replaced by the appropriate piece of cmake code. |
||||||
|
The equivalent `PATH_VARS` argument is given through the `configuration` parameter. |
||||||
|
|
||||||
|
* `name`: the name of the package. |
||||||
|
* `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. |
||||||
|
|
||||||
|
|
||||||
|
Example: |
||||||
|
|
||||||
|
meson.build: |
||||||
|
|
||||||
|
```meson |
||||||
|
cmake = import('cmake') |
||||||
|
|
||||||
|
conf = configuration_data() |
||||||
|
conf.set_quoted('VAR', 'variable value') |
||||||
|
|
||||||
|
cmake.configure_package_config_file( |
||||||
|
name: 'myProject', |
||||||
|
input: 'myProject.cmake.in', |
||||||
|
configuration: conf |
||||||
|
) |
||||||
|
``` |
||||||
|
|
||||||
|
myProject.cmake.in: |
||||||
|
|
||||||
|
```text |
||||||
|
@PACKAGE_INIT@ |
||||||
|
|
||||||
|
set(MYVAR VAR) |
||||||
|
``` |
@ -0,0 +1,4 @@ |
|||||||
|
cmake_minimum_required(VERSION 2.8) |
||||||
|
project(cmakeMeson C) |
||||||
|
|
||||||
|
find_package(cmakeModule REQUIRED) |
@ -0,0 +1,2 @@ |
|||||||
|
usr/lib/cmake/cmakeModule/cmakeModuleConfig.cmake |
||||||
|
usr/lib/cmake/cmakeModule/cmakeModuleConfigVersion.cmake |
@ -0,0 +1,31 @@ |
|||||||
|
project('cmakeModule', 'c', version: '1.0.0') |
||||||
|
|
||||||
|
if build_machine.system() == 'cygwin' |
||||||
|
error('MESON_SKIP_TEST CMake is broken on Cygwin.') |
||||||
|
endif |
||||||
|
|
||||||
|
cmake_bin = find_program('cmake', required: false) |
||||||
|
if not cmake_bin.found() |
||||||
|
error('MESON_SKIP_TEST CMake not installed.') |
||||||
|
endif |
||||||
|
|
||||||
|
cc = meson.get_compiler('c') |
||||||
|
if cc.get_id() == 'clang-cl' and meson.backend() == 'ninja' and build_machine.system() == 'windows' |
||||||
|
error('MESON_SKIP_TEST CMake installation nor operational for vs2017 clangclx64ninja') |
||||||
|
endif |
||||||
|
|
||||||
|
cmake = import('cmake') |
||||||
|
|
||||||
|
cmake.write_basic_package_version_file(version: '0.0.1', |
||||||
|
name: 'cmakeModule', |
||||||
|
) |
||||||
|
|
||||||
|
conf = configuration_data() |
||||||
|
conf.set('MYVAR', 'my variable value') |
||||||
|
conf.set_quoted('MYQUOTEDVAR', 'my quoted variable value') |
||||||
|
|
||||||
|
cmake.configure_package_config_file( |
||||||
|
input: 'projectConfig.cmake.in', |
||||||
|
name: 'cmakeModule', |
||||||
|
configuration: conf, |
||||||
|
) |
@ -0,0 +1,4 @@ |
|||||||
|
@PACKAGE_INIT@ |
||||||
|
|
||||||
|
set(MYVAR "@MYVAR@") |
||||||
|
set(MYQUOTEDVAR @MYQUOTEDVAR@) |
Loading…
Reference in new issue