summaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindChromaprint.cmake
blob: b4cff3c3b66e6dbda6d0c1f98261b8a506d5ea33 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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:
FindChromaprint
---------------

Finds the Chromaprint library.

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

This module provides the following imported targets, if found:

``Chromaprint::Chromaprint``
  The Chromaprint library

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

This will define the following variables:

``Chromaprint_FOUND``
  True if the system has the Chromaprint library.
``Chromaprint_INCLUDE_DIRS``
  Include directories needed to use Chromaprint.
``Chromaprint_LIBRARIES``
  Libraries needed to link to Chromaprint.
``Chromaprint_DEFINITIONS``
  Compile definitions needed to use Chromaprint.

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

The following cache variables may also be set:

``Chromaprint_INCLUDE_DIR``
  The directory containing ``chromaprint.h``.
``Chromaprint_LIBRARY``
  The path to the Chromaprint library.

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

include(IsStaticLibrary)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
  pkg_check_modules(PC_Chromaprint QUIET libchromaprint)
endif()

find_path(Chromaprint_INCLUDE_DIR
  NAMES chromaprint.h
  PATHS ${PC_Chromaprint_INCLUDE_DIRS}
  PATH_SUFFIXES chromaprint
  DOC "Chromaprint include directory")
mark_as_advanced(Chromaprint_INCLUDE_DIR)

find_library(Chromaprint_LIBRARY
  NAMES chromaprint chromaprint_p
  PATHS ${PC_Chromaprint_LIBRARY_DIRS}
  DOC "Chromaprint library"
)
mark_as_advanced(Chromaprint_LIBRARY)

if(DEFINED PC_Chromaprint_VERSION AND NOT PC_Chromaprint_VERSION STREQUAL "")
  set(Chromaprint_VERSION "${PC_Chromaprint_VERSION}")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
  Chromaprint
  REQUIRED_VARS Chromaprint_LIBRARY Chromaprint_INCLUDE_DIR
  VERSION_VAR Chromaprint_VERSION
)

if(Chromaprint_FOUND)
  set(Chromaprint_LIBRARIES "${Chromaprint_LIBRARY}")
  set(Chromaprint_INCLUDE_DIRS "${Chromaprint_INCLUDE_DIR}")
  set(Chromaprint_DEFINITIONS ${PC_Chromaprint_CFLAGS_OTHER})

  if(NOT TARGET Chromaprint::Chromaprint)
    add_library(Chromaprint::Chromaprint UNKNOWN IMPORTED)
    set_target_properties(Chromaprint::Chromaprint
      PROPERTIES
        IMPORTED_LOCATION "${Chromaprint_LIBRARY}"
        INTERFACE_COMPILE_OPTIONS "${PC_Chromaprint_CFLAGS_OTHER}"
        INTERFACE_INCLUDE_DIRECTORIES "${Chromaprint_INCLUDE_DIR}"
    )
    is_static_library(Chromaprint_IS_STATIC Chromaprint::Chromaprint)
    if(Chromaprint_IS_STATIC)
      if(WIN32)
        # used in chomaprint.h to set dllexport for Windows
        set_property(TARGET Chromaprint::Chromaprint APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS
          CHROMAPRINT_NODLL
        )
      endif()
      find_package(FFTW REQUIRED)
      set_property(TARGET Chromaprint::Chromaprint APPEND PROPERTY INTERFACE_LINK_LIBRARIES
        FFTW::FFTW
      )
    endif()
  endif()
endif()