aboutsummaryrefslogtreecommitdiff
path: root/cmake/modules/FindDav1d.cmake
blob: 8bfd4153814cfbcafa22bb7770cbf2c4eeedb85d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#.rst:
# FindDav1d
# --------
# Finds the dav1d library
#
# This will define the following target:
#
#   dav1d::dav1d   - The dav1d library

if(NOT TARGET dav1d::dav1d)
  if(ENABLE_INTERNAL_DAV1D)
    include(cmake/scripts/common/ModuleHelpers.cmake)

    set(MODULE_LC dav1d)

    SETUP_BUILD_VARS()

    set(DAV1D_VERSION ${${MODULE}_VER})

    find_program(NINJA_EXECUTABLE ninja REQUIRED)
    find_program(MESON_EXECUTABLE meson REQUIRED)

    set(CONFIGURE_COMMAND ${MESON_EXECUTABLE}
                          --buildtype=release
                          --default-library=static
                          --prefix=${DEPENDS_PATH}
                          --libdir=lib
                          -Denable_asm=true
                          -Denable_tools=false
                          -Denable_examples=false
                          -Denable_tests=false
                          ../dav1d)
    set(BUILD_COMMAND ${NINJA_EXECUTABLE})
    set(INSTALL_COMMAND ${NINJA_EXECUTABLE} install)

    BUILD_DEP_TARGET()
  else()
    find_package(PkgConfig)
    # Do not use pkgconfig on windows
    if(PKG_CONFIG_FOUND AND NOT WIN32)
      pkg_check_modules(PC_DAV1D dav1d QUIET)
    endif()

    find_library(DAV1D_LIBRARY NAMES dav1d libdav1d
                               HINTS ${DEPENDS_PATH}/lib ${PC_DAV1D_LIBDIR}
                               ${${CORE_PLATFORM_LC}_SEARCH_CONFIG}
                               NO_CACHE)

    find_path(DAV1D_INCLUDE_DIR NAMES dav1d/dav1d.h
                                HINTS ${DEPENDS_PATH}/include ${PC_DAV1D_INCLUDEDIR}
                                ${${CORE_PLATFORM_LC}_SEARCH_CONFIG}
                                NO_CACHE)

    set(DAV1D_VERSION ${PC_DAV1D_VERSION})
  endif()

  include(FindPackageHandleStandardArgs)
  find_package_handle_standard_args(Dav1d
                                    REQUIRED_VARS DAV1D_LIBRARY DAV1D_INCLUDE_DIR
                                    VERSION_VAR DAV1D_VERSION)

  if(DAV1D_FOUND)
    add_library(dav1d::dav1d UNKNOWN IMPORTED)
    set_target_properties(dav1d::dav1d PROPERTIES
                                             IMPORTED_LOCATION "${DAV1D_LIBRARY}"
                                             INTERFACE_INCLUDE_DIRECTORIES "${DAV1D_INCLUDE_DIR}")
    set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP dav1d::dav1d)

    if(TARGET dav1d)
      add_dependencies(dav1d::dav1d dav1d)
    endif()
  endif()
endif()