ffmpeg.cmake 5.58 KB
Newer Older
1 2
############################################################################
# ffmpeg.cmake
3
# Copyright (C) 2014-2018  Belledonne Communications, Grenoble France
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#
############################################################################
#
# 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
if(LINPHONE_BUILDER_PREBUILT_URL)
24 25 26 27 28
	set(FFMPEG_FILENAME "ffmpeg-0.10.2-${LINPHONE_BUILDER_ARCHITECTURE}.zip")
	file(DOWNLOAD "${LINPHONE_BUILDER_PREBUILT_URL}/${FFMPEG_FILENAME}" "${CMAKE_CURRENT_BINARY_DIR}/${FFMPEG_FILENAME}" STATUS FFMPEG_FILENAME_STATUS)
	list(GET FFMPEG_FILENAME_STATUS 0 FFMPEG_DOWNLOAD_STATUS)
	if(NOT FFMPEG_DOWNLOAD_STATUS)
		set(FFMPEG_PREBUILT 1)
29
	endif()
30 31
endif()

32 33 34
if(FFMPEG_PREBUILT)
	lcb_url("${CMAKE_CURRENT_BINARY_DIR}/${FFMPEG_FILENAME}")
	lcb_build_method("prebuilt")
35 36
elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
	# Use prebuilt library in the source tree for Windows 10
37
	lcb_external_source_paths("build/ffmpeg")
38 39 40 41 42
else()
	if(WIN32)
		set(EP_ffmpeg_PATCH_OPTIONS "--binary")
	endif()

43
	lcb_git_repository("https://gitlab.linphone.org/BC/public/external/ffmpeg.git")
44 45
	lcb_git_tag_latest("bc")
	lcb_git_tag("51aa587f7ddac63c831d73eb360e246765a2675f")
46
	lcb_external_source_paths("externals/ffmpeg" "external/ffmpeg")
47 48 49 50
	lcb_may_be_found_on_system(YES)
	lcb_ignore_warnings(YES)
	lcb_build_method("autotools")
	lcb_configure_options(
51
		"--disable-doc"
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
		"--disable-zlib"
		"--disable-bzlib"
		"--disable-ffplay"
		"--disable-ffprobe"
		"--disable-ffserver"
		"--disable-avdevice"
		"--disable-avfilter"
		"--disable-network"
		"--disable-avformat"
		"--disable-everything"
		"--enable-decoder=mjpeg"
		"--enable-encoder=mjpeg"
		# Disable video acceleration support for compatibility with older Mac OS X versions (vda, vaapi, vdpau).
		"--disable-vda"
		"--disable-vaapi"
		"--disable-vdpau"
68 69 70 71 72 73
		"--ar=\$AR"
		"--cc=\$CC"
		"--nm=\$NM"
		"--extra-cflags=\$CFLAGS -w"
		"--extra-cxxflags=\$CXXFLAGS"
		"--extra-ldflags=\$LDFLAGS"
74
	)
75
	if(ENABLE_H263 OR IOS)
76
		lcb_configure_options(
77 78 79 80
			"--enable-decoder=h263"
			"--enable-encoder=h263"
		)
	endif()
81
	if(ENABLE_H263P OR IOS)
82
		lcb_configure_options("--enable-encoder=h263p")
83
	endif()
84
	if(ENABLE_MPEG4 OR IOS)
85
		lcb_configure_options(
86 87 88 89
			"--enable-decoder=mpeg4"
			"--enable-encoder=mpeg4"
		)
	endif()
90 91
	lcb_linking_type("--disable-static" "--enable-shared")
	set(FFMPEG_ARCH "${CMAKE_SYSTEM_PROCESSOR}")
Ghislain MARY's avatar
Ghislain MARY committed
92

93
	if(WIN32)
