From e03690f1f049240a48d0ccb41a68a746890d784f Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Sat, 21 Jan 2017 02:36:06 +0100 Subject: [PATCH] cmake: Find prebuilt ffmpeg on Windows --- CMakeTests/CheckLib.cmake | 74 +++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/CMakeTests/CheckLib.cmake b/CMakeTests/CheckLib.cmake index ac8d17393b..c17dfb5e83 100644 --- a/CMakeTests/CheckLib.cmake +++ b/CMakeTests/CheckLib.cmake @@ -61,30 +61,66 @@ macro(check_libav) pkg_check_modules(LIBAV libavcodec>=54.35.0 libavformat>=54.20.4 libswscale>=2.1.1 libavutil>=52.3.0) else() - # Attempt to find it through static means - set(LIBAV_LDFLAGS avformat avcodec swscale avutil) - set(CMAKE_REQUIRED_LIBRARIES ${LIBAV_LDFLAGS}) - CHECK_CXX_SOURCE_COMPILES( - "extern \"C\" { - #include - #include - #include - #include - } - int main(int argc, char **argv) - { - av_register_all(); - return 0; - }" - LIBAV_FOUND) - unset(CMAKE_REQUIRED_LIBRARIES) + if(WIN32) + add_library(avcodec STATIC IMPORTED) + set_target_properties(avcodec PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/include + IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/lib/avcodec.lib + ) + + add_library(avformat STATIC IMPORTED) + set_target_properties(avformat PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/include + IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/lib/avformat.lib + ) + + add_library(avutil STATIC IMPORTED) + set_target_properties(avutil PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/include + IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/lib/avutil.lib + ) + + add_library(swresample STATIC IMPORTED) + set_target_properties(swresample PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/include + IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/lib/swresample.lib + ) + + add_library(swscale STATIC IMPORTED) + set_target_properties(swscale PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/include + IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/Externals/ffmpeg/lib/swscale.lib + ) + + set(LIBAV_FOUND ON) + set(LIBAV_LIBRARIES avcodec avformat avutil swresample swscale) + else() + # Attempt to find it through static means + set(LIBAV_LDFLAGS avformat avcodec swscale avutil) + set(CMAKE_REQUIRED_LIBRARIES ${LIBAV_LDFLAGS}) + CHECK_CXX_SOURCE_COMPILES( + "extern \"C\" { + #include + #include + #include + #include + } + int main(int argc, char **argv) + { + av_register_all(); + return 0; + }" + LIBAV_FOUND) + unset(CMAKE_REQUIRED_LIBRARIES) + endif() endif() if(LIBAV_FOUND) message(STATUS "libav/ffmpeg found, enabling AVI frame dumps") add_definitions(-DHAVE_LIBAV) - include_directories(${LIBAV_INCLUDE_DIRS}) + if(LIBAV_INCLUDE_DIRS) + include_directories(${LIBAV_INCLUDE_DIRS}) + endif() else() message(STATUS "libav/ffmpeg not found, disabling AVI frame dumps") endif() endmacro() -