summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2019-09-18 15:19:33 +0200
committerJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2019-10-24 19:12:40 +0200
commit52a1476426ba20edef8b481047fc6a4e461577f9 (patch)
tree159a0699fa44ebdd452a1c59bcfa6236ec53ce70 /cmake
parent812a0e88ae7a381c4296dd78d875bd85fbd73922 (diff)
CMake: Add improvements for FindFFmpeg.cmake
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/FindFFmpeg.cmake128
1 files changed, 54 insertions, 74 deletions
diff --git a/cmake/modules/FindFFmpeg.cmake b/cmake/modules/FindFFmpeg.cmake
index 9d589e5ec8..94539a8180 100644
--- a/cmake/modules/FindFFmpeg.cmake
+++ b/cmake/modules/FindFFmpeg.cmake
@@ -55,6 +55,7 @@
# Copyright (c) 2008, Alexander Neundorf, <neundorf@kde.org>
# Copyright (c) 2011, Michael Jansen, <kde@michael-jansen.biz>
# Copyright (c) 2017, Alexander Drozdov, <adrozdoff@gmail.com>
+# Copyright (c) 2019, Jan Holthuis, <holthuis.jan@googlemail.com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
@@ -67,20 +68,6 @@ if (NOT FFmpeg_FIND_COMPONENTS)
endif ()
#
-### Macro: set_component_found
-#
-# Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present.
-#
-macro(set_component_found _component )
- if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
- # message(STATUS " - ${_component} found.")
- set(${_component}_FOUND TRUE)
- else ()
- # message(STATUS " - ${_component} not found.")
- endif ()
-endmacro()
-
-#
### Macro: find_component
#
# Checks for the given component by invoking pkgconfig and then looking up the libraries and
@@ -88,14 +75,12 @@ endmacro()
#
macro(find_component _component _pkgconfig _library _header)
- #if (NOT WIN32)
- # use pkg-config to get the directories and then use these values
- # in the FIND_PATH() and FIND_LIBRARY() calls
- find_package(PkgConfig)
- if (PKG_CONFIG_FOUND)
- pkg_check_modules(PC_${_component} REQUIRED ${_pkgconfig})
- endif ()
- #endif (NOT WIN32)
+ # use pkg-config to get the directories and then use these values
+ # in the FIND_PATH() and FIND_LIBRARY() calls
+ find_package(PkgConfig QUIET)
+ if (PkgConfig_FOUND)
+ pkg_check_modules(PC_${_component} QUIET ${_pkgconfig})
+ endif ()
find_path(${_component}_INCLUDE_DIRS ${_header}
HINTS
@@ -119,7 +104,12 @@ macro(find_component _component _pkgconfig _library _header)
set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.")
set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.")
- set_component_found(${_component})
+ if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS)
+ # message(STATUS " - ${_component} found.")
+ set(${_component}_FOUND TRUE)
+ else ()
+ # message(STATUS " - ${_component} not found.")
+ endif ()
mark_as_advanced(
${_component}_INCLUDE_DIRS
@@ -130,57 +120,52 @@ macro(find_component _component _pkgconfig _library _header)
endmacro()
-# Check for cached results. If there are skip the costly part.
-if (NOT FFMPEG_LIBRARIES)
-
- # Check for all possible component.
- find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
- find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
- find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
- find_component(AVUTIL libavutil avutil libavutil/avutil.h)
- find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
- find_component(SWSCALE libswscale swscale libswscale/swscale.h)
- find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
- find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
-
- # Check if the required components were found and add their stuff to the FFMPEG_* vars.
- foreach (_component ${FFmpeg_FIND_COMPONENTS})
- if (${_component}_FOUND)
- # message(STATUS "Required component ${_component} present.")
- set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES})
- set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
- list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
-
- string(TOLOWER ${_component} _lowerComponent)
- if (NOT TARGET FFmpeg::${_lowerComponent})
- add_library(FFmpeg::${_lowerComponent} INTERFACE IMPORTED)
- set_target_properties(FFmpeg::${_lowerComponent} PROPERTIES
- INTERFACE_COMPILE_OPTIONS "${${_component}_DEFINITIONS}"
- INTERFACE_INCLUDE_DIRECTORIES ${${_component}_INCLUDE_DIRS}
- INTERFACE_LINK_LIBRARIES "${${_component}_LIBRARIES}")
- endif()
-
- else ()
- # message(STATUS "Required component ${_component} missing.")
- endif ()
- endforeach ()
-
- # Build the include path with duplicates removed.
- if (FFMPEG_INCLUDE_DIRS)
- list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
- endif ()
+# Check for all possible component.
+find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h)
+find_component(AVFORMAT libavformat avformat libavformat/avformat.h)
+find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h)
+find_component(AVUTIL libavutil avutil libavutil/avutil.h)
+find_component(AVFILTER libavfilter avfilter libavfilter/avfilter.h)
+find_component(SWSCALE libswscale swscale libswscale/swscale.h)
+find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h)
+find_component(SWRESAMPLE libswresample swresample libswresample/swresample.h)
- # cache the vars.
- set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
- set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
- set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
+# Check if the required components were found and add their stuff to the FFMPEG_* vars.
+foreach (_component ${FFmpeg_FIND_COMPONENTS})
+ if (${_component}_FOUND)
+ # message(STATUS "Required component ${_component} present.")
+ set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES})
+ set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS})
+ list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS})
+
+ string(TOLOWER ${_component} _lowerComponent)
+ if (NOT TARGET FFmpeg::${_lowerComponent})
+ add_library(FFmpeg::${_lowerComponent} INTERFACE IMPORTED)
+ set_target_properties(FFmpeg::${_lowerComponent} PROPERTIES
+ INTERFACE_COMPILE_OPTIONS "${${_component}_DEFINITIONS}"
+ INTERFACE_INCLUDE_DIRECTORIES ${${_component}_INCLUDE_DIRS}
+ INTERFACE_LINK_LIBRARIES "${${_component}_LIBRARIES}")
+ endif()
- mark_as_advanced(FFMPEG_INCLUDE_DIRS
- FFMPEG_LIBRARIES
- FFMPEG_DEFINITIONS)
+ else ()
+ # message(STATUS "Required component ${_component} missing.")
+ endif ()
+endforeach ()
+# Build the include path with duplicates removed.
+if (FFMPEG_INCLUDE_DIRS)
+ list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
endif ()
+# cache the vars.
+set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE)
+set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE)
+set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE)
+
+mark_as_advanced(FFMPEG_INCLUDE_DIRS
+ FFMPEG_LIBRARIES
+ FFMPEG_DEFINITIONS)
+
if (NOT TARGET FFmpeg::FFmpeg)
add_library(FFmpeg::FFmpeg INTERFACE IMPORTED)
set_target_properties(FFmpeg::FFmpeg PROPERTIES
@@ -189,11 +174,6 @@ if (NOT TARGET FFmpeg::FFmpeg)
INTERFACE_LINK_LIBRARIES "${FFMPEG_LIBRARIES}")
endif()
-# Now set the noncached _FOUND vars for the components.
-foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
- set_component_found(${_component})
-endforeach ()
-
# Compile the list of required vars
set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
foreach (_component ${FFmpeg_FIND_COMPONENTS})