94 95 96 97 98
		set(FFMPEG_TARGET_OS "mingw32")
		set(FFMPEG_ARCH "i386")
		lcb_extra_cflags("-include windows.h")
		lcb_extra_ldflags("-static-libgcc")
		lcb_configure_options("--enable-runtime-cpudetect")
Ghislain MARY's avatar
Ghislain MARY committed
99
	else()
100
		if(APPLE)
101
			set(FFMPEG_TARGET_OS "darwin")
102
			if(IOS)
103
				lcb_configure_options(
104
					"--enable-decoder=h264"
105
					"--disable-iconv"
106
					"--disable-mmx"
107 108
					"--enable-cross-compile"
					"--cross-prefix=${SDK_BIN_PATH}/"
Ghislain MARY's avatar
Ghislain MARY committed
109
					"--sysroot=${CMAKE_OSX_SYSROOT}"
110
				)
111
				lcb_make_options("RANLIB=\"\$RANLIB\"")
112
				if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
113
					set(FFMPEG_ARCH "arm64")
114
				else()
115
					set(FFMPEG_ARCH "${CMAKE_SYSTEM_PROCESSOR}")
116 117
				endif()
				if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7")
118
					lcb_configure_options("--enable-neon" "--cpu=cortex-a8" "--disable-armv5te" "--enable-armv6" "--enable-armv6t2")
119 120
				endif()
			else()
121
				lcb_configure_options(
122 123 124
					"--enable-runtime-cpudetect"
					"--sysroot=${CMAKE_OSX_SYSROOT}"
				)
125
			endif()
126
		elseif(ANDROID)
127
			get_filename_component(TOOLCHAIN_PATH "${CMAKE_LINKER}" DIRECTORY)
128
			lcb_configure_options(
129 130
				"--enable-decoder=h264"
				"--disable-iconv"
131
				"--disable-mmx"
132
				"--enable-cross-compile"
133
				"--cross-prefix=${TOOLCHAIN_PATH}/"
134 135
				"--sysroot=${CMAKE_SYSROOT}"
			)
136 137 138
			set(FFMPEG_TARGET_OS "linux")
			set(FFMPEG_ARCH "${CMAKE_SYSTEM_PROCESSOR}")
			lcb_make_options("RANLIB=\"\$RANLIB\"")
139
			if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a")
140
				lcb_configure_options("--enable-neon" "--cpu=cortex-a8" "--disable-armv5te" "--enable-armv6" "--enable-armv6t2")
141
			else()
142
				lcb_configure_options("--disable-mmx" "--disable-sse2" "--disable-ssse3" "--disable-asm")
143
			endif()
144
			if(CMAKE_C_COMPILER_TARGET) # When building with clang
145 146
				lcb_configure_options("--extra-cflags=--target=${CMAKE_C_COMPILER_TARGET} --gcc-toolchain=${_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN}")
				lcb_configure_options("--extra-ldflags=--target=${CMAKE_C_COMPILER_TARGET} --gcc-toolchain=${_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN}")
147
			endif()
148
		else()
149 150
			set(FFMPEG_TARGET_OS "linux")
			lcb_configure_options("--enable-runtime-cpudetect")
151
			if(CMAKE_SYSTEM_PROCESSOR MATCHES "armv7")
152 153
				lcb_configure_options("--cpu=cortex-a8" 
						"--enable-fft")
154 155 156
				lcb_extra_cflags("-mfpu=neon")
				lcb_extra_cxxflags("-mfpu=neon")
			endif()
157
		endif()
158
		lcb_configure_options("--cc=$CC")
Ghislain MARY's avatar
Ghislain MARY committed
159
	endif()
160

161
	lcb_cross_compilation_options(
162
		"--prefix=${CMAKE_INSTALL_PREFIX}"
163 164
		"--arch=${FFMPEG_ARCH}"
		"--target-os=${FFMPEG_TARGET_OS}"
165
	)
166

167
	if(ENABLE_X264)
168
		lcb_configure_options("--enable-decoder=h264")
169
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
170
endif()