FindFFMpeg.cmake 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
############################################################################
# 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
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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
#
############################################################################
#
# - 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)

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

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
if(ANDROID)
	find_library(FFMPEG_LIBRARIES
		NAMES ffmpeg-linphone-${CMAKE_SYSTEM_PROCESSOR}
	)
else()
	find_library(LIBAVCODEC_LIBRARIES
		NAMES avcodec
		PATH_SUFFIXES bin lib
	)
	find_library(LIBAVUTIL_LIBRARIES
		NAMES avutil
		PATH_SUFFIXES bin lib
	)
	find_library(LIBSWSCALE_LIBRARIES
		NAMES swscale
		PATH_SUFFIXES bin lib
	)
endif()
72 73

set(FFMPEG_INCLUDE_DIRS ${LIBAVCODEC_INCLUDE_DIRS} ${LIBAVUTIL_INCLUDE_DIRS} ${LIBSWSCALE_INCLUDE_DIRS})
74 75 76
if(NOT ANDROID)
	set(FFMPEG_LIBRARIES ${LIBAVCODEC_LIBRARIES} ${LIBAVUTIL_LIBRARIES} ${LIBSWSCALE_LIBRARIES})
endif()
77 78 79 80 81 82 83
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})
84 85 86
	if(ANDROID)
		list(APPEND CMAKE_REQUIRED_LIBRARIES m)
	endif()
87 88 89
	if(MSVC)
		list(APPEND CMAKE_REQUIRED_DEFINITIONS -Dinline=__inline)
	endif()
90 91 92 93 94 95
	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;libavutil/frame.h" HAVE_FUN_av_frame_alloc)
	check_symbol_exists(av_frame_free "libavutil/avutil.h;libavutil/frame.h" HAVE_FUN_av_frame_free)
	check_symbol_exists(av_frame_unref "libavutil/avutil.h;libavutil/frame.h" HAVE_FUN_av_frame_unref)
96 97 98
	cmake_pop_check_state()
endif()

99 100 101 102 103
set(VARS FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES LIBAVCODEC_INCLUDE_DIRS LIBAVUTIL_INCLUDE_DIRS LIBSWSCALE_INCLUDE_DIRS)
if(NOT ANDROID)
	list(APPEND VARS LIBAVCODEC_LIBRARIES LIBAVUTIL_LIBRARIES LIBSWSCALE_LIBRARIES)
endif()

104
include(FindPackageHandleStandardArgs)
105
find_package_handle_standard_args(FFMpeg DEFAULT_MSG ${VARS})
106

107
mark_as_advanced(${VARS})