summaryrefslogtreecommitdiffstats
path: root/cmake/FindSndFile.cmake
blob: 05ef05103e4aac725d71d1cf39d841e451a07516 (plain) (blame)
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
# Found on http://hg.kvats.net
#
# - Try to find libsndfile
# 
# Once done this will define
#
#  SNDFILE_FOUND        - system has libsndfile
#  SNDFILE_INCLUDE_DIRS - the libsndfile include directory
#  SNDFILE_LIBRARIES    - Link these to use libsndfile
#  SNDFILE_CFLAGS       - Compile options to use libsndfile
#  SndFile::SNdFile     - Imported library of libsndfile
#
#  Copyright (C) 2006  Wengo
#
#  Redistribution and use is allowed according to the terms of the New
#  BSD license.
#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
    pkg_search_module(PKG_SNDFILE "sndfile")
endif()

find_path(SNDFILE_INCLUDE_DIR
    NAMES
        sndfile.h
    HINTS
        ${PKG_SNDFILE_INCLUDE_DIRS}
    PATHS
        /usr/include
        /usr/local/include
        /opt/local/include
        /sw/include
    )

find_library(SNDFILE_LIBRARY
    NAMES
        sndfile
    HINTS
        ${PKG_SNDFILE_LIBRARIES}
    PATHS
        /usr/lib
        /usr/local/lib
        /opt/local/lib
        /sw/lib
)

set(SNDFILE_CFLAGS "${PKG_SNDFILE_CFLAGS_OTHER}" CACHE STRING "CFLAGS of libsndfile")

set(SNDFILE_INCLUDE_DIRS ${SNDFILE_INCLUDE_DIR})
set(SNDFILE_LIBRARIES ${SNDFILE_LIBRARY})

if (SNDFILE_INCLUDE_DIRS AND SNDFILE_LIBRARIES)
set(SNDFILE_FOUND TRUE)
endif (SNDFILE_INCLUDE_DIRS AND SNDFILE_LIBRARIES)


# handle the QUIETLY and REQUIRED arguments and set SNdFile_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SndFile DEFAULT_MSG SNDFILE_INCLUDE_DIRS SNDFILE_LIBRARIES)

if(NOT TARGET SndFile::SndFile)
    add_library(__SndFile INTERFACE)
    target_compile_options(__SndFile INTERFACE ${SNDFILE_CFLAGS})
    target_include_directories(__SndFile INTERFACE ${SNDFILE_INCLUDE_DIRS})
    target_link_libraries(__SndFile INTERFACE ${SNDFILE_LIBRARIES})
    add_library(SndFile::SndFile ALIAS __SndFile)
endif()