[cosmetic] separate c-lang format commit
[xbmc.git] / cmake / modules / FindVAAPI.cmake
blob68d08bddfb27b13a8873d6e71a5d44d55e607bdd
1 #.rst:
2 # FindVAAPI
3 # ---------
4 # Finds the VAAPI library
6 # This will define the following target:
8 #   ${APP_NAME_LC}::VAAPI   - The VAAPI library
10 if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
11   find_package(PkgConfig)
13   if(PKG_CONFIG_FOUND)
14     pkg_check_modules(PC_VAAPI libva libva-drm libva-wayland libva-x11 QUIET)
15   endif()
17   set(REQUIRED_VARS "VAAPI_libva_LIBRARY" "VAAPI_libva-drm_LIBRARY" "VAAPI_libva_INCLUDE_DIR" "VAAPI_libva-drm_INCLUDE_DIR")
19   find_path(VAAPI_libva_INCLUDE_DIR va/va.h
20                               HINTS ${PC_VAAPI_libva_INCLUDEDIR})
21   find_library(VAAPI_libva_LIBRARY NAMES va
22                                    HINTS ${PC_VAAPI_libva_LIBDIR})
23   find_path(VAAPI_libva-drm_INCLUDE_DIR va/va_drm.h
24                                   HINTS ${PC_VAAPI_libva-drm_INCLUDEDIR})
25   find_library(VAAPI_libva-drm_LIBRARY NAMES va-drm
26                                        HINTS ${PC_VAAPI_libva-drm_LIBDIR})
27   if("wayland" IN_LIST CORE_PLATFORM_NAME_LC)
28     find_path(VAAPI_libva-wayland_INCLUDE_DIR va/va_wayland.h
29                                         HINTS ${PC_VAAPI_libva-wayland_INCLUDEDIR})
30     find_library(VAAPI_libva-wayland_LIBRARY NAMES va-wayland
31                                              HINTS ${PC_VAAPI_libva-wayland_LIBDIR})
32     list(APPEND REQUIRED_VARS "VAAPI_libva-wayland_INCLUDE_DIR" "VAAPI_libva-wayland_LIBRARY")
33   endif()
34   if("x11" IN_LIST CORE_PLATFORM_NAME_LC)
35     find_path(VAAPI_libva-x11_INCLUDE_DIR va/va_x11.h
36                                     HINTS ${PC_VAAPI_libva-x11_INCLUDEDIR})
37     find_library(VAAPI_libva-x11_LIBRARY NAMES va-x11
38                                          HINTS ${PC_VAAPI_libva-x11_LIBDIR})
39     list(APPEND REQUIRED_VARS "VAAPI_libva-x11_INCLUDE_DIR" "VAAPI_libva-x11_LIBRARY")
40   endif()
42   if(PC_VAAPI_libva_VERSION)
43     set(VAAPI_VERSION_STRING ${PC_VAAPI_libva_VERSION})
44   elseif(VAAPI_INCLUDE_DIR AND EXISTS "${VAAPI_INCLUDE_DIR}/va/va_version.h")
45     file(STRINGS "${VAAPI_INCLUDE_DIR}/va/va_version.h" vaapi_version_str REGEX "^#define[\t ]+VA_VERSION_S[\t ]+\".*\".*")
46     string(REGEX REPLACE "^#define[\t ]+VA_VERSION_S[\t ]+\"([^\"]+)\".*" "\\1" VAAPI_VERSION_STRING "${vaapi_version_str}")
47     unset(vaapi_version_str)
48   endif()
50   if(NOT VAAPI_FIND_VERSION)
51     set(VAAPI_FIND_VERSION 0.39.0)
52   endif()
54   include(FindPackageHandleStandardArgs)
55   find_package_handle_standard_args(VAAPI
56                                     REQUIRED_VARS ${REQUIRED_VARS}
57                                     VERSION_VAR VAAPI_VERSION_STRING)
59   if(VAAPI_FOUND)
60     if(VAAPI_libva-x11_LIBRARY)
61       add_library(${APP_NAME_LC}::va-x11 UNKNOWN IMPORTED)
62       set_target_properties(${APP_NAME_LC}::va-x11 PROPERTIES
63                                                    IMPORTED_LOCATION "${VAAPI_libva-x11_LIBRARY}"
64                                                    INTERFACE_INCLUDE_DIRECTORIES "${VAAPI_libva-x11_INCLUDE_DIR}")
65     endif()
67     if(VAAPI_libva-wayland_LIBRARY)
68       add_library(${APP_NAME_LC}::va-wayland UNKNOWN IMPORTED)
69       set_target_properties(${APP_NAME_LC}::va-wayland PROPERTIES
70                                                        IMPORTED_LOCATION "${VAAPI_libva-wayland_LIBRARY}"
71                                                        INTERFACE_INCLUDE_DIRECTORIES "${VAAPI_libva-wayland_INCLUDE_DIR}")
72     endif()
74     add_library(${APP_NAME_LC}::va-drm UNKNOWN IMPORTED)
75     set_target_properties(${APP_NAME_LC}::va-drm PROPERTIES
76                                                      IMPORTED_LOCATION "${VAAPI_libva-drm_LIBRARY}"
77                                                      INTERFACE_INCLUDE_DIRECTORIES "${VAAPI_libva-drm_INCLUDE_DIR}")
79     add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
80     set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
81                                                                      IMPORTED_LOCATION "${VAAPI_libva_LIBRARY}"
82                                                                      INTERFACE_INCLUDE_DIRECTORIES "${VAAPI_libva_INCLUDE_DIR}"
83                                                                      INTERFACE_LINK_LIBRARIES "${APP_NAME_LC}::va-drm;$<TARGET_NAME_IF_EXISTS:${APP_NAME_LC}::va-wayland>;$<TARGET_NAME_IF_EXISTS:${APP_NAME_LC}::va-x11>"
84                                                                      INTERFACE_COMPILE_DEFINITIONS "HAVE_LIBVA")
85   endif()
86 endif()