-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
230aece
commit c71a358
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |