katetemplate: Template=FindXXX.cmake Group=Other Highlight=CMake
katetemplate: Author=Alex Turbov <i.zaufi@gmail.com>
katetemplate: Description=CMake finder skeleton wrapper based on pkg-config
# - Find ${package_description} using `pkg-config`
# Search for %{package_description} and set the following variables:
#  %{package}_FOUND        - is package found
#  %{package}_VERSION      - found package version
#  %{package}_INCLUDE_DIRS - dir w/ header files
#  %{package}_DEFINITIONS  - other than `-I' compiler flags
#  %{package}_LIBRARIES    - libs for dynamic linkage
#%{cursor}

#
# Copyright (C) %{year}, %{fullname} <%{email}>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file LICENSE for details.
#

# Check if already in cache
# NOTE Feel free to check/change/add any other vars
if(NOT %{package}_LIBRARIES)

    if(%{package}_FIND_QUIETLY)
        set(_pkg_find_quietly QUIET)
    endif()

    set(_pkg_module_name "${pkg_config_module_name}")
    if(${package}_FIND_VERSION)
        if(%{package}_FIND_VERSION_EXACT)
            set(_pkg_module_name "\${_pkg_module_name}=\${%{package}_FIND_VERSION}")
        else()
            set(_pkg_module_name "\${_pkg_module_name}>=\${%{package}_FIND_VERSION}")
        endif()
    endif()

    find_package(PkgConfig \${_pkg_find_quietly})
    pkg_check_modules(%{package} \${_pkg_module_name} \${_pkg_find_quietly})

    include(FindPackageHandleStandardArgs)
    find_package_handle_standard_args(
        %{package_finder_name}
        FOUND_VAR %{package}_FOUND
        REQUIRED_VARS %{package}_LIBRARIES
        VERSION_VAR %{package}_VERSION
      )

    if(%{package}_FOUND)
        # Copy other than `-I' flags to `XXX_DEFINITIONS' variable,
        # according CMake guide (/usr/share/cmake/Modules/readme.txt)
        set(%{package}_DEFINITIONS \${%{package}_CFLAGS_OTHER})
        # Unset non-standard variable
        unset(%{package}_CFLAGS_OTHER)
    endif()
endif()

