diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index 41e4d874..5224a1f5 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -379,23 +379,6 @@ function(sfml_add_test target SOURCES DEPENDS) catch_discover_tests(${target} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) endfunction() -# Find the requested package and make an INTERFACE library from it -# The created INTERFACE library is tagged for export to be part of the generated SFMLConfig -# Usage: sfml_find_package(wanted_target_name [OPENGL_INCLUDE_DIR] [OPENGL_gl_LIBRARY]) -function(sfml_find_package target INCLUDE_DIRS LINK_LIBRARIES) - if(TARGET ${target}) - message(FATAL_ERROR "Target '${target}' is already defined") - endif() - - find_package(${target} REQUIRED) - add_library(${target} INTERFACE) - - target_include_directories(${target} SYSTEM INTERFACE "$") - target_link_libraries(${target} INTERFACE "$") - - install(TARGETS ${target} EXPORT SFMLConfigExport) -endfunction() - # Generate a SFMLConfig.cmake file (and associated files) from the targets registered against # the EXPORT name "SFMLConfigExport" (EXPORT parameter of install(TARGETS)) function(sfml_export_targets) diff --git a/cmake/Modules/FindVORBIS.cmake b/cmake/Modules/FindVORBIS.cmake deleted file mode 100644 index c9b1a799..00000000 --- a/cmake/Modules/FindVORBIS.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# -# Try to find Ogg/Vorbis libraries and include paths. -# Once done this will define -# -# VORBIS_FOUND -# VORBIS_INCLUDE_DIRS -# VORBIS_LIBRARIES -# - -find_path(OGG_INCLUDE_DIR ogg/ogg.h) -find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h) - -find_library(OGG_LIBRARY NAMES ogg) -find_library(VORBIS_LIBRARY NAMES vorbis) -if(NOT SFML_OS_IOS) - find_library(VORBISFILE_LIBRARY NAMES vorbisfile) - find_library(VORBISENC_LIBRARY NAMES vorbisenc) - set(VORBIS_LIBRARIES ${VORBISENC_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY}) -else() - set(VORBIS_LIBRARIES ${VORBIS_LIBRARY} ${OGG_LIBRARY}) -endif() - -include(FindPackageHandleStandardArgs) - -find_package_handle_standard_args(VORBIS DEFAULT_MSG VORBIS_LIBRARIES VORBIS_INCLUDE_DIR OGG_INCLUDE_DIR) - -set(VORBIS_INCLUDE_DIRS ${OGG_INCLUDE_DIR} ${VORBIS_INCLUDE_DIR}) - -mark_as_advanced(OGG_INCLUDE_DIR VORBIS_INCLUDE_DIR OGG_LIBRARY VORBIS_LIBRARY VORBISFILE_LIBRARY VORBISENC_LIBRARY) diff --git a/cmake/Modules/FindVorbis.cmake b/cmake/Modules/FindVorbis.cmake new file mode 100644 index 00000000..361ccf7f --- /dev/null +++ b/cmake/Modules/FindVorbis.cmake @@ -0,0 +1,69 @@ +# +# Try to find Ogg/Vorbis libraries and include paths. +# Once done this will define +# +# VORBIS_FOUND +# VORBIS_INCLUDE_DIRS +# VORBIS_LIBRARIES +# + +find_path(OGG_INCLUDE_DIR ogg/ogg.h) +find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h) + +find_library(OGG_LIBRARY NAMES ogg) +find_library(VORBIS_LIBRARY NAMES vorbis) +find_library(VORBISFILE_LIBRARY NAMES vorbisfile) +find_library(VORBISENC_LIBRARY NAMES vorbisenc) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(Vorbis DEFAULT_MSG + OGG_INCLUDE_DIR + OGG_LIBRARY + VORBIS_INCLUDE_DIR + VORBIS_LIBRARY) +mark_as_advanced( + OGG_INCLUDE_DIR + OGG_LIBRARY + VORBIS_INCLUDE_DIR + VORBIS_LIBRARY + VORBISFILE_LIBRARY + VORBISENC_LIBRARY) + +add_library(Ogg::ogg IMPORTED UNKNOWN) +set_target_properties(Ogg::ogg PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${OGG_INCLUDE_DIR}) +if(OGG_LIBRARY MATCHES "/([^/]+)\\.framework$") + set_target_properties(Ogg::ogg PROPERTIES IMPORTED_LOCATION ${OGG_LIBRARY}/${CMAKE_MATCH_1}) +else() + set_target_properties(Ogg::ogg PROPERTIES IMPORTED_LOCATION ${OGG_LIBRARY}) +endif() + +add_library(Vorbis::vorbis IMPORTED UNKNOWN) +set_target_properties(Vorbis::vorbis PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${VORBIS_INCLUDE_DIR} + INTERFACE_LINK_LIBRARIES Ogg::ogg) +if(VORBIS_LIBRARY MATCHES "/([^/]+)\\.framework$") + set_target_properties(Vorbis::vorbis PROPERTIES IMPORTED_LOCATION ${VORBIS_LIBRARY}/${CMAKE_MATCH_1}) +else() + set_target_properties(Vorbis::vorbis PROPERTIES IMPORTED_LOCATION ${VORBIS_LIBRARY}) +endif() + +if(VORBISFILE_LIBRARY) + add_library(Vorbis::vorbisfile IMPORTED UNKNOWN) + set_target_properties(Vorbis::vorbisfile PROPERTIES INTERFACE_LINK_LIBRARIES Vorbis::vorbis) + if(VORBISFILE_LIBRARY MATCHES "/([^/]+)\\.framework$") + set_target_properties(Vorbis::vorbisfile PROPERTIES IMPORTED_LOCATION ${VORBISFILE_LIBRARY}/${CMAKE_MATCH_1}) + else() + set_target_properties(Vorbis::vorbisfile PROPERTIES IMPORTED_LOCATION ${VORBISFILE_LIBRARY}) + endif() +endif() + +if(VORBISENC_LIBRARY) + add_library(Vorbis::vorbisenc IMPORTED UNKNOWN) + set_target_properties(Vorbis::vorbisenc PROPERTIES INTERFACE_LINK_LIBRARIES Vorbis::vorbis) + if(VORBISENC_LIBRARY MATCHES "/([^/]+)\\.framework$") + set_target_properties(Vorbis::vorbisenc PROPERTIES IMPORTED_LOCATION ${VORBISENC_LIBRARY}/${CMAKE_MATCH_1}) + else() + set_target_properties(Vorbis::vorbisenc PROPERTIES IMPORTED_LOCATION ${VORBISENC_LIBRARY}) + endif() +endif() diff --git a/cmake/SFMLConfigDependencies.cmake.in b/cmake/SFMLConfigDependencies.cmake.in index 178452dd..6762accf 100644 --- a/cmake/SFMLConfigDependencies.cmake.in +++ b/cmake/SFMLConfigDependencies.cmake.in @@ -24,24 +24,6 @@ if(SFML_STATIC_LIBRARIES) # start with an empty list set(FIND_SFML_DEPENDENCIES_NOTFOUND) - # macro that searches for a 3rd-party library - function(sfml_bind_dependency) - cmake_parse_arguments(THIS "" "TARGET;FRIENDLY_NAME" "SEARCH_NAMES" ${ARGN}) - if(THIS_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unknown arguments when calling sfml_bind_dependency: ${THIS_UNPARSED_ARGUMENTS}") - endif() - - # No lookup in environment variables (PATH on Windows), as they may contain wrong library versions - find_library(${THIS_FRIENDLY_NAME}_LIB NAMES ${THIS_SEARCH_NAMES} - PATHS ${FIND_SFML_PATHS} PATH_SUFFIXES lib NO_SYSTEM_ENVIRONMENT_PATH) - mark_as_advanced(${THIS_FRIENDLY_NAME}_LIB) - if(${THIS_FRIENDLY_NAME}_LIB) - set_property(TARGET ${THIS_TARGET} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "${${THIS_FRIENDLY_NAME}_LIB}") - else() - set(FIND_SFML_DEPENDENCIES_NOTFOUND "${FIND_SFML_DEPENDENCIES_NOTFOUND} ${THIS_FRIENDLY_NAME}" PARENT_SCOPE) - endif() - endfunction() - # SFML::Window list(FIND SFML_FIND_COMPONENTS "Window" FIND_SFML_WINDOW_COMPONENT_INDEX) if(FIND_SFML_WINDOW_COMPONENT_INDEX GREATER -1) @@ -74,12 +56,7 @@ if(SFML_STATIC_LIBRARIES) list(FIND SFML_FIND_COMPONENTS "Audio" FIND_SFML_AUDIO_COMPONENT_INDEX) if(FIND_SFML_AUDIO_COMPONENT_INDEX GREATER -1) find_package(OpenAL) - if(NOT FIND_SFML_OS_IOS) - sfml_bind_dependency(TARGET VORBIS FRIENDLY_NAME "VorbisFile" SEARCH_NAMES "vorbisfile") - sfml_bind_dependency(TARGET VORBIS FRIENDLY_NAME "VorbisEnc" SEARCH_NAMES "vorbisenc") - endif() - sfml_bind_dependency(TARGET VORBIS FRIENDLY_NAME "Vorbis" SEARCH_NAMES "vorbis") - sfml_bind_dependency(TARGET VORBIS FRIENDLY_NAME "Ogg" SEARCH_NAMES "ogg") + find_package(Vorbis) find_package(FLAC) endif() diff --git a/src/SFML/Audio/CMakeLists.txt b/src/SFML/Audio/CMakeLists.txt index aad18505..266ef2d5 100644 --- a/src/SFML/Audio/CMakeLists.txt +++ b/src/SFML/Audio/CMakeLists.txt @@ -69,7 +69,7 @@ endif() # find external libraries find_package(OpenAL REQUIRED) -sfml_find_package(VORBIS VORBIS_INCLUDE_DIRS VORBIS_LIBRARIES) +find_package(Vorbis REQUIRED) find_package(FLAC REQUIRED) # define the sfml-audio target @@ -82,7 +82,10 @@ target_compile_definitions(sfml-audio PRIVATE OV_EXCLUDE_STATIC_CALLBACKS FLAC__ # setup dependencies target_link_libraries(sfml-audio PUBLIC SFML::System - PRIVATE OpenAL::OpenAL VORBIS FLAC::FLAC) + PRIVATE OpenAL::OpenAL Vorbis::vorbis FLAC::FLAC) +if(NOT SFML_OS_IOS) + target_link_libraries(sfml-audio PRIVATE Vorbis::vorbisfile Vorbis::vorbisenc) +endif() # minimp3 sources target_include_directories(sfml-audio SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/minimp3")