Android: Always set CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION
When this variable is not set by the user or toolchain file, set it to the default selected. This will be useful for client code that needs to pass the value to an external tool that needs to find the same toolchain in the NDK. Leave it empty for a standalone toolchain. Suggested-by: Ruslan Baratov <ruslan_baratov@yahoo.com>
This commit is contained in:
parent
5cfc2e926a
commit
236d6244a0
|
@ -387,7 +387,7 @@ Configure use of an Android NDK with the following variables:
|
||||||
|
|
||||||
:variable:`CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION`
|
:variable:`CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION`
|
||||||
Set to the version of the NDK toolchain to be selected as the compiler.
|
Set to the version of the NDK toolchain to be selected as the compiler.
|
||||||
If not specified, the latest available GCC toolchain will be used.
|
If not specified, the default will be the latest available GCC toolchain.
|
||||||
|
|
||||||
:variable:`CMAKE_ANDROID_STL_TYPE`
|
:variable:`CMAKE_ANDROID_STL_TYPE`
|
||||||
Set to specify which C++ standard library to use. If not specified,
|
Set to specify which C++ standard library to use. If not specified,
|
||||||
|
|
|
@ -11,3 +11,6 @@ as the compiler. The variable must be set to one of these forms:
|
||||||
|
|
||||||
A toolchain of the requested version will be selected automatically to
|
A toolchain of the requested version will be selected automatically to
|
||||||
match the ABI named in the :variable:`CMAKE_ANDROID_ARCH_ABI` variable.
|
match the ABI named in the :variable:`CMAKE_ANDROID_ARCH_ABI` variable.
|
||||||
|
|
||||||
|
If not specified, the default will be a value that selects the latest
|
||||||
|
available GCC toolchain.
|
||||||
|
|
|
@ -52,6 +52,7 @@ unset(_ANDROID_CONFIG_MK_PATTERNS)
|
||||||
# Find the newest toolchain version matching the ABI.
|
# Find the newest toolchain version matching the ABI.
|
||||||
set(_ANDROID_TOOL_NAME "")
|
set(_ANDROID_TOOL_NAME "")
|
||||||
set(_ANDROID_TOOL_VERS 0)
|
set(_ANDROID_TOOL_VERS 0)
|
||||||
|
set(_ANDROID_TOOL_VERS_NDK "")
|
||||||
set(_ANDROID_TOOL_SETUP_MK "")
|
set(_ANDROID_TOOL_SETUP_MK "")
|
||||||
foreach(config_mk IN LISTS _ANDROID_CONFIG_MKS)
|
foreach(config_mk IN LISTS _ANDROID_CONFIG_MKS)
|
||||||
# Check that the toolchain matches the ABI.
|
# Check that the toolchain matches the ABI.
|
||||||
|
@ -62,18 +63,21 @@ foreach(config_mk IN LISTS _ANDROID_CONFIG_MKS)
|
||||||
unset(_ANDROID_TOOL_ABIS)
|
unset(_ANDROID_TOOL_ABIS)
|
||||||
|
|
||||||
# Check the version.
|
# Check the version.
|
||||||
if("${config_mk}" MATCHES [[/([^/]+-(clang)?([0-9]\.[0-9]|))/config.mk$]])
|
if("${config_mk}" MATCHES [[/([^/]+-((clang)?([0-9]\.[0-9]|)))/config.mk$]])
|
||||||
set(_ANDROID_CUR_NAME "${CMAKE_MATCH_1}")
|
set(_ANDROID_CUR_NAME "${CMAKE_MATCH_1}")
|
||||||
set(_ANDROID_CUR_VERS "${CMAKE_MATCH_3}")
|
set(_ANDROID_CUR_VERS "${CMAKE_MATCH_4}")
|
||||||
|
set(_ANDROID_CUR_VERS_NDK "${CMAKE_MATCH_2}")
|
||||||
if(_ANDROID_TOOL_VERS STREQUAL "")
|
if(_ANDROID_TOOL_VERS STREQUAL "")
|
||||||
# already the latest possible
|
# already the latest possible
|
||||||
elseif(_ANDROID_CUR_VERS STREQUAL "" OR _ANDROID_CUR_VERS VERSION_GREATER _ANDROID_TOOL_VERS)
|
elseif(_ANDROID_CUR_VERS STREQUAL "" OR _ANDROID_CUR_VERS VERSION_GREATER _ANDROID_TOOL_VERS)
|
||||||
set(_ANDROID_TOOL_NAME "${_ANDROID_CUR_NAME}")
|
set(_ANDROID_TOOL_NAME "${_ANDROID_CUR_NAME}")
|
||||||
set(_ANDROID_TOOL_VERS "${_ANDROID_CUR_VERS}")
|
set(_ANDROID_TOOL_VERS "${_ANDROID_CUR_VERS}")
|
||||||
|
set(_ANDROID_TOOL_VERS_NDK "${_ANDROID_CUR_VERS_NDK}")
|
||||||
string(REPLACE "/config.mk" "/setup.mk" _ANDROID_TOOL_SETUP_MK "${config_mk}")
|
string(REPLACE "/config.mk" "/setup.mk" _ANDROID_TOOL_SETUP_MK "${config_mk}")
|
||||||
endif()
|
endif()
|
||||||
unset(_ANDROID_CUR_TOOL)
|
unset(_ANDROID_CUR_TOOL)
|
||||||
unset(_ANDROID_CUR_VERS)
|
unset(_ANDROID_CUR_VERS)
|
||||||
|
unset(_ANDROID_CUR_VERS_NDK)
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
@ -206,6 +210,8 @@ endif()
|
||||||
# Help CMakeFindBinUtils locate things.
|
# Help CMakeFindBinUtils locate things.
|
||||||
set(_CMAKE_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_PREFIX}")
|
set(_CMAKE_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_PREFIX}")
|
||||||
|
|
||||||
|
set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "${_ANDROID_TOOL_VERS_NDK}")
|
||||||
|
|
||||||
set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "${_ANDROID_TOOL_VERS}")
|
set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "${_ANDROID_TOOL_VERS}")
|
||||||
set(_ANDROID_TOOL_C_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_NAME}/prebuilt/${_ANDROID_HOST_DIR}/bin/${_ANDROID_TOOL_PREFIX}")
|
set(_ANDROID_TOOL_C_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_NAME}/prebuilt/${_ANDROID_HOST_DIR}/bin/${_ANDROID_TOOL_PREFIX}")
|
||||||
set(_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX "${_ANDROID_HOST_EXT}")
|
set(_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX "${_ANDROID_HOST_EXT}")
|
||||||
|
@ -231,6 +237,7 @@ endif()
|
||||||
if(CMAKE_ANDROID_NDK_TOOLCHAIN_DEBUG)
|
if(CMAKE_ANDROID_NDK_TOOLCHAIN_DEBUG)
|
||||||
message(STATUS "_ANDROID_TOOL_NAME=${_ANDROID_TOOL_NAME}")
|
message(STATUS "_ANDROID_TOOL_NAME=${_ANDROID_TOOL_NAME}")
|
||||||
message(STATUS "_ANDROID_TOOL_VERS=${_ANDROID_TOOL_VERS}")
|
message(STATUS "_ANDROID_TOOL_VERS=${_ANDROID_TOOL_VERS}")
|
||||||
|
message(STATUS "_ANDROID_TOOL_VERS_NDK=${_ANDROID_TOOL_VERS_NDK}")
|
||||||
message(STATUS "_ANDROID_TOOL_PREFIX=${_ANDROID_TOOL_PREFIX}")
|
message(STATUS "_ANDROID_TOOL_PREFIX=${_ANDROID_TOOL_PREFIX}")
|
||||||
message(STATUS "_ANDROID_TOOL_CLANG_NAME=${_ANDROID_TOOL_CLANG_NAME}")
|
message(STATUS "_ANDROID_TOOL_CLANG_NAME=${_ANDROID_TOOL_CLANG_NAME}")
|
||||||
message(STATUS "_ANDROID_TOOL_CLANG_VERS=${_ANDROID_TOOL_CLANG_VERS}")
|
message(STATUS "_ANDROID_TOOL_CLANG_VERS=${_ANDROID_TOOL_CLANG_VERS}")
|
||||||
|
@ -239,6 +246,7 @@ endif()
|
||||||
|
|
||||||
unset(_ANDROID_TOOL_NAME)
|
unset(_ANDROID_TOOL_NAME)
|
||||||
unset(_ANDROID_TOOL_VERS)
|
unset(_ANDROID_TOOL_VERS)
|
||||||
|
unset(_ANDROID_TOOL_VERS_NDK)
|
||||||
unset(_ANDROID_TOOL_PREFIX)
|
unset(_ANDROID_TOOL_PREFIX)
|
||||||
unset(_ANDROID_TOOL_CLANG_NAME)
|
unset(_ANDROID_TOOL_CLANG_NAME)
|
||||||
unset(_ANDROID_TOOL_CLANG_VERS)
|
unset(_ANDROID_TOOL_CLANG_VERS)
|
||||||
|
|
|
@ -57,3 +57,5 @@ else()
|
||||||
set(_ANDROID_TOOL_CXX_COMPILER "${_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX}g++${_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX}")
|
set(_ANDROID_TOOL_CXX_COMPILER "${_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX}g++${_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX}")
|
||||||
set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "")
|
set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "")
|
||||||
|
|
|
@ -40,6 +40,7 @@ if(CMAKE_ANDROID_NDK)
|
||||||
elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN)
|
elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN)
|
||||||
include(Platform/Android/Determine-Compiler-Standalone)
|
include(Platform/Android/Determine-Compiler-Standalone)
|
||||||
else()
|
else()
|
||||||
|
set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "")
|
||||||
set(_ANDROID_TOOL_C_COMPILER "")
|
set(_ANDROID_TOOL_C_COMPILER "")
|
||||||
set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "")
|
set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "")
|
||||||
set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN "")
|
set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN "")
|
||||||
|
@ -61,6 +62,7 @@ macro(__android_determine_compiler lang)
|
||||||
|
|
||||||
# Save the Android-specific information in CMake${lang}Compiler.cmake.
|
# Save the Android-specific information in CMake${lang}Compiler.cmake.
|
||||||
set(CMAKE_${lang}_COMPILER_CUSTOM_CODE "
|
set(CMAKE_${lang}_COMPILER_CUSTOM_CODE "
|
||||||
|
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION \"${_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION}\")
|
||||||
set(CMAKE_${lang}_ANDROID_TOOLCHAIN_VERSION \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_VERSION}\")
|
set(CMAKE_${lang}_ANDROID_TOOLCHAIN_VERSION \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_VERSION}\")
|
||||||
set(CMAKE_${lang}_COMPILER_EXTERNAL_TOOLCHAIN \"${_ANDROID_TOOL_${lang}_COMPILER_EXTERNAL_TOOLCHAIN}\")
|
set(CMAKE_${lang}_COMPILER_EXTERNAL_TOOLCHAIN \"${_ANDROID_TOOL_${lang}_COMPILER_EXTERNAL_TOOLCHAIN}\")
|
||||||
set(CMAKE_${lang}_ANDROID_TOOLCHAIN_PREFIX \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_PREFIX}\")
|
set(CMAKE_${lang}_ANDROID_TOOLCHAIN_PREFIX \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_PREFIX}\")
|
||||||
|
|
|
@ -22,8 +22,15 @@ string(APPEND CMAKE_CXX_FLAGS " -Werror -Wno-attributes")
|
||||||
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-no-undefined")
|
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-no-undefined")
|
||||||
|
|
||||||
if(CMAKE_ANDROID_NDK)
|
if(CMAKE_ANDROID_NDK)
|
||||||
if(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION MATCHES "clang")
|
if(NOT CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION)
|
||||||
|
message(SEND_ERROR "CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION is not set!")
|
||||||
|
elseif(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION MATCHES "^clang")
|
||||||
add_definitions(-DCOMPILER_IS_CLANG)
|
add_definitions(-DCOMPILER_IS_CLANG)
|
||||||
|
elseif(NOT "${CMAKE_C_COMPILER}" MATCHES "toolchains/[^/]+-${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}/prebuilt")
|
||||||
|
message(SEND_ERROR "CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION is\n"
|
||||||
|
" ${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}\n"
|
||||||
|
"which does not appear in CMAKE_C_COMPILER:\n"
|
||||||
|
" ${CMAKE_C_COMPILER}")
|
||||||
endif()
|
endif()
|
||||||
elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN)
|
elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN)
|
||||||
execute_process(
|
execute_process(
|
||||||
|
|
Loading…
Reference in New Issue