summaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindFLAC.cmake
blob: 463861ee074fbcc563f5c83622ca18d49c0742c5 (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
# 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:
FindFLAC
--------

Finds the FLAC library.

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

This module provides the following imported targets, if found:

``FLAC::FLAC``
  The FLAC library

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

This will define the following variables:

``FLAC_FOUND``
  True if the system has the FLAC library.
``FLAC_INCLUDE_DIRS``
  Include directories needed to use FLAC.
``FLAC_LIBRARIES``
  Libraries needed to link to FLAC.
``FLAC_DEFINITIONS``
  Compile definitions needed to use FLAC.

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

The following cache variables may also be set:

``FLAC_INCLUDE_DIR``
  The directory containing ``FLAC/all.h``.
``FLAC_LIBRARY``
  The path to the FLAC library.

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

include(IsStaticLibrary)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
  pkg_check_modules(PC_FLAC QUIET flac)
endif()

find_path(FLAC_INCLUDE_DIR
  NAMES FLAC/all.h
  PATHS ${PC_FLAC_INCLUDE_DIRS}
  DOC "FLAC include directory")
mark_as_advanced(FLAC_INCLUDE_DIR)

find_library(FLAC_LIBRARY
  NAMES FLAC
  PATHS ${PC_FLAC_LIBRARY_DIRS}
  DOC "FLAC library"
)
mark_as_advanced(FLAC_LIBRARY)

if(DEFINED PC_FLAC_VERSION AND NOT PC_FLAC_VERSION STREQUAL "")
  set(FLAC_VERSION "${PC_FLAC_VERSION}")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
  FLAC
  REQUIRED_VARS FLAC_LIBRARY FLAC_INCLUDE_DIR
  VERSION_VAR FLAC_VERSION
)

if(FLAC_FOUND)
  set(FLAC_LIBRARIES "${FLAC_LIBRARY}")
  set(FLAC_INCLUDE_DIRS "${FLAC_INCLUDE_DIR}")
  set(FLAC_DEFINITIONS ${PC_FLAC_CFLAGS_OTHER})

  if(NOT TARGET FLAC::FLAC)
    add_library(FLAC::FLAC UNKNOWN IMPORTED)
    set_target_properties(FLAC::FLAC
      PROPERTIES
        IMPORTED_LOCATION "${FLAC_LIBRARY}"
        INTERFACE_COMPILE_OPTIONS "${PC_FLAC_CFLAGS_OTHER}"
        INTERFACE_INCLUDE_DIRECTORIES "${FLAC_INCLUDE_DIR}"
    )
    is_static_library(FLAC_IS_STATIC FLAC::FLAC)
    if(FLAC_IS_STATIC)
      if(WIN32)
        set_property(TARGET FLAC::FLAC APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS
          FLAC__NO_DLL
        )
      endif()
    endif()
  endif()
endif()