Skip to content

Commit

Permalink
Merge pull request #11 from rainyl/ffmpeg-use-target
Browse files Browse the repository at this point in the history
use target for ffmpeg_libraries
  • Loading branch information
rainyl authored Sep 27, 2024
2 parents 17be80e + 4bbf97d commit ebd3e80
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 55 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
env:
ANDROID_PLATFORM: android-24
FFMPEG_ROOT: /tmp/ffmpeg
SOURCE_DIR: opencv

jobs:
android:
Expand All @@ -17,6 +18,7 @@ jobs:
opencv-version: [4.10.0]
abi: [armeabi-v7a, arm64-v8a, x86_64]
env:
PACKAGE_NAME: libopencv-android-${{ matrix.abi }}
COMMON_CMAKE_OPTIONS: |
-DCMAKE_POLICY_DEFAULT_CMP0057=NEW \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_LATEST_HOME/build/cmake/android.toolchain.cmake \
Expand All @@ -34,10 +36,11 @@ jobs:
- uses: actions/checkout@v4
- name: setup-opencv-source
run: |
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git opencv
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git ${{ env.SOURCE_DIR }}
git apply -p 0 patches/opencv-4.10.0-detect_ffmpeg.patch
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv_contrib.git opencv_contrib
echo "SOURCE_DIR=${{ github.workspace }}/opencv" >> "$GITHUB_ENV"
echo "PACKAGE_NAME=libopencv-android-${{ matrix.abi }}" >> "$GITHUB_ENV"
- name: setup ffmpeg
run: |
wget -q -O ffmpeg.tar.xz https://sourceforge.net/projects/avbuild/files/android/ffmpeg-6.1-android-lite.tar.xz
Expand Down
39 changes: 22 additions & 17 deletions .github/workflows/apple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ env:
ENABLE_ARC: OFF
ENABLE_VISIBILITY: OFF
FFMPEG_ROOT: /tmp/ffmpeg
SOURCE_DIR: opencv
OPENCV_SUBDIR: lib/cmake/opencv4

