toolchain-android.cmake 2.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
############################################################################
# toolchain-android.cmake
# Copyright (C) 2016  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
set(CMAKE_ANDROID_NDK "$ENV{ANDROID_NDK_HOME}")
if(NOT CMAKE_ANDROID_NDK)
	find_program(ANDROID_NDK_BUILD_PROGRAM ndk-build)
	if(NOT ANDROID_NDK_BUILD_PROGRAM)
		message(FATAL_ERROR "Cannot find 'ndk-build', make sure you installed the NDK and added it to your PATH")
	endif()
	get_filename_component(CMAKE_ANDROID_NDK "${ANDROID_NDK_BUILD_PROGRAM}" DIRECTORY)
30
endif()
31 32

file(READ "${CMAKE_ANDROID_NDK}/source.properties" SOURCE_PROPERTIES_CONTENT)
33
string(REGEX MATCH "Pkg\\.Revision = ([0-9]+)\\.([0-9]+)\\." NDK_VERSION_MATCH "${SOURCE_PROPERTIES_CONTENT}")
34
set(CMAKE_ANDROID_NDK_VERSION ${CMAKE_MATCH_1})
35
set(CMAKE_ANDROID_NDK_VERSION_MINOR ${CMAKE_MATCH_2})
36

37
if(ENABLE_AAUDIO)
38
	set(ANDROID_NATIVE_API_LEVEL "android-28")
39
else()
40 41 42 43 44 45
	if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS 19)
		set(ANDROID_NATIVE_API_LEVEL "android-17")
	else()
		# Starting with NDK 19, API 17 no longer exists
		set(ANDROID_NATIVE_API_LEVEL "android-21")
	endif()
46
endif()
47 48
set(ANDROID_CPP_FEATURES "rtti exceptions")
set(ANDROID_STL "c++_shared")
49

50
include("${CMAKE_ANDROID_NDK}/build/cmake/android.toolchain.cmake")
51

52 53
if(CMAKE_ANDROID_NDK_VERSION VERSION_LESS 19)
	set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}" "${ANDROID_SYSTEM_LIBRARY_PATH}" "${CMAKE_INSTALL_PREFIX}")
54
else()
55 56 57 58 59 60
	if(CMAKE_ANDROID_NDK_VERSION VERSION_EQUAL 19)
		# NDK 19b needs this, but not NDK 19
		if(CMAKE_ANDROID_NDK_VERSION_MINOR GREATER_EQUAL 1)
			set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}" "${ANDROID_SYSTEM_LIBRARY_PATH}" "${CMAKE_INSTALL_PREFIX}")
		endif()
	else()
61 62
		set(CMAKE_FIND_ROOT_PATH "${CMAKE_SYSROOT}" "${ANDROID_SYSTEM_LIBRARY_PATH}" "${CMAKE_INSTALL_PREFIX}")
	endif()
63
endif()
64

65 66 67 68
set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os -g -DNDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -g -DNDEBUG")