Skip to content

Commit

Permalink
cmake: add FindOpus.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr committed Jan 12, 2024
1 parent 3b1fc10 commit b5082e2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ if(SDL3MIXER_INSTALL)
cmake/Findlibxmp-lite.cmake
cmake/Findmodplug.cmake
cmake/FindOgg.cmake
cmake/FindOpus.cmake
cmake/FindOpusFile.cmake
cmake/Findmpg123.cmake
cmake/FindVorbis.cmake
Expand Down
51 changes: 51 additions & 0 deletions cmake/FindOpus.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
include(FindPackageHandleStandardArgs)

find_package(PkgConfig QUIET)
pkg_check_modules(PC_OPUS QUIET opus)

find_library(Opus_LIBRARY
NAMES opus
HINTS ${PC_OPUS_LIBDIR}
)

find_path(Opus_INCLUDE_PATH
NAMES opus.h
PATH_SUFFIXES opus
HINTS ${PC_OPUS_INCLUDEDIR}
)
list(APPEND Opus_INCLUDE_PATH "${Opus_INCLUDE_PATH}/opus")

if(PC_OPUS_FOUND)
get_flags_from_pkg_config("${Opus_LIBRARY}" "PC_OPUS" "_opus")
endif()

set(Opus_COMPILE_OPTIONS "${_opus_compile_options}" CACHE STRING "Extra compile options of opus")

set(Opus_LINK_LIBRARIES "${_opus_link_libraries}" CACHE STRING "Extra link libraries of opus")

set(Opus_LINK_OPTIONS "${_opus_link_options}" CACHE STRING "Extra link flags of opus")

set(Opus_LINK_DIRECTORIES "${_opus_link_directories}" CACHE PATH "Extra link directories of opus")

find_package(Ogg ${required})

find_package_handle_standard_args(Opus
REQUIRED_VARS Opus_LIBRARY Opus_INCLUDE_PATH Ogg_FOUND
)

if(Opus_FOUND)
set(Opus_dirs ${Opus_INCLUDE_PATH})
if(NOT TARGET Opus::opus)
add_library(Opus::opus UNKNOWN IMPORTED)
set_target_properties(Opus::opus PROPERTIES
IMPORTED_LOCATION "${Opus_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${Opus_dirs}"
INTERFACE_COMPILE_OPTIONS "${Opus_COMPILE_OPTIONS}:$<TARGET_PROPERTY:Ogg::ogg,INTERFACE_INCLUDE_DIRECTORIES>"
INTERFACE_LINK_LIBRARIES "${Opus_LINK_LIBRARIES}"
INTERFACE_LINK_OPTIONS "${Opus_LINK_OPTIONS}"
INTERFACE_LINK_DIRECTORIES "${Opus_LINK_DIRECTORIES}"
)
endif()
endif()

set(Opus_INCLUDE_DIRS ${Opus_INCLUDE_PATH})
6 changes: 3 additions & 3 deletions cmake/FindOpusFile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ set(OpusFile_LINK_OPTIONS "${_opusfile_link_options}" CACHE STRING "Extra link f

set(OpusFile_LINK_DIRECTORIES "${_opusfile_link_directories}" CACHE PATH "Extra link directories of opusfile")

find_package(Ogg ${required})
find_package(Opus)

find_package_handle_standard_args(OpusFile
REQUIRED_VARS OpusFile_LIBRARY OpusFile_INCLUDE_PATH Ogg_FOUND
REQUIRED_VARS OpusFile_LIBRARY OpusFile_INCLUDE_PATH Opus_FOUND
)

if(OpusFile_FOUND)
Expand All @@ -40,7 +40,7 @@ if(OpusFile_FOUND)
add_library(OpusFile::opusfile UNKNOWN IMPORTED)
set_target_properties(OpusFile::opusfile PROPERTIES
IMPORTED_LOCATION "${OpusFile_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${OpusFile_dirs};$<TARGET_PROPERTY:Ogg::ogg,INTERFACE_INCLUDE_DIRECTORIES>"
INTERFACE_INCLUDE_DIRECTORIES "${OpusFile_dirs};$<TARGET_PROPERTY:Opus::opus,INTERFACE_INCLUDE_DIRECTORIES>"
INTERFACE_COMPILE_OPTIONS "${OpusFile_COMPILE_OPTIONS}"
INTERFACE_LINK_LIBRARIES "${OpusFile_LINK_LIBRARIES}"
INTERFACE_LINK_OPTIONS "${OpusFile_LINK_OPTIONS}"
Expand Down

0 comments on commit b5082e2

Please sign in to comment.