jobs:
ios:
Expand All @@ -23,6 +25,7 @@ jobs:
matrix:
opencv-version: [4.10.0]
env:
PACKAGE_NAME: libopencv-ios-arm64
COMMON_CMAKE_OPTIONS: |
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/cmake/ios.toolchain.cmake \
-DDEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET \
Expand All @@ -41,11 +44,11 @@ jobs:
- uses: actions/checkout@v4
- name: setup-opencv-source
run: |
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git opencv
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git ${{ env.SOURCE_DIR }}
git apply -p 0 patches/opencv-4.10.0-detect_ffmpeg.patch
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv_contrib.git opencv_contrib
echo "SOURCE_DIR=${{ github.workspace }}/opencv" >> "$GITHUB_ENV"
echo "PACKAGE_NAME=libopencv-ios-arm64" >> "$GITHUB_ENV"
echo "OPENCV_SUBDIR=lib/cmake/opencv4" >> "$GITHUB_ENV"
- name: setup ffmpeg
run: |
wget -q -O ffmpeg.tar.xz https://sourceforge.net/projects/avbuild/files/iOS/ffmpeg-6.1-iOS-lite-shared.tar.xz
Expand All @@ -55,8 +58,8 @@ jobs:
cp -rf ${{ github.workspace }}/cmake/ffmpeg-config.cmake $FFMPEG_ROOT/cmake/
- name: build
run: |
cd ${{ env.SOURCE_DIR }}
mkdir build && cd build
mkdir -p opencv/build
cd opencv/build
cmake `cat ${{ github.workspace }}/options.txt` \
${{ env.COMMON_CMAKE_OPTIONS }} -S .. \
-DPLATFORM=OS64 \
Expand Down Expand Up @@ -103,6 +106,7 @@ jobs:
- { arch: x64, name: SIMULATOR64 }
- { arch: arm64, name: SIMULATORARM64 }
env:
PACKAGE_NAME: libopencv-iossimulator-${{ matrix.platform.arch }}
COMMON_CMAKE_OPTIONS: |
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/cmake/ios.toolchain.cmake \
-DDEPLOYMENT_TARGET=$IOS_DEPLOYMENT_TARGET \
Expand All @@ -122,10 +126,10 @@ jobs:
- name: setup-opencv-source
run: |
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git opencv
git apply -p 0 patches/opencv-4.10.0-detect_ffmpeg.patch
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv_contrib.git opencv_contrib
echo "SOURCE_DIR=${{ github.workspace }}/opencv" >> "$GITHUB_ENV"
echo "PACKAGE_NAME=libopencv-iossimulator-${{ matrix.platform.arch }}" >> "$GITHUB_ENV"
echo "OPENCV_SUBDIR=lib/cmake/opencv4" >> "$GITHUB_ENV"
- name: setup ffmpeg
run: |
wget -q -O ffmpeg.tar.xz https://sourceforge.net/projects/avbuild/files/iOSSimulator/ffmpeg-6.1-iOSSimulator-lite-shared.tar.xz
Expand All @@ -135,8 +139,8 @@ jobs:
cp -rf ${{ github.workspace }}/cmake/ffmpeg-config.cmake $FFMPEG_ROOT/cmake/
- name: build
run: |
cd ${{ env.SOURCE_DIR }}
mkdir build && cd build
mkdir -p opencv/build
cd opencv/build
cmake `cat ${{ github.workspace }}/options.txt` \
${{ env.COMMON_CMAKE_OPTIONS }} -S .. \
-DPLATFORM=${{ matrix.platform.name }} \
Expand Down Expand Up @@ -180,10 +184,11 @@ jobs:
matrix:
opencv-version: [4.10.0]
osname:
- { os: macos-13, arch: x64, platform: MAC }
- { os: macos-14, arch: x64, platform: MAC }
- { os: macos-14, arch: arm64, platform: MAC_ARM64 }
runs-on: ${{ matrix.osname.os }}
env:
PACKAGE_NAME: libopencv-macos-${{ matrix.osname.arch }}
COMMON_CMAKE_OPTIONS: |
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/cmake/ios.toolchain.cmake \
-DDEPLOYMENT_TARGET=$MAC_DEPLOYMENT_TARGET \
Expand All @@ -199,10 +204,10 @@ jobs:
- name: setup-opencv-source
run: |
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git opencv
git apply -p 0 patches/opencv-4.10.0-detect_ffmpeg.patch
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv_contrib.git opencv_contrib
echo "SOURCE_DIR=${{ github.workspace }}/opencv" >> "$GITHUB_ENV"
echo "PACKAGE_NAME=libopencv-macos-${{ matrix.osname.arch }}" >> "$GITHUB_ENV"
echo "OPENCV_SUBDIR=lib/cmake/opencv4" >> "$GITHUB_ENV"
- name: setup ffmpeg
run: |
wget -q -O ffmpeg.tar.xz https://sourceforge.net/projects/avbuild/files/macOS/ffmpeg-6.1-macOS-lite.tar.xz
Expand All @@ -212,8 +217,8 @@ jobs:
cp -rf ${{ github.workspace }}/cmake/ffmpeg-config.cmake $FFMPEG_ROOT/cmake/
- name: build
run: |
cd ${{ env.SOURCE_DIR }}
mkdir build && cd build
mkdir -p opencv/build
cd opencv/build
cmake `cat ${{ github.workspace }}/options.txt` \
${{ env.COMMON_CMAKE_OPTIONS }} -S .. \
-DPLATFORM=${{ matrix.osname.platform }} \
Expand Down
21 changes: 12 additions & 9 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:

env:
FFMPEG_ROOT: /tmp/ffmpeg
SOURCE_DIR: opencv
OPENCV_SUBDIR: lib/cmake/opencv4

jobs:
linux-x64:
Expand All @@ -18,6 +20,7 @@ jobs:
os:
- { arch: x64, ffmpeg_arch: amd64 }
env:
PACKAGE_NAME: libopencv-linux-${{ matrix.os.arch }}
COMMON_CMAKE_OPTIONS: |
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_BUILD_TYPE=Release \
Expand All @@ -27,16 +30,16 @@ jobs:
- name: setup
run: |
sudo apt-get update
sudo apt-get install libgtk-3-dev
sudo apt-get install -y libgtk-3-dev
- uses: actions/checkout@v4
- name: setup-opencv-source
run: |
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git opencv
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git ${{ env.SOURCE_DIR }}
git apply -p 0 patches/opencv-4.10.0-detect_ffmpeg.patch
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv_contrib.git opencv_contrib
echo "SOURCE_DIR=${{ github.workspace }}/opencv" >> "$GITHUB_ENV"
echo "PACKAGE_NAME=libopencv-linux-${{ matrix.os.arch }}" >> "$GITHUB_ENV"
echo "OPENCV_SUBDIR=lib/cmake/opencv4" >> "$GITHUB_ENV"
- name: setup ffmpeg
run: |
wget -q -O ffmpeg.tar.xz https://github.com/rainyl/FFmpeg-Builds/releases/download/latest/ffmpeg-n6.1-latest-linux64-lgpl-shared-6.1.tar.xz
Expand Down Expand Up @@ -66,7 +69,6 @@ jobs:
cd test
mkdir build && cd build
cmake ${{ env.COMMON_CMAKE_OPTIONS }} \
${{ env.TOOLCHAIN_FILE }} \
-DOpenCV_DIR=${{ github.workspace }}/${{ env.PACKAGE_NAME }}/${{ env.OPENCV_SUBDIR }} \
-DFFMPEG_DIR=$FFMPEG_ROOT/cmake ..
cmake --build . -j $(nproc)
Expand All @@ -92,6 +94,7 @@ jobs:
os:
- { arch: arm64, ffmpeg_arch: arm64 }
env:
PACKAGE_NAME: libopencv-linux-${{ matrix.os.arch }}
COMMON_CMAKE_OPTIONS: |
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_BUILD_TYPE=Release \
Expand All @@ -107,10 +110,10 @@ jobs:
- name: setup-opencv-source
run: |
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git opencv
git apply -p 0 patches/opencv-4.10.0-detect_ffmpeg.patch
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv_contrib.git opencv_contrib
echo "SOURCE_DIR=${{ github.workspace }}/opencv" >> "$GITHUB_ENV"
echo "PACKAGE_NAME=libopencv-linux-${{ matrix.os.arch }}" >> "$GITHUB_ENV"
echo "OPENCV_SUBDIR=lib/cmake/opencv4" >> "$GITHUB_ENV"
- name: setup ffmpeg
run: |
wget -q -O ffmpeg.tar.xz https://github.com/rainyl/FFmpeg-Builds/releases/download/latest/ffmpeg-n6.1-latest-linuxarm64-lgpl-shared-6.1.tar.xz
Expand Down
24 changes: 13 additions & 11 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

