aboutsummaryrefslogtreecommitdiff
path: root/cmake/modules/FindBluray.cmake
blob: 1c4f12c89d8ce3e7125578dbcff5e636ddebf8fb (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
74
75
76
77
78
#.rst:
# FindBluray
# ----------
# Finds the libbluray library
#
# This will define the following target:
#
#   Bluray::Bluray   - The libbluray library

if(NOT TARGET Bluray::Bluray)

  find_package(PkgConfig)

  # We only rely on pkgconfig for non windows platforms
  if(PKG_CONFIG_FOUND AND NOT (WIN32 OR WINDOWS_STORE))
    if(Bluray_FIND_VERSION_EXACT)
      set(Bluray_FIND_SPEC "=${Bluray_FIND_VERSION_COMPLETE}")
    else()
      set(Bluray_FIND_SPEC ">=${Bluray_FIND_VERSION_COMPLETE}")
    endif()
    pkg_check_modules(BLURAY libbluray${Bluray_FIND_SPEC} QUIET)

    # First item is the full path of the library file found
    # pkg_check_modules does not populate a variable of the found library explicitly
    list(GET BLURAY_LINK_LIBRARIES 0 BLURAY_LIBRARY)
  else()
    # todo: for windows use find_package CONFIG call potentially

    find_path(BLURAY_INCLUDEDIR NAMES libbluray/bluray.h
                                HINTS ${DEPENDS_PATH}/include
                                ${${CORE_PLATFORM_LC}_SEARCH_CONFIG}
                                NO_CACHE)

    find_library(BLURAY_LIBRARY NAMES bluray libbluray
                                HINTS ${DEPENDS_PATH}/lib
                                ${${CORE_PLATFORM_LC}_SEARCH_CONFIG}
                                NO_CACHE)
  endif()

  if(NOT BLURAY_VERSION AND EXISTS ${BLURAY_INCLUDEDIR}/libbluray/bluray-version.h)
    file(STRINGS ${BLURAY_INCLUDEDIR}/libbluray/bluray-version.h _bluray_version_str
         REGEX "#define[ \t]BLURAY_VERSION_STRING[ \t][\"]?[0-9.]+[\"]?")
    string(REGEX REPLACE "^.*BLURAY_VERSION_STRING[ \t][\"]?([0-9.]+).*$" "\\1" BLURAY_VERSION ${_bluray_version_str})
    unset(_bluray_version_str)
  endif()

  include(FindPackageHandleStandardArgs)
  find_package_handle_standard_args(Bluray
                                    REQUIRED_VARS BLURAY_LIBRARY BLURAY_INCLUDEDIR BLURAY_VERSION
                                    VERSION_VAR BLURAY_VERSION)

  if(BLURAY_FOUND)
    add_library(Bluray::Bluray UNKNOWN IMPORTED)
    set_target_properties(Bluray::Bluray PROPERTIES
                                         IMPORTED_LOCATION "${BLURAY_LIBRARY}"
                                         INTERFACE_COMPILE_DEFINITIONS "HAVE_LIBBLURAY=1"
                                         INTERFACE_INCLUDE_DIRECTORIES "${BLURAY_INCLUDEDIR}")

    # Add link libraries for static lib usage
    if(${BLURAY_LIBRARY} MATCHES ".+\.a$" AND BLURAY_LINK_LIBRARIES)
      # Remove duplicates
      list(REMOVE_DUPLICATES BLURAY_LINK_LIBRARIES)

      # Remove own library - eg libbluray.a
      list(FILTER BLURAY_LINK_LIBRARIES EXCLUDE REGEX ".*bluray.*\.a$")

      set_target_properties(Bluray::Bluray PROPERTIES
                                           INTERFACE_LINK_LIBRARIES "${BLURAY_LINK_LIBRARIES}")
    endif()

    if(NOT CORE_PLATFORM_NAME_LC STREQUAL windowsstore)
      set_target_properties(Bluray::Bluray PROPERTIES
                                           INTERFACE_COMPILE_DEFINITIONS "HAVE_LIBBLURAY_BDJ=1")
    endif()

    set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP Bluray::Bluray)
  endif()
endif()