Debian Codegraph @

cmake/FindOggVorbis.cmake

raw
1 # - Try to find the OggVorbis libraries
2 # Once done this will define
3 #
4 # OGGVORBIS_FOUND - system has OggVorbis
5 # OGGVORBIS_VERSION - set either to 1 or 2
6 # OGGVORBIS_INCLUDE_DIR - the OggVorbis include directory
7 # OGGVORBIS_LIBRARIES - The libraries needed to use OggVorbis
8 # OGG_LIBRARY - The Ogg library
9 # VORBIS_LIBRARY - The Vorbis library
10 # VORBISFILE_LIBRARY - The VorbisFile library
11 # VORBISENC_LIBRARY - The VorbisEnc library
12
13 # Copyright (c) 2006, Richard Laerkaeng, <[email protected]>
14 #
15 # Redistribution and use is allowed according to the terms of the BSD license.
16 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
17
18
19 include (CheckLibraryExists)
20
21 find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h)
22 find_path(OGG_INCLUDE_DIR ogg/ogg.h)
23
24 find_library(OGG_LIBRARY NAMES ogg)
25 find_library(VORBIS_LIBRARY NAMES vorbis)
26 find_library(VORBISFILE_LIBRARY NAMES vorbisfile)
27 find_library(VORBISENC_LIBRARY NAMES vorbisenc)
28
29 mark_as_advanced(
30 VORBIS_INCLUDE_DIR
31 OGG_INCLUDE_DIR
32 OGG_LIBRARY
33 VORBIS_LIBRARY
34 VORBISFILE_LIBRARY
35 VORBISENC_LIBRARY
36 )
37
38 if (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY AND VORBISENC_LIBRARY)
39 set(OGGVORBIS_FOUND TRUE)
40
41 set(OGGVORBIS_LIBRARIES ${OGG_LIBRARY} ${VORBIS_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBISENC_LIBRARY})
42
43 set(_CMAKE_REQUIRED_LIBRARIES_TMP ${CMAKE_REQUIRED_LIBRARIES})
44 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${OGGVORBIS_LIBRARIES})
45 check_library_exists(vorbis vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)
46 set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_TMP})
47
48 if (HAVE_LIBVORBISENC2)
49 set (OGGVORBIS_VERSION 2)
50 else ()
51 set (OGGVORBIS_VERSION 1)
52 endif ()
53
54 else ()
55 set (OGGVORBIS_VERSION)
56 set(OGGVORBIS_FOUND FALSE)
57 endif ()
58
59
60 if (OGGVORBIS_FOUND)
61 if (NOT OggVorbis_FIND_QUIETLY)
62 message(STATUS "Found OggVorbis: ${OGGVORBIS_LIBRARIES}")
63 endif ()
64 else ()
65 if (OggVorbis_FIND_REQUIRED)
66 message(FATAL_ERROR "Could NOT find OggVorbis libraries")
67 endif (OggVorbis_FIND_REQUIRED)
68 if (NOT OggVorbis_FIND_QUITELY)
69 message(STATUS "Could NOT find OggVorbis libraries")
70 endif ()
71 endif ()
72
73 #check_include_files(vorbis/vorbisfile.h HAVE_VORBISFILE_H)
74 #check_library_exists(ogg ogg_page_version "" HAVE_LIBOGG)
75 #check_library_exists(vorbis vorbis_info_init "" HAVE_LIBVORBIS)
76 #check_library_exists(vorbisfile ov_open "" HAVE_LIBVORBISFILE)
77 #check_library_exists(vorbisenc vorbis_info_clear "" HAVE_LIBVORBISENC)
78 #check_library_exists(vorbis vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)
79
80 #if (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
81 # message(STATUS "Ogg/Vorbis found")
82 # set (VORBIS_LIBS "-lvorbis -logg")
83 # set (VORBISFILE_LIBS "-lvorbisfile")
84 # set (VORBISENC_LIBS "-lvorbisenc")
85 # set (OGGVORBIS_FOUND TRUE)
86 # if (HAVE_LIBVORBISENC2)
87 # set (HAVE_VORBIS 2)
88 # else (HAVE_LIBVORBISENC2)
89 # set (HAVE_VORBIS 1)
90 # endif (HAVE_LIBVORBISENC2)
91 #else (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
92 # message(STATUS "Ogg/Vorbis not found")
93 #endif (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
94
95 if(OGGVORBIS_FOUND AND NOT TARGET OGGVORBIS::vorbis)
96 add_library(OGGVORBIS::ogg UNKNOWN IMPORTED)
97 set_target_properties(OGGVORBIS::ogg PROPERTIES
98 IMPORTED_LOCATION "${OGG_LIBRARY}"
99 INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIR}"
100 )
101 add_library(OGGVORBIS::vorbis UNKNOWN IMPORTED)
102 set_target_properties(OGGVORBIS::vorbis PROPERTIES
103 IMPORTED_LOCATION "${VORBIS_LIBRARY}"
104 INTERFACE_INCLUDE_DIRECTORIES "${VORBIS_INCLUDE_DIR}"
105 INTERFACE_LINK_LIBRARIES "OGGVORBIS::ogg;${VORBISFILE_LIBRARY};${VORBISENC_LIBRARY}"
106 )
107 endif()