• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# - Find FLAC
2# Find the native FLAC includes and libraries
3#
4#  FLAC_INCLUDE_DIRS - where to find FLAC headers.
5#  FLAC_LIBRARIES    - List of libraries when using libFLAC.
6#  FLAC_FOUND        - True if libFLAC found.
7#  FLAC_DEFINITIONS  - FLAC compile definitons
8
9if (FLAC_INCLUDE_DIR)
10    # Already in cache, be silent
11    set (FLAC_FIND_QUIETLY TRUE)
12endif ()
13
14find_package (Ogg QUIET)
15
16find_package (PkgConfig QUIET)
17pkg_check_modules(PC_FLAC QUIET flac)
18
19set(FLAC_VERSION ${PC_FLAC_VERSION})
20
21find_path (FLAC_INCLUDE_DIR FLAC/stream_decoder.h
22	HINTS
23		${PC_FLAC_INCLUDEDIR}
24		${PC_FLAC_INCLUDE_DIRS}
25		${FLAC_ROOT}
26	)
27
28# MSVC built libraries can name them *_static, which is good as it
29# distinguishes import libraries from static libraries with the same extension.
30find_library (FLAC_LIBRARY
31	NAMES
32		FLAC
33		libFLAC
34		libFLAC_dynamic
35		libFLAC_static
36	HINTS
37		${PC_FLAC_LIBDIR}
38		${PC_FLAC_LIBRARY_DIRS}
39		${FLAC_ROOT}
40	)
41
42# Handle the QUIETLY and REQUIRED arguments and set FLAC_FOUND to TRUE if
43# all listed variables are TRUE.
44include (FindPackageHandleStandardArgs)
45find_package_handle_standard_args (FLAC
46	REQUIRED_VARS
47		FLAC_LIBRARY
48		FLAC_INCLUDE_DIR
49		Ogg_FOUND
50	VERSION_VAR
51        FLAC_VERSION
52	)
53
54if (FLAC_FOUND)
55	set (FLAC_INCLUDE_DIRS ${FLAC_INCLUDE_DIR})
56	set (FLAC_LIBRARIES ${FLAC_LIBRARY} ${OGG_LIBRARIES})
57    if (NOT TARGET FLAC::FLAC)
58		add_library(FLAC::FLAC UNKNOWN IMPORTED)
59		set_target_properties(FLAC::FLAC PROPERTIES
60			INTERFACE_INCLUDE_DIRECTORIES "${FLAC_INCLUDE_DIR}"
61			IMPORTED_LOCATION "${FLAC_LIBRARY}"
62			INTERFACE_LINK_LIBRARIES Ogg::ogg
63			)
64	endif ()
65endif ()
66
67mark_as_advanced(FLAC_INCLUDE_DIR FLAC_LIBRARY)
68