diff --git a/cmake/FindOpus.cmake b/cmake/FindOpus.cmake index b0b232c59d0..2392d6c5cc0 100644 --- a/cmake/FindOpus.cmake +++ b/cmake/FindOpus.cmake @@ -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) diff --git a/lib/sound/CMakeLists.txt b/lib/sound/CMakeLists.txt index 31c9253ee11..e61b9105546 100644 --- a/lib/sound/CMakeLists.txt +++ b/lib/sound/CMakeLists.txt @@ -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) @@ -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)