vpx.cmake 7.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
############################################################################
# vpx.cmake
# 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
if(LINPHONE_BUILDER_PREBUILT_URL)
24 25 26 27 28
	set(VPX_FILENAME "vpx-v1.3.0-${LINPHONE_BUILDER_ARCHITECTURE}.zip")
	file(DOWNLOAD "${LINPHONE_BUILDER_PREBUILT_URL}/${VPX_FILENAME}" "${CMAKE_CURRENT_BINARY_DIR}/${VPX_FILENAME}" STATUS VPX_FILENAME_STATUS)
	list(GET VPX_FILENAME_STATUS 0 VPX_DOWNLOAD_STATUS)
	if(NOT VPX_DOWNLOAD_STATUS)
		set(VPX_PREBUILT 1)
29
	endif()
30 31
endif()

32 33 34
if(VPX_PREBUILT)
	lcb_url("${CMAKE_CURRENT_BINARY_DIR}/${VPX_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/libvpx")
38
else()
39 40
	lcb_url("http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.5.0.tar.bz2")
	lcb_url_hash("MD5=49e59dd184caa255886683facea56fca")
41
	lcb_external_source_paths("externals/libvpx" "external/libvpx")
42 43 44 45 46 47 48
	lcb_may_be_found_on_system(YES)
	lcb_ignore_warnings(YES)

	lcb_build_method("autotools")
	lcb_do_not_use_cmake_flags(YES)
	lcb_config_h_file("vpx_config.h")
	lcb_configure_options(
49
		"--enable-error-concealment"
50
		"--enable-multithread"
51 52 53 54 55 56 57 58 59
		"--enable-realtime-only"
		"--enable-spatial-resampling"
		"--enable-vp8"
		"--disable-vp9"
		"--enable-libs"
		"--disable-install-docs"
		"--disable-debug-libs"
		"--disable-examples"
		"--disable-unit-tests"
60
		"--disable-tools"
61 62
		"--as=yasm"
	)
63
	string(FIND "${CMAKE_C_COMPILER_LAUNCHER}" "ccache" CCACHE_ENABLED)
64
	if (NOT "${CCACHE_ENABLED}" STREQUAL "-1")
65
		lcb_configure_options("--enable-ccache")
66
	endif()
67

68
	set(USE_TARGET YES)
69
	if(WIN32)
70
		if(CMAKE_GENERATOR MATCHES "^Visual Studio")
71
			lcb_build_method("custom")
72
			lcb_build_in_source_tree(TRUE)
73 74
			string(REPLACE " " ";" GENERATOR_LIST "${CMAKE_GENERATOR}")
			list(GET GENERATOR_LIST 2 VS_VERSION)
75
			set(VPX_TARGET "x86-win32-vs${VS_VERSION}")
76 77 78
			execute_process(COMMAND "cmd.exe" "/c" "${CMAKE_CURRENT_SOURCE_DIR}/builders/vpx/windows_env.bat" "${VS_VERSION}"
				WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
			)
79 80 81
			file(READ "${CMAKE_CURRENT_BINARY_DIR}/windowsenv_path.txt" VPX_ENV_PATH_LIST)
			set(VPX_ENV_PATH "")
			foreach(P ${VPX_ENV_PATH_LIST})
82
				string(REGEX REPLACE "^([a-zA-Z]):(.*)$" "/\\1\\2" P ${P})
83
				string(REPLACE "\\" "/" P ${P})
84
				set(VPX_ENV_PATH "${VPX_ENV_PATH}:${P}")
85
			endforeach()
86 87 88 89 90 91
			set(VPX_ENV_PATH "${VPX_ENV_PATH}:${AUTOTOOLS_PROGRAM_PATH}")
			string(SUBSTRING ${VPX_ENV_PATH} 1 -1 VPX_ENV_PATH)
			string(STRIP ${VPX_ENV_PATH} VPX_ENV_PATH)
			file(READ "${CMAKE_CURRENT_BINARY_DIR}/windowsenv_include.txt" VPX_ENV_INCLUDE)
			file(READ "${CMAKE_CURRENT_BINARY_DIR}/windowsenv_lib.txt" VPX_ENV_LIB)
			file(READ "${CMAKE_CURRENT_BINARY_DIR}/windowsenv_libpath.txt" VPX_ENV_LIBPATH)
92
		else()
93
			set(VPX_TARGET "x86-win32-gcc")
94 95 96 97 98
		endif()
		set(EP_vpx_CONFIGURE_OPTIONS_STR "")
		foreach(OPTION ${EP_vpx_CONFIGURE_OPTIONS})
			set(EP_vpx_CONFIGURE_OPTIONS_STR "${EP_vpx_CONFIGURE_OPTIONS_STR} \"${OPTION}\"")
		endforeach()
