Skip to content

Commit

Permalink
[CMake] Tweak FindOpus.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Jun 21, 2024
1 parent 1e6c7ac commit 67f80ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
34 changes: 25 additions & 9 deletions cmake/FindOpus.cmake
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
# - Try to find the Opus library
# Once done this will define
#
# OPUS_FOUND - system has Opus
# OPUS_INCLUDE_DIR - the OggOpus include directory
# OPUS_LIBRARY - The Opus library
# Opus_FOUND - system has Opus
# Opus_INCLUDE_DIR - the OggOpus include directory
# Opus_LIBRARY - The Opus library
#
# Also creates the imported Opus::opus target

find_path(OPUS_INCLUDE_DIR opus/opus.h)
find_library(OPUS_LIBRARY NAMES opus)
# Try config mode first!
find_package(Opus CONFIG QUIET) # Deliberately quiet, so we can handle the result
if(Opus_FOUND)
if (TARGET Opus::opus)
# CONFIG mode succeeded
if(NOT Opus_INCLUDE_DIR)
get_target_property(Opus_INCLUDE_DIR Opus::opus INTERFACE_INCLUDE_DIRECTORIES)
endif()
if(NOT Opus_LIBRARY)
set(Opus_LIBRARY Opus::opus)
endif()
message(STATUS "Found Opus: ${Opus_INCLUDE_DIR}")
return()
endif()
endif()

mark_as_advanced(OPUS_INCLUDE_DIR OPUS_LIBRARY)
find_path(Opus_INCLUDE_DIR opus/opus.h)
find_library(Opus_LIBRARY NAMES opus)

mark_as_advanced(Opus_INCLUDE_DIR Opus_LIBRARY)

add_library(Opus::opus UNKNOWN IMPORTED)
set_target_properties(Opus::opus
PROPERTIES
IMPORTED_LOCATION "${OPUS_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${OPUS_INCLUDE_DIR}"
IMPORTED_LOCATION "${Opus_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${Opus_INCLUDE_DIR}"
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Opus REQUIRED_VARS OPUS_LIBRARY OPUS_INCLUDE_DIR)
find_package_handle_standard_args(Opus REQUIRED_VARS Opus_LIBRARY Opus_INCLUDE_DIR)
4 changes: 2 additions & 2 deletions lib/sound/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ else()
)
# opusfile.h includes "opus_multistream.h" instead of "opus/opus_multistream.h"
# so add "opus" subdirectory to fix that
set(OPUS_MULTISTREAM_DIR "${OPUS_INCLUDE_DIR}/opus")
set(OPUS_MULTISTREAM_DIR "${Opus_INCLUDE_DIR}/opus")
target_include_directories(opusfile PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/opusfile/include" "${OPUS_MULTISTREAM_DIR}")
target_link_libraries(opusfile PRIVATE Ogg::ogg Opus::opus)
include(CMakePushCheckState)
Expand All @@ -75,7 +75,7 @@ else()
include(CheckLibraryExists)
check_library_exists(m lrintf "" OP_HAVE_LIBM)
if(OP_HAVE_LIBM)
target_link_libraries(opusfile PRIVATE ${OGG_LIBRARY} ${OPUS_LIBRARY})
target_link_libraries(opusfile PRIVATE ${OGG_LIBRARY} ${Opus_LIBRARY})
list(APPEND CMAKE_REQUIRED_LIBRARIES "m")
endif()
check_symbol_exists(lrintf "math.h" OP_HAVE_LRINTF)
Expand Down

0 comments on commit 67f80ef

Please sign in to comment.