Skip to content

Commit

Permalink
Add FFmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
sakertooth committed Jun 11, 2022
1 parent 230aece commit c71a358
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ jobs:
- checkout
- *init
- *restore_cache
- run:
name: Install FFMpeg
command: apt update && apt install ffmpeg -y
- run:
name: Configure
command: |
Expand Down
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,22 @@ FIND_PACKAGE(SndFile REQUIRED)
IF(NOT SNDFILE_FOUND)
MESSAGE(FATAL_ERROR "LMMS requires libsndfile1 and libsndfile1-dev >= 1.0.18 - please install, remove CMakeCache.txt and try again!")
ENDIF()

# check for FFmpeg
FIND_PACKAGE(FFmpeg REQUIRED COMPONENTS avcodec avformat avutil)

INCLUDE_DIRECTORIES(
${FFmpeg_avcodec_INCLUDE_DIR}
${FFmpeg_avformat_INCLUDE_DIR}
${FFmpeg_avutil_INCLUDE_DIR}
)

SET(FFmpeg_LIBRARIES
FFmpeg::avcodec
FFmpeg::avformat
FFmpeg::avutil
)

# check if we can use SFC_SET_COMPRESSION_LEVEL
INCLUDE(CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES(
Expand Down
107 changes: 107 additions & 0 deletions cmake/modules/FindFFmpeg.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Distributed under the MIT License. See accompanying
# Copyright (c) 2022 sakertooth <[email protected]>

#[=======================================================================[.rst:
FindFFmpeg
-------
Finds the FFmpeg library.
Result Variables
^^^^^^^^^^^^^^^^
``FFmpeg_FOUND``
True if the system has the required FFmpeg components.
``FFmpeg_INCLUDE_DIRS``
The include directories of the required FFmpeg components.
``FFmpeg_LIBRARIES``
The libraries of the required FFmpeg components.
For each FFmpeg component:
avcodec,
avformat,
avutil,
avfilter,
avdevice,
swresample,
swscale
That is required, this will define the following variables:
``FFmpeg_<component>_FOUND``
True if the FFmpeg component was found.
``FFmpeg_<component>_INCLUDE_DIR``
The include directory for the FFmpeg component.
``FFmpeg_<component>_LIBRARY``
The library for the FFmpeg component.
``FFmpeg_<component>_VERSION``
The version for the FFmpeg component.
``FFmpeg::<component>``
The FFmpeg component as an imported target.
#]=======================================================================]

find_package(PkgConfig)
foreach(component ${FFmpeg_FIND_COMPONENTS})
pkg_check_modules(PC_FFmpeg_${component} QUIET lib${component})

find_path(FFmpeg_${component}_INCLUDE_DIR
NAMES lib${component}/${component}.h
PATHS ${PC_FFmpeg_${component}_INCLUDEDIR} /usr/include
)

find_library(FFmpeg_${component}_LIBRARY
NAMES ${component}
PATHS ${PC_FFmpeg_${component}_LIBDIR} /usr/lib/x86_64-linux-gnu/
)

if (FFmpeg_${component}_INCLUDE_DIR AND FFmpeg_${component}_LIBRARY)
set(FFmpeg_${component}_FOUND TRUE)
endif()

if (PKG_CONFIG_FOUND)
set(FFmpeg_${component}_VERSION ${PC_FFmpeg_${component}_VERSION})
else()
string(TOUPPER ${component} component_upper)
file(STRINGS ${FFmpeg_${component}_INCLUDE_DIR}/lib${component}/version.h version
REGEX "#define *LIB${component_upper}_VERSION_(MAJOR|MINOR|MICRO) ")
string(REGEX REPLACE ".*_MAJOR *\([0-9]*\).*" "\\1" major "${version}")
string(REGEX REPLACE ".*_MINOR *\([0-9]*\).*" "\\1" minor "${version}")
string(REGEX REPLACE ".*_MICRO *\([0-9]*\).*" "\\1" micro "${version}")

if (NOT major STREQUAL "" AND NOT minor STREQUAL "" AND NOT micro STREQUAL "")
set(FFmpeg_${component}_VERSION ${major}.${minor}.${micro})
endif()
endif()

mark_as_advanced(FFmpeg_${component}_INCLUDE_DIR FFmpeg_${component}_LIBRARY)

if(FFmpeg_${component}_FOUND AND NOT TARGET FFmpeg::${component})
add_library(FFmpeg::${component} UNKNOWN IMPORTED)
set_target_properties(FFmpeg::${component} PROPERTIES
IMPORTED_LOCATION "${FFmpeg_${component}_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${FFmpeg_${component}_INCLUDE_DIR}"
INTERFACE_COMPILE_OPTIONS "${PC_FFmpeg_${component}_CFLAGS_OTHER}"
)

set(FFmpeg_INCLUDE_DIRS ${FFmpeg_INCLUDE_DIRS} ${FFmpeg_${component}_INCLUDE_DIR})
set(FFmpeg_LIBRARIES ${FFmpeg_LIBRARIES} ${FFmpeg_${component}_LIBRARY})
set(_FFmpeg_REQUIRED_VARS FFmpeg_${component}_INCLUDE_DIR FFmpeg_${component}_LIBRARY)
message(STATUS "Found FFmpeg component ${component}, version ${FFmpeg_${component}_VERSION}")
endif()
endforeach()

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(FFmpeg
FOUND_VAR FFmpeg_FOUND
REQUIRED_VARS
FFmpeg_LIBRARIES
FFmpeg_INCLUDE_DIRS
HANDLE_COMPONENTS
)

0 comments on commit c71a358

Please sign in to comment.