99 100 101
		lcb_configure_command_source("${CMAKE_CURRENT_SOURCE_DIR}/builders/vpx/windows_configure.sh.cmake")
		lcb_build_command_source("${CMAKE_CURRENT_SOURCE_DIR}/builders/vpx/windows_build.sh.cmake")
		lcb_install_command_source("${CMAKE_CURRENT_SOURCE_DIR}/builders/vpx/windows_install.sh.cmake")
102
	elseif(APPLE)
103 104
		if(IOS)
			if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
105
				set(VPX_TARGET "arm64-darwin-gcc")
106
			elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7")
107
				set(VPX_TARGET "armv7-darwin-gcc")
108
			elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
109
				set(VPX_TARGET "x86_64-iphonesimulator-gcc")
110
			else()
111
				set(VPX_TARGET "x86-iphonesimulator-gcc")
112
			endif()
113
		else()
114
			if(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
115
				set(VPX_TARGET "x86_64-darwin10-gcc")
116
			else()
117
				set(VPX_TARGET "x86-darwin10-gcc")
118
			endif()
119 120 121
		endif()
		if(CMAKE_GENERATOR STREQUAL "Xcode")
			# It appears that the build occurs in the cmake directory instead of the Build/vpx one with Xcode, so these flags are needed for include files to be found...
122 123
			lcb_extra_cflags("-I${LINPHONE_BUILDER_WORK_DIR}/Build/vpx")
			lcb_extra_asflags("-I${LINPHONE_BUILDER_WORK_DIR}/Build/vpx")
124
		endif()
125
		lcb_linking_type("--enable-static" "--disable-shared" "--enable-pic")
126
	elseif(ANDROID)
127
		if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv5te")
128
			message(FATAL_ERROR "VPX cannot be built on arm.")
129
		elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a")
130
			set(VPX_TARGET "armv7-android-gcc")
131 132
		elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
			set(VPX_TARGET "arm64-android-gcc")
133 134
		elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
			set(VPX_TARGET "x86_64-android-gcc")
135
		else()
136
			set(VPX_TARGET "x86-android-gcc")
137
		endif()
138 139 140 141
		lcb_configure_options(
			"--sdk-path=${CMAKE_ANDROID_NDK}/"
			"--android_ndk_api=${ANDROID_NATIVE_API_LEVEL}"
		)
142
		lcb_linking_type("--enable-static" "--disable-shared" "--enable-pic")
143
	elseif(QNX)
144 145
		set(VPX_TARGET "armv7-qnx-gcc")
		lcb_configure_options(
146 147 148 149
			"--libc=${QNX_TARGET}/${ROOT_PATH_SUFFIX}"
			"--force-target=armv7-qnx-gcc"
			"--disable-runtime-cpu-detect"
		)
150
		list(REMOVE_ITEM EP_vpx_CONFIGURE_OPTIONS "--enable-multithread")
151
      else()
152
		lcb_use_c_compiler_for_assembler(NO)
153
		if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
154
			set(VPX_TARGET "armv7-linux-gcc")
155 156 157
	        elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
			#A bit hacky, but CMAKE_SYSTEM_PROCESSOR sometimes doesn't include abi version so assume `armv7` by default
			set(VPX_TARGET "armv7-linux-gcc")
158
		else()
159 160 161 162 163
			if(CMAKE_SIZEOF_VOID_P EQUAL 8)
				set(VPX_TARGET "x86_64-linux-gcc")
			else()
				set(VPX_TARGET "x86-linux-gcc")
			endif()
164
		endif()
165
		lcb_linking_type("--disable-static" "--enable-shared")
166
	endif()
167

168 169 170
	if(USE_TARGET)
		lcb_cross_compilation_options(
			"--prefix=${CMAKE_INSTALL_PREFIX}"
171
			"--libdir=${CMAKE_INSTALL_PREFIX}/lib"
172 173 174 175 176 177 178
			"--target=${VPX_TARGET}"
		)
	else()
		lcb_cross_compilation_options(
                	"--prefix=${CMAKE_INSTALL_PREFIX}"
        	)
	endif()
179 180 181
	if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "4.0")
		lcb_configure_options("--disable-avx512")
	endif()
182
	lcb_configure_env("CC=$CC_NO_LAUNCHER LD=$CC_NO_LAUNCHER ASFLAGS=$ASFLAGS CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS")
183 184 185
	# BUILD_ROOT is set by Xcode, but we still need the current build root.
	# See https://gitlab.linphone.org/BC/public/external/libvpx/blob/v1.7.0-linphone/build/make/Makefile
	lcb_make_options("BUILD_ROOT=.")
186
endif()