| 1 |
# Distributed under the original FontForge BSD 3-clause license |
| 2 |
|
| 3 |
#[=======================================================================[.rst: |
| 4 |
PackageUtils |
| 5 |
------------ |
| 6 |
|
| 7 |
``find_package_with_target` calls ``find_package`` with the provided |
| 8 |
arguments. If searching for package ``PACKAGE``, then if ``PACKAGE`` |
| 9 |
is found but the imported target ``PACKAGE::PACKAGE`` does not exist, |
| 10 |
a basic imported target of that name is created, on the assumption |
| 11 |
that ``PACKAGE_INCLUDE_DIRS`` and ``PACKAGE_LIBRARIES`` are correctly |
| 12 |
set. This is for use with find targets that do not natively provide |
| 13 |
an imported target. |
| 14 |
|
| 15 |
``find_package_auto`` calls ``find_package`` with the provided |
| 16 |
arguments, iff ``auto_option`` evaluates to a truthy value or ``AUTO``. |
| 17 |
If ``auto_option`` is truthy (but not ``AUTO``), ``REQUIRED`` is |
| 18 |
passed into ``find_package``. ``auto_option_RESULT`` is set to |
| 19 |
the ``find_package`` result. |
| 20 |
|
| 21 |
#]=======================================================================] |
| 22 |
|
| 23 |
macro(find_package_with_target) |
| 24 |
find_package(${ARGV}) |
| 25 |
if(${ARGV0}_FOUND AND NOT TARGET ${ARGV0}::${ARGV0}) |
| 26 |
add_library(${ARGV0}::${ARGV0} INTERFACE IMPORTED) |
| 27 |
set_property(TARGET ${ARGV0}::${ARGV0} PROPERTY |
| 28 |
INTERFACE_INCLUDE_DIRECTORIES "${${ARGV0}_INCLUDE_DIRS}") |
| 29 |
set_property(TARGET ${ARGV0}::${ARGV0} PROPERTY |
| 30 |
INTERFACE_LINK_LIBRARIES "${${ARGV0}_LIBRARIES}") |
| 31 |
endif() |
| 32 |
endmacro() |
| 33 |
|
| 34 |
macro(find_package_auto auto_option) |
| 35 |
if(${auto_option}) |
| 36 |
unset(_find_package_auto_required) |
| 37 |
if(NOT ${${auto_option}} STREQUAL "AUTO") |
| 38 |
set(_find_package_auto_required REQUIRED) |
| 39 |
endif() |
| 40 |
|
| 41 |
find_package(${ARGN} ${_find_package_auto_required}) |
| 42 |
set(${auto_option}_RESULT ${${ARGV1}_FOUND}) |
| 43 |
endif() |
| 44 |
endmacro() |
| 45 |
|
| 46 |
# pkg_check_auto - pkg-config based alternative to find_package_auto |
| 47 |
# |
| 48 |
# Usage: pkg_check_auto(ENABLE_OPTION TargetName pkg-config-name) |
| 49 |
# |
| 50 |
# If ENABLE_OPTION is truthy, calls pkg_check_modules to find the package. |
| 51 |
# Creates an aliased target TargetName::TargetName from PkgConfig::TargetName. |
| 52 |
# Sets ENABLE_OPTION_RESULT to the result. |
| 53 |
# |
| 54 |
macro(pkg_check_auto auto_option target_name pkg_name) |
| 55 |
if(${auto_option}) |
| 56 |
unset(_pkg_check_auto_required) |
| 57 |
if(NOT ${${auto_option}} STREQUAL "AUTO") |
| 58 |
set(_pkg_check_auto_required REQUIRED) |
| 59 |
endif() |
| 60 |
|
| 61 |
pkg_check_modules(${target_name} ${_pkg_check_auto_required} IMPORTED_TARGET ${pkg_name}) |
| 62 |
set(${auto_option}_RESULT ${${target_name}_FOUND}) |
| 63 |
|
| 64 |
if(${target_name}_FOUND AND NOT TARGET ${target_name}::${target_name}) |
| 65 |
include(${PROJECT_SOURCE_DIR}/cmake/TargetUtils.cmake) |
| 66 |
alias_imported_target(${target_name}::${target_name} PkgConfig::${target_name}) |
| 67 |
endif() |
| 68 |
endif() |
| 69 |
endmacro() |