env:
FFMPEG_ROOT: C:\ffmpeg
SOURCE_DIR: opencv

jobs:
windows:
Expand All @@ -19,6 +20,7 @@ jobs:
runs-on: windows-2019
env:
UseMultiToolTask: true
PACKAGE_NAME: libopencv-windows-${{ matrix.os.arch }}
COMMON_CMAKE_OPTIONS: |
$(type ${{ github.workspace }}/options.txt) `
-T ${{ matrix.os.toolset-version }},host=x64 `
Expand All @@ -32,10 +34,11 @@ jobs:
- uses: actions/checkout@v4
- name: setup-opencv-source
run: |
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git opencv
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git ${{ env.SOURCE_DIR }}
git apply -p 0 patches/opencv-4.10.0-detect_ffmpeg.patch
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv_contrib.git opencv_contrib
echo "SOURCE_DIR=${{ github.workspace }}/opencv" >> $env:GITHUB_ENV
echo "PACKAGE_NAME=libopencv-windows-${{ matrix.os.arch }}" >> $env:GITHUB_ENV
- name: download ffmpeg
uses: robinraju/release-downloader@v1.10
with:
Expand All @@ -52,8 +55,7 @@ jobs:
cp -Recurse -Force ${{ github.workspace }}/cmake/ffmpeg-config.cmake $env:FFMPEG_ROOT/cmake/
- name: build
run: |
cd ${{ env.SOURCE_DIR }}
mkdir build
mkdir -Force ${{ env.SOURCE_DIR }}/build
cd ${{ env.SOURCE_DIR }}/build
cmake ${{ env.COMMON_CMAKE_OPTIONS }} -S .. `
-DFFMPEG_DIR="$env:FFMPEG_ROOT/cmake"
Expand Down Expand Up @@ -98,6 +100,7 @@ jobs:
runs-on: windows-2019
env:
UseMultiToolTask: true
PACKAGE_NAME: libopencv-windows-${{ matrix.os.arch }}
COMMON_CMAKE_OPTIONS: |
$(type ${{ github.workspace }}/options.txt) `
-T ${{ matrix.os.toolset-version }},host=x64 `
Expand All @@ -112,10 +115,11 @@ jobs:
- uses: actions/checkout@v4
- name: setup-opencv-source
run: |
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git opencv
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv.git ${{ env.SOURCE_DIR }}
git apply -p 0 patches/opencv-4.10.0-detect_ffmpeg.patch
git clone -b ${{ matrix.opencv-version }} https://github.com/opencv/opencv_contrib.git opencv_contrib
echo "SOURCE_DIR=${{ github.workspace }}/opencv" >> $env:GITHUB_ENV
echo "PACKAGE_NAME=libopencv-windows-${{ matrix.os.arch }}" >> $env:GITHUB_ENV
- name: download ffmpeg
uses: robinraju/release-downloader@v1.10
with:
Expand All @@ -132,13 +136,11 @@ jobs:
cp -Recurse -Force ${{ github.workspace }}/cmake/ffmpeg-config.cmake $env:FFMPEG_ROOT/cmake/
- name: build
run: |
cd ${{ env.SOURCE_DIR }}
mkdir build
mkdir -Force ${{ env.SOURCE_DIR }}/build
cd ${{ env.SOURCE_DIR }}/build
cmake ${{ env.COMMON_CMAKE_OPTIONS }} -S .. `
-DWITH_IPP=OFF `
-DFFMPEG_DIR="$env:FFMPEG_ROOT/cmake"
cd ${{ env.SOURCE_DIR }}/build
cmake --build . --config Release --target install -j 4
- name: package
run: |
Expand Down
45 changes: 32 additions & 13 deletions cmake/ffmpeg-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,28 @@ if(NOT DEFINED FFMPEG_ROOT)
endif()

# some builds have multiple architectures like `lib/arm64`
if(NOT DEFINED FFMPEG_ARCH)
message(STATUS "FFMPEG_ARCH not defined, set to: ${CMAKE_SYSTEM_PROCESSOR}")
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} FFMPEG_ARCH)
if(DEFINED FFMPEG_ARCH)
# custom overridden values
elseif(MSVC)
# see Modules/CMakeGenericSystem.cmake
if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
set(FFMPEG_ARCH "x64")
elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64")
set(FFMPEG_ARCH "ARM64")
elseif("${CMAKE_GENERATOR}" MATCHES "ARM")
set(FFMPEG_ARCH "ARM")
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
set(FFMPEG_ARCH "x64")
else()
set(FFMPEG_ARCH x86)
endif()
elseif(MINGW)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
set(FFMPEG_ARCH x64)
else()
set(FFMPEG_ARCH x86)
endif()
message(STATUS "FFMPEG_ARCH not defined, set to: ${FFMPEG_ARCH}")
endif()

message(STATUS "FFMPEG_ROOT: ${FFMPEG_ROOT}")
Expand All @@ -131,12 +150,11 @@ set(
)

# set(FFMPEG_FIND_COMPONENTS
# avcodec
# avformat
# avutil
# swscale
# avcodec
# avformat
# avutil
# swscale
# )

set(component_avcodec libavcodec avcodec avcodec.h)
set(component_avdevice libavdevice avdevice avdevice.h)
set(component_avformat libavformat avformat avformat.h)
Expand Down Expand Up @@ -306,7 +324,7 @@ macro(ffmpeg_check_version)
set(FFMPEG_${component_libname}_VERSION "${_version_major}.${_version_minor}.${_version_micro}")
message(DEBUG "[FindFFMPEG]: found ${component}: ${_version_major}.${_version_minor}.${_version_micro}")
else()
message(AUTHOR_WARNING "Failed to find ${component_name} version.")
message(STATUS "Failed to find ${component_name} version.")
endif()

unset(_version_major)
Expand All @@ -316,7 +334,7 @@ macro(ffmpeg_check_version)
unset(_major_version_file)
else()
if(NOT FFMPEG_FIND_QUIETLY)
message(AUTHOR_WARNING "Failed to find ${component_name} version.")
message(STATUS "Failed to find ${component_name} version.")
endif()

# set(FFMPEG_${component_libname}_VERSION 0.0.0)
Expand Down Expand Up @@ -412,7 +430,10 @@ foreach(component IN LISTS FFMPEG_FIND_COMPONENTS)
endif()

if(FFMPEG_${component}_FOUND)
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${FFMPEG_${component}_LIBRARY})
ffmpeg_create_target(${component})

# set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${FFMPEG_${component}_LIBRARY})
set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} FFMPEG::${component})
set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${FFMPEG_${component}_DEFINITIONS})
set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} ${FFMPEG_${component}_INCLUDE_DIR})
endif()
Expand Down Expand Up @@ -458,8 +479,6 @@ if(FFMPEG_FOUND AND NOT TARGET FFMPEG::FFMPEG)
add_library(FFMPEG::FFMPEG INTERFACE IMPORTED)

foreach(component IN LISTS FFMPEG_FIND_COMPONENTS)
ffmpeg_create_target(${component})

if(FFMPEG_${component}_FOUND)
set_property(TARGET FFMPEG::FFMPEG APPEND PROPERTY INTERFACE_LINK_LIBRARIES FFMPEG::${component})
endif()
Expand Down
3 changes: 1 addition & 2 deletions options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
-DWITH_GDCM=OFF
-DWITH_TBB=OFF
-DWITH_HPX=OFF
-DWITH_OPENMP=ON
-DWITH_PTHREADS_PF=OFF
-DWITH_OPENMP=OFF
-DWITH_CLP=OFF
-DWITH_OPENCL=ON
-DWITH_OPENCL_SVM=OFF
Expand Down
Loading

0 comments on commit ebd3e80

Please sign in to comment.