summaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindMAD.cmake
blob: a54e498bad6ce52b68f2f311f613ad0a3d25ce74 (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
79
80
81
82
83
84
85
86
87
88
89
90
# This file is part of Mixxx, Digital DJ'ing software.
# Copyright (C) 2001-2023 Mixxx Development Team
# Distributed under the GNU General Public Licence (GPL) version 2 or any later
# later version. See the LICENSE file for details.

#[=======================================================================[.rst:
FindMAD
-------

Finds the MAD library.

Imported Targets
^^^^^^^^^^^^^^^^

This module provides the following imported targets, if found:

``MAD::MAD``
  The MAD library

Result Variables
^^^^^^^^^^^^^^^^

This will define the following variables:

``MAD_FOUND``
  True if the system has the MAD library.
``MAD_INCLUDE_DIRS``
  Include directories needed to use MAD.
``MAD_LIBRARIES``
  Libraries needed to link to MAD.
``MAD_DEFINITIONS``
  Compile definitions needed to use MAD.

Cache Variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``MAD_INCLUDE_DIR``
  The directory containing ``mad.h``.
``MAD_LIBRARY``
  The path to the MAD library.

#]=======================================================================]

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
  pkg_check_modules(PC_MAD QUIET mad)
endif()

find_path(MAD_INCLUDE_DIR
  NAMES mad.h
  PATHS ${PC_MAD_INCLUDE_DIRS}
  PATH_SUFFIXES mad
  DOC "MAD include directory")
mark_as_advanced(MAD_INCLUDE_DIR)

find_library(MAD_LIBRARY
  NAMES mad
  PATHS ${PC_MAD_LIBRARY_DIRS}
  DOC "MAD library"
)
mark_as_advanced(MAD_LIBRARY)

if(DEFINED PC_MAD_VERSION AND NOT PC_MAD_VERSION STREQUAL "")
  set(MAD_VERSION "${PC_MAD_VERSION}")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
  MAD
  REQUIRED_VARS MAD_LIBRARY MAD_INCLUDE_DIR
  VERSION_VAR MAD_VERSION
)

if(MAD_FOUND)
  set(MAD_LIBRARIES "${MAD_LIBRARY}")
  set(MAD_INCLUDE_DIRS "${MAD_INCLUDE_DIR}")
  set(MAD_DEFINITIONS ${PC_MAD_CFLAGS_OTHER})

  if(NOT TARGET MAD::MAD)
    add_library(MAD::MAD UNKNOWN IMPORTED)
    set_target_properties(MAD::MAD
      PROPERTIES
        IMPORTED_LOCATION "${MAD_LIBRARY}"
        INTERFACE_COMPILE_OPTIONS "${PC_MAD_CFLAGS_OTHER}"
        INTERFACE_INCLUDE_DIRECTORIES "${MAD_INCLUDE_DIR}"
    )
  endif()
endif()