From 236d6244a0f44fbe0f50f16fb259a3817ce463c4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 11 Nov 2016 14:50:50 -0500 Subject: 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 --- Help/manual/cmake-toolchains.7.rst | 2 +- Help/variable/CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION.rst | 3 +++ Modules/Platform/Android/Determine-Compiler-NDK.cmake | 12 ++++++++++-- Modules/Platform/Android/Determine-Compiler-Standalone.cmake | 2 ++ Modules/Platform/Android/Determine-Compiler.cmake | 2 ++ Tests/RunCMake/Android/common.cmake | 9 ++++++++- 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Help/manual/cmake-toolchains.7.rst b/Help/manual/cmake-toolchains.7.rst index 74eab2d..64abe9a 100644 --- a/Help/manual/cmake-toolchains.7.rst +++ b/Help/manual/cmake-toolchains.7.rst @@ -387,7 +387,7 @@ Configure use of an Android NDK with the following variables: :variable:`CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION` 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` Set to specify which C++ standard library to use. If not specified, diff --git a/Help/variable/CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION.rst b/Help/variable/CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION.rst index dff7d64..5ae55d1 100644 --- a/Help/variable/CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION.rst +++ b/Help/variable/CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION.rst @@ -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 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. diff --git a/Modules/Platform/Android/Determine-Compiler-NDK.cmake b/Modules/Platform/Android/Determine-Compiler-NDK.cmake index 953bc85..a33935b 100644 --- a/Modules/Platform/Android/Determine-Compiler-NDK.cmake +++ b/Modules/Platform/Android/Determine-Compiler-NDK.cmake @@ -52,6 +52,7 @@ unset(_ANDROID_CONFIG_MK_PATTERNS) # Find the newest toolchain version matching the ABI. set(_ANDROID_TOOL_NAME "") set(_ANDROID_TOOL_VERS 0) +set(_ANDROID_TOOL_VERS_NDK "") set(_ANDROID_TOOL_SETUP_MK "") foreach(config_mk IN LISTS _ANDROID_CONFIG_MKS) # Check that the toolchain matches the ABI. @@ -62,18 +63,21 @@ foreach(config_mk IN LISTS _ANDROID_CONFIG_MKS) unset(_ANDROID_TOOL_ABIS) # 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_VERS "${CMAKE_MATCH_3}") + set(_ANDROID_CUR_VERS "${CMAKE_MATCH_4}") + set(_ANDROID_CUR_VERS_NDK "${CMAKE_MATCH_2}") if(_ANDROID_TOOL_VERS STREQUAL "") # already the latest possible elseif(_ANDROID_CUR_VERS STREQUAL "" OR _ANDROID_CUR_VERS VERSION_GREATER _ANDROID_TOOL_VERS) set(_ANDROID_TOOL_NAME "${_ANDROID_CUR_NAME}") 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}") endif() unset(_ANDROID_CUR_TOOL) unset(_ANDROID_CUR_VERS) + unset(_ANDROID_CUR_VERS_NDK) endif() endforeach() @@ -206,6 +210,8 @@ endif() # Help CMakeFindBinUtils locate things. 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_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}") @@ -231,6 +237,7 @@ endif() if(CMAKE_ANDROID_NDK_TOOLCHAIN_DEBUG) message(STATUS "_ANDROID_TOOL_NAME=${_ANDROID_TOOL_NAME}") 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_CLANG_NAME=${_ANDROID_TOOL_CLANG_NAME}") message(STATUS "_ANDROID_TOOL_CLANG_VERS=${_ANDROID_TOOL_CLANG_VERS}") @@ -239,6 +246,7 @@ endif() unset(_ANDROID_TOOL_NAME) unset(_ANDROID_TOOL_VERS) +unset(_ANDROID_TOOL_VERS_NDK) unset(_ANDROID_TOOL_PREFIX) unset(_ANDROID_TOOL_CLANG_NAME) unset(_ANDROID_TOOL_CLANG_VERS) diff --git a/Modules/Platform/Android/Determine-Compiler-Standalone.cmake b/Modules/Platform/Android/Determine-Compiler-Standalone.cmake index 6393105..9f07ab9 100644 --- a/Modules/Platform/Android/Determine-Compiler-Standalone.cmake +++ b/Modules/Platform/Android/Determine-Compiler-Standalone.cmake @@ -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_EXTERNAL_TOOLCHAIN "") endif() + +set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "") diff --git a/Modules/Platform/Android/Determine-Compiler.cmake b/Modules/Platform/Android/Determine-Compiler.cmake index 2fd2c4a..7ec703a 100644 --- a/Modules/Platform/Android/Determine-Compiler.cmake +++ b/Modules/Platform/Android/Determine-Compiler.cmake @@ -40,6 +40,7 @@ if(CMAKE_ANDROID_NDK) elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN) include(Platform/Android/Determine-Compiler-Standalone) else() + set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "") set(_ANDROID_TOOL_C_COMPILER "") set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "") 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. 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}_COMPILER_EXTERNAL_TOOLCHAIN \"${_ANDROID_TOOL_${lang}_COMPILER_EXTERNAL_TOOLCHAIN}\") set(CMAKE_${lang}_ANDROID_TOOLCHAIN_PREFIX \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_PREFIX}\") diff --git a/Tests/RunCMake/Android/common.cmake b/Tests/RunCMake/Android/common.cmake index d803c98..18c9797 100644 --- a/Tests/RunCMake/Android/common.cmake +++ b/Tests/RunCMake/Android/common.cmake @@ -22,8 +22,15 @@ string(APPEND CMAKE_CXX_FLAGS " -Werror -Wno-attributes") string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-no-undefined") 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) + 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() elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN) execute_process( -- cgit v0.12 From 0d3eb139e117582fe5a625c1c380bb30dbc6d31b Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 11 Nov 2016 15:22:43 -0500 Subject: Android: Add CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG variable The NDK provides prebuilt toolchain files in directories named for the host architecture. The NDK build system calls this `HOST_TAG`. Expose the value publicly for use by clients that need to pass it to external tools. Suggested-by: Ruslan Baratov --- Help/manual/cmake-variables.7.rst | 1 + Help/variable/CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG.rst | 6 ++++++ Modules/Platform/Android/Determine-Compiler-NDK.cmake | 1 + Modules/Platform/Android/Determine-Compiler-Standalone.cmake | 1 + Modules/Platform/Android/Determine-Compiler.cmake | 2 ++ Tests/RunCMake/Android/common.cmake | 8 ++++++++ 6 files changed, 19 insertions(+) create mode 100644 Help/variable/CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG.rst diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index b74f867..0b28c73 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -241,6 +241,7 @@ Variables that Control the Build /variable/CMAKE_ANDROID_NATIVE_LIB_DEPENDENCIES /variable/CMAKE_ANDROID_NATIVE_LIB_DIRECTORIES /variable/CMAKE_ANDROID_NDK + /variable/CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG /variable/CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION /variable/CMAKE_ANDROID_PROCESS_MAX /variable/CMAKE_ANDROID_PROGUARD diff --git a/Help/variable/CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG.rst b/Help/variable/CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG.rst new file mode 100644 index 0000000..207019a --- /dev/null +++ b/Help/variable/CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG.rst @@ -0,0 +1,6 @@ +CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG +------------------------------------ + +When :ref:`Cross Compiling for Android with the NDK`, this variable +provides the NDK's "host tag" used to construct the path to prebuilt +toolchains that run on the host. diff --git a/Modules/Platform/Android/Determine-Compiler-NDK.cmake b/Modules/Platform/Android/Determine-Compiler-NDK.cmake index a33935b..855ae86 100644 --- a/Modules/Platform/Android/Determine-Compiler-NDK.cmake +++ b/Modules/Platform/Android/Determine-Compiler-NDK.cmake @@ -210,6 +210,7 @@ endif() # Help CMakeFindBinUtils locate things. set(_CMAKE_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_PREFIX}") +set(_ANDROID_TOOL_NDK_TOOLCHAIN_HOST_TAG "${_ANDROID_HOST_DIR}") set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "${_ANDROID_TOOL_VERS_NDK}") set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "${_ANDROID_TOOL_VERS}") diff --git a/Modules/Platform/Android/Determine-Compiler-Standalone.cmake b/Modules/Platform/Android/Determine-Compiler-Standalone.cmake index 9f07ab9..d81e691 100644 --- a/Modules/Platform/Android/Determine-Compiler-Standalone.cmake +++ b/Modules/Platform/Android/Determine-Compiler-Standalone.cmake @@ -58,4 +58,5 @@ else() set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "") endif() +set(_ANDROID_TOOL_NDK_TOOLCHAIN_HOST_TAG "") set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "") diff --git a/Modules/Platform/Android/Determine-Compiler.cmake b/Modules/Platform/Android/Determine-Compiler.cmake index 7ec703a..162bc9d 100644 --- a/Modules/Platform/Android/Determine-Compiler.cmake +++ b/Modules/Platform/Android/Determine-Compiler.cmake @@ -40,6 +40,7 @@ if(CMAKE_ANDROID_NDK) elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN) include(Platform/Android/Determine-Compiler-Standalone) else() + set(_ANDROID_TOOL_NDK_TOOLCHAIN_HOST_TAG "") set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "") set(_ANDROID_TOOL_C_COMPILER "") set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "") @@ -62,6 +63,7 @@ macro(__android_determine_compiler lang) # Save the Android-specific information in CMake${lang}Compiler.cmake. set(CMAKE_${lang}_COMPILER_CUSTOM_CODE " +set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG \"${_ANDROID_TOOL_NDK_TOOLCHAIN_HOST_TAG}\") 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}_COMPILER_EXTERNAL_TOOLCHAIN \"${_ANDROID_TOOL_${lang}_COMPILER_EXTERNAL_TOOLCHAIN}\") diff --git a/Tests/RunCMake/Android/common.cmake b/Tests/RunCMake/Android/common.cmake index 18c9797..0afa78c 100644 --- a/Tests/RunCMake/Android/common.cmake +++ b/Tests/RunCMake/Android/common.cmake @@ -32,6 +32,14 @@ if(CMAKE_ANDROID_NDK) "which does not appear in CMAKE_C_COMPILER:\n" " ${CMAKE_C_COMPILER}") endif() + if(NOT CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG) + message(SEND_ERROR "CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG is not set!") + elseif(NOT "${CMAKE_C_COMPILER}" MATCHES "prebuilt/${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}/bin") + message(SEND_ERROR "CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG is\n" + " ${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}\n" + "which does not appear in CMAKE_C_COMPILER:\n" + " ${CMAKE_C_COMPILER}") + endif() elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN) execute_process( COMMAND ${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/clang --version -- cgit v0.12 From ea8eba0bbf8447dfc109236cc694b7c16b2b3827 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 14 Nov 2016 14:19:55 -0500 Subject: Android: Add CMAKE__ANDROID_TOOLCHAIN_MACHINE Expose the binutils' machine name (typically used as a prefix on the tool names) publicly. This is expected to match the `gcc -dumpmachine` value. Suggested-by: Ruslan Baratov --- Help/manual/cmake-variables.7.rst | 1 + Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_MACHINE.rst | 9 +++++++++ Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_PREFIX.rst | 3 ++- Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_SUFFIX.rst | 3 ++- Modules/Platform/Android/Determine-Compiler-NDK.cmake | 4 ++++ .../Android/Determine-Compiler-Standalone.cmake | 4 ++++ Modules/Platform/Android/Determine-Compiler.cmake | 3 +++ Tests/RunCMake/Android/common.cmake | 17 +++++++++++++++++ 8 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_MACHINE.rst diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 0b28c73..ab69303 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -351,6 +351,7 @@ Variables for Languages /variable/CMAKE_Fortran_MODDIR_FLAG /variable/CMAKE_Fortran_MODOUT_FLAG /variable/CMAKE_INTERNAL_PLATFORM_ABI + /variable/CMAKE_LANG_ANDROID_TOOLCHAIN_MACHINE /variable/CMAKE_LANG_ANDROID_TOOLCHAIN_PREFIX /variable/CMAKE_LANG_ANDROID_TOOLCHAIN_SUFFIX /variable/CMAKE_LANG_ARCHIVE_APPEND diff --git a/Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_MACHINE.rst b/Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_MACHINE.rst new file mode 100644 index 0000000..d336364 --- /dev/null +++ b/Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_MACHINE.rst @@ -0,0 +1,9 @@ +CMAKE__ANDROID_TOOLCHAIN_MACHINE +-------------------------------------- + +When :ref:`Cross Compiling for Android` this variable contains the +toolchain binutils machine name (e.g. ``gcc -dumpmachine``). The +binutils typically have a ``-`` prefix on their name. + +See also :variable:`CMAKE__ANDROID_TOOLCHAIN_PREFIX` +and :variable:`CMAKE__ANDROID_TOOLCHAIN_SUFFIX`. diff --git a/Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_PREFIX.rst b/Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_PREFIX.rst index b51422f..db04af3 100644 --- a/Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_PREFIX.rst +++ b/Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_PREFIX.rst @@ -4,7 +4,8 @@ CMAKE__ANDROID_TOOLCHAIN_PREFIX When :ref:`Cross Compiling for Android` this variable contains the absolute path prefixing the toolchain GNU compiler and its binutils. -See also :variable:`CMAKE__ANDROID_TOOLCHAIN_SUFFIX`. +See also :variable:`CMAKE__ANDROID_TOOLCHAIN_SUFFIX` +and :variable:`CMAKE__ANDROID_TOOLCHAIN_MACHINE`. For example, the path to the linker is:: diff --git a/Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_SUFFIX.rst b/Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_SUFFIX.rst index a4af640..159eb22 100644 --- a/Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_SUFFIX.rst +++ b/Help/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_SUFFIX.rst @@ -4,4 +4,5 @@ CMAKE__ANDROID_TOOLCHAIN_SUFFIX When :ref:`Cross Compiling for Android` this variable contains the host platform suffix of the toolchain GNU compiler and its binutils. -See also :variable:`CMAKE__ANDROID_TOOLCHAIN_PREFIX`. +See also :variable:`CMAKE__ANDROID_TOOLCHAIN_PREFIX` +and :variable:`CMAKE__ANDROID_TOOLCHAIN_MACHINE`. diff --git a/Modules/Platform/Android/Determine-Compiler-NDK.cmake b/Modules/Platform/Android/Determine-Compiler-NDK.cmake index 855ae86..d983dd6 100644 --- a/Modules/Platform/Android/Determine-Compiler-NDK.cmake +++ b/Modules/Platform/Android/Determine-Compiler-NDK.cmake @@ -213,10 +213,14 @@ set(_CMAKE_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_PREFIX}") set(_ANDROID_TOOL_NDK_TOOLCHAIN_HOST_TAG "${_ANDROID_HOST_DIR}") set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "${_ANDROID_TOOL_VERS_NDK}") +# _ANDROID_TOOL_PREFIX should now match `gcc -dumpmachine`. +string(REGEX REPLACE "-$" "" _ANDROID_TOOL_C_TOOLCHAIN_MACHINE "${_ANDROID_TOOL_PREFIX}") + 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_SUFFIX "${_ANDROID_HOST_EXT}") +set(_ANDROID_TOOL_CXX_TOOLCHAIN_MACHINE "${_ANDROID_TOOL_C_TOOLCHAIN_MACHINE}") set(_ANDROID_TOOL_CXX_TOOLCHAIN_VERSION "${_ANDROID_TOOL_C_TOOLCHAIN_VERSION}") set(_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_C_TOOLCHAIN_PREFIX}") set(_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX "${_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX}") diff --git a/Modules/Platform/Android/Determine-Compiler-Standalone.cmake b/Modules/Platform/Android/Determine-Compiler-Standalone.cmake index d81e691..4c1ac1f 100644 --- a/Modules/Platform/Android/Determine-Compiler-Standalone.cmake +++ b/Modules/Platform/Android/Determine-Compiler-Standalone.cmake @@ -22,6 +22,9 @@ endif() # Help CMakeFindBinUtils locate things. set(_CMAKE_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_PREFIX}") +# _ANDROID_TOOL_PREFIX should now match `gcc -dumpmachine`. +string(REGEX REPLACE "-$" "" _ANDROID_TOOL_C_TOOLCHAIN_MACHINE "${_ANDROID_TOOL_PREFIX}") + execute_process( COMMAND "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/${_ANDROID_TOOL_PREFIX}gcc${_ANDROID_HOST_EXT}" -dumpversion OUTPUT_VARIABLE _gcc_version @@ -42,6 +45,7 @@ endif() set(_ANDROID_TOOL_C_TOOLCHAIN_PREFIX "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/${_ANDROID_TOOL_PREFIX}") set(_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX "${_ANDROID_HOST_EXT}") +set(_ANDROID_TOOL_CXX_TOOLCHAIN_MACHINE "${_ANDROID_TOOL_C_TOOLCHAIN_MACHINE}") set(_ANDROID_TOOL_CXX_TOOLCHAIN_VERSION "${_ANDROID_TOOL_C_TOOLCHAIN_VERSION}") set(_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX "${_ANDROID_TOOL_C_TOOLCHAIN_PREFIX}") set(_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX "${_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX}") diff --git a/Modules/Platform/Android/Determine-Compiler.cmake b/Modules/Platform/Android/Determine-Compiler.cmake index 162bc9d..a03ebcc 100644 --- a/Modules/Platform/Android/Determine-Compiler.cmake +++ b/Modules/Platform/Android/Determine-Compiler.cmake @@ -43,11 +43,13 @@ else() set(_ANDROID_TOOL_NDK_TOOLCHAIN_HOST_TAG "") set(_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION "") set(_ANDROID_TOOL_C_COMPILER "") + set(_ANDROID_TOOL_C_TOOLCHAIN_MACHINE "") set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "") set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN "") set(_ANDROID_TOOL_C_TOOLCHAIN_PREFIX "") set(_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX "") set(_ANDROID_TOOL_CXX_COMPILER "") + set(_ANDROID_TOOL_CXX_TOOLCHAIN_MACHINE "") set(_ANDROID_TOOL_CXX_TOOLCHAIN_VERSION "") set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "") set(_ANDROID_TOOL_CXX_TOOLCHAIN_PREFIX "") @@ -65,6 +67,7 @@ macro(__android_determine_compiler lang) set(CMAKE_${lang}_COMPILER_CUSTOM_CODE " set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG \"${_ANDROID_TOOL_NDK_TOOLCHAIN_HOST_TAG}\") set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION \"${_ANDROID_TOOL_NDK_TOOLCHAIN_VERSION}\") +set(CMAKE_${lang}_ANDROID_TOOLCHAIN_MACHINE \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_MACHINE}\") 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}_ANDROID_TOOLCHAIN_PREFIX \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_PREFIX}\") diff --git a/Tests/RunCMake/Android/common.cmake b/Tests/RunCMake/Android/common.cmake index 0afa78c..bef2428 100644 --- a/Tests/RunCMake/Android/common.cmake +++ b/Tests/RunCMake/Android/common.cmake @@ -52,6 +52,23 @@ elseif(CMAKE_ANDROID_STANDALONE_TOOLCHAIN) endif() endif() +execute_process( + COMMAND "${CMAKE_C_ANDROID_TOOLCHAIN_PREFIX}gcc${CMAKE_C_ANDROID_TOOLCHAIN_SUFFIX}" -dumpmachine + OUTPUT_VARIABLE _out OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE _err + RESULT_VARIABLE _res + ) +if(NOT _res EQUAL 0) + message(SEND_ERROR "Failed to run 'gcc -dumpmachine':\n ${_res}") +endif() +if(NOT _out STREQUAL "${CMAKE_C_ANDROID_TOOLCHAIN_MACHINE}") + message(SEND_ERROR "'gcc -dumpmachine' produced:\n" + " ${_out}\n" + "which is not equal to CMAKE_C_ANDROID_TOOLCHAIN_MACHINE:\n" + " ${CMAKE_C_ANDROID_TOOLCHAIN_MACHINE}" + ) +endif() + if(CMAKE_ANDROID_STL_TYPE STREQUAL "none") add_definitions(-DSTL_NONE) elseif(CMAKE_ANDROID_STL_TYPE STREQUAL "system") -- cgit v0.12