build(meson): generate CMake package config files

The cmake/config.cmake.in file uses the 'install(EXPORT)` CMake feature,
that is not (yet?) supported by Meson (see
https://github.com/mesonbuild/meson/issues/7632#issuecomment-704932266).

To work around this issue I created a simple CMake config file that
defines a single IMPORTED target.

It is really basic, but since xbyak is a header-only library defining a
single target works without issues.

This is useful because with this feature when building the library using
Meson, CMake users will be able to still use `find_package(xbyak)`, and
are not forced to use the FindPkgConfig module
This commit is contained in:
Andrea Pappacoda 2021-10-05 10:17:06 +02:00
parent e831805cc0
commit 345de8a541
No known key found for this signature in database
GPG key ID: A8A128A8AB1CEE49
2 changed files with 28 additions and 2 deletions

View file

@ -0,0 +1,8 @@
@PACKAGE_INIT@
if(NOT TARGET @TARGET_NAME@)
add_library(@TARGET_NAME@ INTERFACE IMPORTED)
set_target_properties(@TARGET_NAME@ PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_FILE}/include"
)
endif()

View file

@ -15,12 +15,30 @@ install_subdir('xbyak', install_dir: get_option('includedir'))
xbyak_dep = declare_dependency(include_directories: include_directories('.'))
if meson.version().version_compare('>=0.54.0')
meson.override_dependency('xbyak', xbyak_dep)
meson.override_dependency(meson.project_name(), xbyak_dep)
endif
import('pkgconfig').generate(
name: 'xbyak',
name: meson.project_name(),
description: 'JIT assembler for x86(IA32), x64(AMD64, x86-64)',
version: meson.project_version(),
url: 'https://github.com/herumi/xbyak'
)
if meson.version().version_compare('>=0.50.0')
cmake = import('cmake')
cmake.write_basic_package_version_file(
name: meson.project_name(),
version: meson.project_version()
)
cmake_conf = configuration_data()
cmake_conf.set('TARGET_NAME', meson.project_name() + '::' + meson.project_name())
cmake.configure_package_config_file(
name: meson.project_name(),
input: 'cmake'/'meson-config.cmake.in',
configuration: cmake_conf
)
endif