|
| 1 | +#[=======================================================================[.rst |
| 2 | +FindWIL |
| 3 | +------- |
| 4 | +
|
| 5 | +FindModule for WIL and associated headers |
| 6 | +
|
| 7 | +Imported Targets |
| 8 | +^^^^^^^^^^^^^^^^ |
| 9 | +
|
| 10 | +.. versionadded:: 3.0 |
| 11 | +
|
| 12 | +This module defines the :prop_tgt:`IMPORTED` target ``WIL::WIL``. |
| 13 | +
|
| 14 | +Result Variables |
| 15 | +^^^^^^^^^^^^^^^^ |
| 16 | +
|
| 17 | +This module sets the following variables: |
| 18 | +
|
| 19 | +``WIL_FOUND`` |
| 20 | + True, if headers were found. |
| 21 | +``WIL_VERSION`` |
| 22 | + Detected version of found WIL headers. |
| 23 | +
|
| 24 | +Cache variables |
| 25 | +^^^^^^^^^^^^^^^ |
| 26 | +
|
| 27 | +The following cache variables may also be set: |
| 28 | +
|
| 29 | +``WIL_INCLUDE_DIR`` |
| 30 | + Directory containing ``cppwinrt.h``. |
| 31 | +
|
| 32 | +#]=======================================================================] |
| 33 | + |
| 34 | +# cmake-format: off |
| 35 | +# cmake-lint: disable=C0103 |
| 36 | +# cmake-lint: disable=C0301 |
| 37 | +# cmake-format: on |
| 38 | + |
| 39 | +find_package(PkgConfig QUIET) |
| 40 | +if(PKG_CONFIG_FOUND) |
| 41 | + pkg_search_module(_WIL QUIET wil) |
| 42 | +endif() |
| 43 | + |
| 44 | +find_path( |
| 45 | + WIL_INCLUDE_DIR |
| 46 | + NAMES wil/cppwinrt.h |
| 47 | + HINTS ${_WI_INCLUDE_DIRS} ${_WIL_INCLUDE_DIRS} |
| 48 | + PATHS /usr/include /usr/local/include /opt/local/include /sw/include |
| 49 | + DOC "WIL include directory") |
| 50 | + |
| 51 | +include(FindPackageHandleStandardArgs) |
| 52 | +find_package_handle_standard_args( |
| 53 | + WIL |
| 54 | + REQUIRED_VARS WIL_INCLUDE_DIR |
| 55 | + VERSION_VAR WIL_VERSION REASON_FAILURE_MESSAGE "${WIL_ERROR_REASON}") |
| 56 | +mark_as_advanced(WIL_INCLUDE_DIR) |
| 57 | +unset(WIL_ERROR_REASON) |
| 58 | + |
| 59 | +if(EXISTS "${WIL_INCLUDE_DIR}/wil/cppwinrt.h") |
| 60 | + file(STRINGS "${WIL_INCLUDE_DIR}/wil/cppwinrt.h" _version_string REGEX "^.*VERSION_(MAJOR|MINOR)[ \t]+[0-9]+[ \t]*$") |
| 61 | + |
| 62 | + string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}") |
| 63 | + string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}") |
| 64 | + |
| 65 | + set(WIL_VERSION "${_version_major}.${_version_minor}") |
| 66 | + unset(_version_major) |
| 67 | + unset(_version_minor) |
| 68 | +else() |
| 69 | + if(NOT WIL_FIND_QUIETLY) |
| 70 | + message(AUTHOR_WARNING "Failed to find WIL version.") |
| 71 | + endif() |
| 72 | + set(WIL_VERSION 0.0.0) |
| 73 | +endif() |
| 74 | + |
| 75 | +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") |
| 76 | + set(WIL_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.") |
| 77 | +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") |
| 78 | + set(WIL_ERROR_REASON "Ensure WIL headers are available in local library paths.") |
| 79 | +endif() |
| 80 | + |
| 81 | +if(WIL_FOUND) |
| 82 | + set(WIL_INCLUDE_DIRS ${WIL_INCLUDE_DIR}) |
| 83 | + |
| 84 | + if(NOT TARGET WIL::WIL) |
| 85 | + add_library(WIL::WIL INTERFACE IMPORTED) |
| 86 | + set_target_properties(WIL::WIL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${WIL_INCLUDE_DIRS}") |
| 87 | + |
| 88 | + endif() |
| 89 | +endif() |
| 90 | + |
| 91 | +include(FeatureSummary) |
| 92 | +set_package_properties( |
| 93 | + WIL PROPERTIES |
| 94 | + URL "https://github.com/microsoft/wil.git" |
| 95 | + DESCRIPTION |
| 96 | + "The Windows Implementation Libraries (WIL) is a header-only C++ library created to make life easier for developers on Windows through readable type-safe C++ interfaces for common Windows coding patterns." |
| 97 | +) |
0 commit comments