FindFFMpeg.cmake 3.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
############################################################################
# FindFFMpeg.txt
# Copyright (C) 2014  Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
############################################################################
#
# - Find the ffmpeg include file and library
#
#  FFMPEG_FOUND - system has ffmpeg
#  FFMPEG_INCLUDE_DIRS - the ffmpeg include directory
#  FFMPEG_LIBRARIES - The libraries needed to use ffmpeg

include(CMakePushCheckState)
include(CheckSymbolExists)

set(_FFMPEG_ROOT_PATHS
	${CMAKE_INSTALL_PREFIX}
)

find_path(LIBAVCODEC_INCLUDE_DIRS
	NAMES libavcodec/avcodec.h
	HINTS _FFMPEG_ROOT_PATHS
	PATH_SUFFIXES include
)
if(LIBAVCODEC_INCLUDE_DIRS)
	set(HAVE_LIBAVCODEC_AVCODEC_H 1)
endif()
find_path(LIBAVUTIL_INCLUDE_DIRS
	NAMES libavutil/avutil.h
	HINTS _FFMPEG_ROOT_PATHS
	PATH_SUFFIXES include
)
if(LIBAVUTIL_INCLUDE_DIRS)
	set(HAVE_LIBAVUTIL_AVUTIL_H 1)
endif()
find_path(LIBSWSCALE_INCLUDE_DIRS
	NAMES libswscale/swscale.h
	HINTS _FFMPEG_ROOT_PATHS
	PATH_SUFFIXES include
)
if(LIBSWSCALE_INCLUDE_DIRS)
	set(HAVE_LIBSWSCALE_SWSCALE_H 1)
endif()

find_library(LIBAVCODEC_LIBRARIES
	NAMES avcodec
	HINTS _FFMPEG_ROOT_PATHS
	PATH_SUFFIXES bin lib
)
find_library(LIBAVUTIL_LIBRARIES
	NAMES avutil
	HINTS _FFMPEG_ROOT_PATHS
	PATH_SUFFIXES bin lib
)
find_library(LIBSWSCALE_LIBRARIES
	NAMES swscale
	HINTS _FFMPEG_ROOT_PATHS
	PATH_SUFFIXES bin lib
)

set(FFMPEG_INCLUDE_DIRS ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
set(FFMPEG_LIBRARIES ${LIBAVCODEC_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES})
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
list(REMOVE_DUPLICATES FFMPEG_LIBRARIES)

if(FFMPEG_LIBRARIES)
	cmake_push_check_state(RESET)
	list(APPEND CMAKE_REQUIRED_INCLUDES ${FFMPEG_INCLUDE_DIRS})
	list(APPEND CMAKE_REQUIRED_LIBRARIES ${FFMPEG_LIBRARIES})
	if(MSVC)
		list(APPEND CMAKE_REQUIRED_DEFINITIONS -Dinline=__inline)
	endif()
	check_symbol_exists(avcodec_get_context_defaults3 libavcodec/avcodec.h HAVE_FUN_avcodec_get_context_defaults3)
	check_symbol_exists(avcodec_open2 libavcodec/avcodec.h HAVE_FUN_avcodec_open2)
	check_symbol_exists(avcodec_encode_video2 libavcodec/avcodec.h HAVE_FUN_avcodec_encode_video2)
	check_symbol_exists(av_frame_alloc libavutil/avutil.h HAVE_FUN_av_frame_alloc)
	check_symbol_exists(av_frame_free libavutil/avutil.h HAVE_FUN_av_frame_free)
	check_symbol_exists(av_frame_unref libavutil/avutil.h HAVE_FUN_av_frame_unref)
	cmake_pop_check_state()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFMpeg
	DEFAULT_MSG
	FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES
	LIBAVCODEC_INCLUDE_DIRS LIBAVUTIL_INCLUDE_DIRS LIBSWSCALE_INCLUDE_DIRS
	LIBAVCODEC_LIBRARIES LIBAVUTIL_LIBRARIES LIBSWSCALE_LIBRARIES
)

mark_as_advanced(FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES
	LIBAVCODEC_INCLUDE_DIRS LIBAVUTIL_INCLUDE_DIRS LIBSWSCALE_INCLUDE_DIRS
	LIBAVCODEC_LIBRARIES LIBAVUTIL_LIBRARIES LIBSWSCALE_LIBRARIES)