|
| 1 | +# SPDX-License-Identifier: BSD-3-Clause |
| 2 | +# Copyright Contributors to the OpenColorIO Project. |
| 3 | +# |
| 4 | +# Locate DirectX-Headers (header-only, Windows only) |
| 5 | +# |
| 6 | +# Variables defined by this module: |
| 7 | +# DirectX-Headers_FOUND - Indicate whether the package was found or not |
| 8 | +# DirectX-Headers_INCLUDE_DIR - Location of the header files |
| 9 | +# DirectX-Headers_VERSION - Package version |
| 10 | +# |
| 11 | +# Global targets defined by this module: |
| 12 | +# Microsoft::DirectX-Headers |
| 13 | +# |
| 14 | +# DirectX-Headers can be supplied by the caller through any of the standard |
| 15 | +# CMake mechanisms: |
| 16 | +# -- Set -DDirectX-Headers_DIR to the directory containing directx-headers-config.cmake |
| 17 | +# -- Set -DDirectX-Headers_ROOT to the install prefix (with include/directx/ underneath) |
| 18 | +# -- Set -DDirectX-Headers_INCLUDE_DIR to the directory containing directx/d3d12.h |
| 19 | +# |
| 20 | +# When OCIO_INSTALL_EXT_PACKAGES is not ALL, this module first tries to locate |
| 21 | +# an existing install via the upstream CMake config, then falls back to a |
| 22 | +# manual header search. If still not found and OCIO_INSTALL_EXT_PACKAGES is |
| 23 | +# MISSING (the default), OCIO's ocio_install_dependency() pathway will invoke |
| 24 | +# InstallDirectX-Headers.cmake to build it via FetchContent. |
| 25 | +# |
| 26 | + |
| 27 | +if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) |
| 28 | + # Prefer the upstream CMake config (installed as lower-case). |
| 29 | + find_package(directx-headers ${DirectX-Headers_FIND_VERSION} CONFIG QUIET) |
| 30 | + |
| 31 | + if(directx-headers_FOUND) |
| 32 | + set(DirectX-Headers_FOUND TRUE) |
| 33 | + if(directx-headers_VERSION) |
| 34 | + set(DirectX-Headers_VERSION ${directx-headers_VERSION}) |
| 35 | + endif() |
| 36 | + else() |
| 37 | + # Fall back to locating the public header directly (e.g. when the |
| 38 | + # headers were installed without the CMake config, or are provided |
| 39 | + # by a vendored copy). |
| 40 | + find_path(DirectX-Headers_INCLUDE_DIR |
| 41 | + NAMES |
| 42 | + directx/d3d12.h |
| 43 | + HINTS |
| 44 | + ${DirectX-Headers_ROOT} |
| 45 | + PATH_SUFFIXES |
| 46 | + include |
| 47 | + ) |
| 48 | + endif() |
| 49 | + |
| 50 | + # If OCIO can install the package itself, demote REQUIRED so a missing |
| 51 | + # dependency here does not abort configuration before the install step. |
| 52 | + if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING) |
| 53 | + set(DirectX-Headers_FIND_REQUIRED FALSE) |
| 54 | + endif() |
| 55 | + |
| 56 | + include(FindPackageHandleStandardArgs) |
| 57 | + find_package_handle_standard_args(DirectX-Headers |
| 58 | + REQUIRED_VARS |
| 59 | + DirectX-Headers_INCLUDE_DIR |
| 60 | + VERSION_VAR |
| 61 | + DirectX-Headers_VERSION |
| 62 | + ) |
| 63 | +endif() |
| 64 | + |
| 65 | +############################################################################### |
| 66 | +### Create target (only needed for the manual-header-search fallback; the |
| 67 | +### upstream CMake config already defines Microsoft::DirectX-Headers). |
| 68 | + |
| 69 | +if(DirectX-Headers_FOUND AND NOT TARGET Microsoft::DirectX-Headers AND DirectX-Headers_INCLUDE_DIR) |
| 70 | + add_library(Microsoft::DirectX-Headers INTERFACE IMPORTED GLOBAL) |
| 71 | + set_target_properties(Microsoft::DirectX-Headers PROPERTIES |
| 72 | + INTERFACE_INCLUDE_DIRECTORIES "${DirectX-Headers_INCLUDE_DIR}" |
| 73 | + ) |
| 74 | + |
| 75 | + mark_as_advanced(DirectX-Headers_INCLUDE_DIR DirectX-Headers_VERSION) |
| 76 | +endif() |
0 commit comments