@@ -5,34 +5,75 @@ endif()
55add_library (${FFMPEG_CORE_NAME} INTERFACE )
66
77target_include_directories (${FFMPEG_CORE_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR} /include" )
8+
9+ # Detect OS
810if (WIN32 AND NOT MINGW)
11+ set (FFMPEG_PREBUILTS_NAME "ffmpeg-windows" )
12+ elseif (APPLE )
13+ set (FFMPEG_PREBUILTS_NAME "ffmpeg-macos" )
14+ elseif (UNIX )
15+ set (FFMPEG_PREBUILTS_NAME "ffmpeg-linux" )
16+ else ()
17+ message (FATAL_ERROR "Unsupported OS." )
18+ endif ()
19+
20+ # Detect Architecture
21+ if (NOT DEFINED ARCHITECTURE)
22+ message (FATAL_ERROR "ARCHITECTURE variable is not set up" )
23+ elseif (ARCHITECTURE STREQUAL "x86_64" )
24+ set (FFMPEG_PREBUILTS_NAME "${FFMPEG_PREBUILTS_NAME} -x64.zip" )
25+ elseif (ARCHITECTURE STREQUAL "arm64" )
26+ set (FFMPEG_PREBUILTS_NAME "${FFMPEG_PREBUILTS_NAME} -arm64.zip" )
27+ elseif (APPLE AND "x86_64" IN_LIST ARCHITECTURE AND "arm64" IN_LIST ARCHITECTURE) # macOS universal
28+ set (FFMPEG_PREBUILTS_NAME "${FFMPEG_PREBUILTS_NAME} -universal.zip" )
29+ else ()
30+ message (FATAL_ERROR "Unsupported architecture." )
31+ endif ()
32+
33+ # Compute current short git commit SHA
34+ execute_process (
35+ COMMAND git rev-parse --short HEAD
36+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
37+ OUTPUT_VARIABLE FFMPEG_GIT_SHA
38+ OUTPUT_STRIP_TRAILING_WHITESPACE)
39+
40+ # Download prebuilt ffmpeg
41+ if (NOT EXISTS "${CMAKE_BINARY_DIR} /external/ffmpeg.zip" )
42+ message (STATUS "Downloading FFMPEG prebuilts..." )
43+ file (DOWNLOAD https://github.com/Vita3K/ffmpeg-core/releases/download/${FFMPEG_GIT_SHA} /${FFMPEG_PREBUILTS_NAME}
44+ "${CMAKE_BINARY_DIR} /external/ffmpeg.zip" SHOW_PROGRESS
45+ STATUS FILE_STATUS)
46+ list (GET FILE_STATUS 0 STATUS_CODE)
47+ if (NOT STATUS_CODE EQUAL 0)
48+ file (REMOVE "${CMAKE_BINARY_DIR} /external/ffmpeg.zip" ) # CMake create 0 byte file even if URL is invalid. So need to delete it.
49+ message (FATAL_ERROR "No FFMPEG prebuilt found with corresponding commit SHA (${FFMPEG_GIT_SHA} )" )
50+ endif ()
51+ endif ()
52+
53+ if (NOT EXISTS "${CMAKE_BINARY_DIR} /external/ffmpeg/lib" )
54+ file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR} /external/ffmpeg/lib" )
55+ execute_process (COMMAND ${CMAKE_COMMAND} -E tar xzf "${CMAKE_BINARY_DIR} /external/ffmpeg.zip"
56+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR} /external/ffmpeg/lib" )
57+ endif ()
58+
59+ set (LIB_PREFIX "lib" )
60+ set (LIB_EXT "a" )
61+ if (WIN32 AND NOT MINGW)
62+ set (LIB_PREFIX "" )
63+ set (LIB_EXT "lib" )
964 target_link_libraries (${FFMPEG_CORE_NAME} INTERFACE
10- "${CMAKE_CURRENT_SOURCE_DIR} /lib/windows/x86_64/avformat.lib"
11- "${CMAKE_CURRENT_SOURCE_DIR} /lib/windows/x86_64/avcodec.lib"
12- "${CMAKE_CURRENT_SOURCE_DIR} /lib/windows/x86_64/swscale.lib"
13- "${CMAKE_CURRENT_SOURCE_DIR} /lib/windows/x86_64/avutil.lib"
14- "${CMAKE_CURRENT_SOURCE_DIR} /lib/windows/x86_64/avfilter.lib"
15- "${CMAKE_CURRENT_SOURCE_DIR} /lib/windows/x86_64/swresample.lib"
1665 "psapi;strmiids;uuid;oleaut32;shlwapi;ws2_32;ole32;user32;bcrypt" )
1766elseif (APPLE )
1867 target_link_libraries (${FFMPEG_CORE_NAME} INTERFACE
19- "${CMAKE_CURRENT_SOURCE_DIR} /lib/macos/libavformat.a"
20- "${CMAKE_CURRENT_SOURCE_DIR} /lib/macos/libavcodec.a"
21- "${CMAKE_CURRENT_SOURCE_DIR} /lib/macos/libswscale.a"
22- "${CMAKE_CURRENT_SOURCE_DIR} /lib/macos/libavutil.a"
23- "${CMAKE_CURRENT_SOURCE_DIR} /lib/macos/libavfilter.a"
24- "${CMAKE_CURRENT_SOURCE_DIR} /lib/macos/libswresample.a"
2568 "-framework CoreServices" "-framework CoreFoundation" "-framework AudioUnit"
2669 "-framework AudioToolbox" "-framework CoreAudio" "-framework CoreMedia"
2770 "-framework VideoToolbox" "-framework CoreVideo" "-framework Security" )
28- elseif (UNIX )
29- target_link_libraries (${FFMPEG_CORE_NAME} INTERFACE
30- "${CMAKE_CURRENT_SOURCE_DIR} /lib/linux/x86_64/libavformat.a"
31- "${CMAKE_CURRENT_SOURCE_DIR} /lib/linux/x86_64/libavcodec.a"
32- "${CMAKE_CURRENT_SOURCE_DIR} /lib/linux/x86_64/libswscale.a"
33- "${CMAKE_CURRENT_SOURCE_DIR} /lib/linux/x86_64/libavutil.a"
34- "${CMAKE_CURRENT_SOURCE_DIR} /lib/linux/x86_64/libavfilter.a"
35- "${CMAKE_CURRENT_SOURCE_DIR} /lib/linux/x86_64/libswresample.a" )
36- else ()
37- message (FATAL_ERROR "No prebuilt was found for ffmpeg" )
3871endif ()
72+
73+ target_link_libraries (${FFMPEG_CORE_NAME} INTERFACE
74+ "${CMAKE_BINARY_DIR} /external/ffmpeg/lib/${LIB_PREFIX} avformat.${LIB_EXT} "
75+ "${CMAKE_BINARY_DIR} /external/ffmpeg/lib/${LIB_PREFIX} avcodec.${LIB_EXT} "
76+ "${CMAKE_BINARY_DIR} /external/ffmpeg/lib/${LIB_PREFIX} swscale.${LIB_EXT} "
77+ "${CMAKE_BINARY_DIR} /external/ffmpeg/lib/${LIB_PREFIX} avutil.${LIB_EXT} "
78+ "${CMAKE_BINARY_DIR} /external/ffmpeg/lib/${LIB_PREFIX} avfilter.${LIB_EXT} "
79+ "${CMAKE_BINARY_DIR} /external/ffmpeg/lib/${LIB_PREFIX} swresample.${LIB_EXT} " )
0 commit comments