From d5b220d7c30cc685f6016c6f21793c73688308d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Wed, 21 Oct 2020 11:59:36 +0200 Subject: [PATCH] Fix FindFFMPEG.cmake for older CMake (#344) --- cmake/FindFFMPEG.cmake | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/cmake/FindFFMPEG.cmake b/cmake/FindFFMPEG.cmake index 8ad5ec9..a1d0ecd 100644 --- a/cmake/FindFFMPEG.cmake +++ b/cmake/FindFFMPEG.cmake @@ -46,21 +46,29 @@ function (_ffmpeg_find component headername) if(PKG_CONFIG_FOUND) pkg_check_modules(FFMPEG_${component} lib${component} IMPORTED_TARGET) if(FFMPEG_${component}_FOUND) - if(APPLE) - join(FFMPEG_LDFLAGS_STRING " " ${FFMPEG_${component}_LDFLAGS}) - string(REGEX REPLACE "-Wl,-framework,([^ ]+)" "-framework \\1" FFMPEG_LDFLAGS_STRING_CLEAN ${FFMPEG_LDFLAGS_STRING}) - string(REGEX MATCHALL "-framework [^ ]+" FFMPEG_FRAMEWORKS ${FFMPEG_LDFLAGS_STRING_CLEAN}) - list(APPEND FFMPEG_${component}_LIBRARIES ${FFMPEG_FRAMEWORKS}) - set_target_properties(PkgConfig::FFMPEG_${component} PROPERTIES - INTERFACE_LINK_DIRECTORIES "${FFMPEG_${component}_LIBRARY_DIRS}" - INTERFACE_LINK_LIBRARIES "${FFMPEG_${component}_LIBRARIES}" - INTERFACE_LINK_OPTIONS "") - message("set libs to \"${FFMPEG_${component}_LIBRARIES}\"") - message("set lib dirs to \"${FFMPEG_${component}_LIBRARY_DIRS}\"") - message("set lib otps not to \"${FFMPEG_${component}_LDFLAGS}\"") + if((TARGET PkgConfig::FFMPEG_${component}) AND (NOT CMAKE_VERSION VERSION_LESS "3.11.0")) + if(APPLE) + join(FFMPEG_LDFLAGS_STRING " " ${FFMPEG_${component}_LDFLAGS}) + string(REGEX REPLACE "-Wl,-framework,([^ ]+)" "-framework \\1" FFMPEG_LDFLAGS_STRING_CLEAN ${FFMPEG_LDFLAGS_STRING}) + string(REGEX MATCHALL "-framework [^ ]+" FFMPEG_FRAMEWORKS ${FFMPEG_LDFLAGS_STRING_CLEAN}) + list(APPEND FFMPEG_${component}_LIBRARIES ${FFMPEG_FRAMEWORKS}) + set_target_properties(PkgConfig::FFMPEG_${component} PROPERTIES + INTERFACE_LINK_DIRECTORIES "${FFMPEG_${component}_LIBRARY_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFMPEG_${component}_LIBRARIES}" + INTERFACE_LINK_OPTIONS "") + message("set libs to \"${FFMPEG_${component}_LIBRARIES}\"") + message("set lib dirs to \"${FFMPEG_${component}_LIBRARY_DIRS}\"") + message("set lib otps not to \"${FFMPEG_${component}_LDFLAGS}\"") + endif() + set_target_properties(PkgConfig::FFMPEG_${component} PROPERTIES IMPORTED_GLOBAL TRUE) + add_library(FFMPEG::${component} ALIAS PkgConfig::FFMPEG_${component}) + else() + add_library("FFMPEG::${component}" INTERFACE IMPORTED) + set_target_properties("FFMPEG::${component}" PROPERTIES + INTERFACE_LINK_DIRECTORIES "${FFMPEG_${component}_LIBRARY_DIRS}" + INTERFACE_INCLUDE_DIRECTORIES "${FFMPEG_${component}_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${FFMPEG_${component}_LIBRARIES}") endif() - set_target_properties(PkgConfig::FFMPEG_${component} PROPERTIES IMPORTED_GLOBAL TRUE) - add_library(FFMPEG::${component} ALIAS PkgConfig::FFMPEG_${component}) return() endif() endif()