From 4e6c58d937564c6692a86a958ca75a0f1def582d Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 26 Jul 2019 11:04:41 -0400 Subject: Android: Select NDK host tag while determining system The host tag is tied to the host platform and does not depend on any specific language or compiler. --- Modules/Platform/Android-Determine.cmake | 28 ++++++++++++++++++ .../Platform/Android/Determine-Compiler-NDK.cmake | 33 +++------------------- .../Android/Determine-Compiler-Standalone.cmake | 1 - Modules/Platform/Android/Determine-Compiler.cmake | 2 -- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake index bb42eed..bc9c364 100644 --- a/Modules/Platform/Android-Determine.cmake +++ b/Modules/Platform/Android-Determine.cmake @@ -198,6 +198,33 @@ if(NOT CMAKE_SYSTEM_VERSION MATCHES "^[0-9]+$") message(FATAL_ERROR "Android: The API specified by CMAKE_SYSTEM_VERSION='${CMAKE_SYSTEM_VERSION}' is not an integer.") endif() +if(CMAKE_ANDROID_NDK) + # Identify the host platform. + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "darwin-x86_64") + else() + set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "darwin-x86") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "linux-x86_64") + else() + set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "linux-x86") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64") + set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "windows-x86_64") + else() + set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "windows") + endif() + else() + message(FATAL_ERROR "Android: Builds hosted on '${CMAKE_HOST_SYSTEM_NAME}' not supported.") + endif() +else() + set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG "") +endif() + # https://developer.android.com/ndk/guides/abis.html set(_ANDROID_ABI_arm64-v8a_PROC "aarch64") @@ -342,6 +369,7 @@ if(CMAKE_ANDROID_NDK) string(APPEND CMAKE_SYSTEM_CUSTOM_CODE "set(CMAKE_ANDROID_ARCH_HEADER_TRIPLE \"${CMAKE_ANDROID_ARCH_HEADER_TRIPLE}\")\n" "set(CMAKE_ANDROID_NDK_DEPRECATED_HEADERS \"${CMAKE_ANDROID_NDK_DEPRECATED_HEADERS}\")\n" + "set(CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG \"${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}\")\n" ) endif() diff --git a/Modules/Platform/Android/Determine-Compiler-NDK.cmake b/Modules/Platform/Android/Determine-Compiler-NDK.cmake index 5f2cc52..e5a7390 100644 --- a/Modules/Platform/Android/Determine-Compiler-NDK.cmake +++ b/Modules/Platform/Android/Determine-Compiler-NDK.cmake @@ -195,40 +195,16 @@ if(NOT _ANDROID_TOOL_PREFIX AND "${_ANDROID_TOOL_NAME}" MATCHES "^(.*-)[0-9.]+$" set(_ANDROID_TOOL_PREFIX "${CMAKE_MATCH_1}") endif() -# Identify the host platform. -if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") - set(_ANDROID_HOST_DIR "darwin-x86_64") - else() - set(_ANDROID_HOST_DIR "darwin-x86") - endif() -elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") - if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") - set(_ANDROID_HOST_DIR "linux-x86_64") - else() - set(_ANDROID_HOST_DIR "linux-x86") - endif() -elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64") - set(_ANDROID_HOST_DIR "windows-x86_64") - else() - set(_ANDROID_HOST_DIR "windows") - endif() -else() - message(FATAL_ERROR "Android: Builds hosted on '${CMAKE_HOST_SYSTEM_NAME}' not supported.") -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}") # _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_PREFIX "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_NAME}/prebuilt/${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}/bin/${_ANDROID_TOOL_PREFIX}") set(_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX "${_ANDROID_HOST_EXT}") set(_ANDROID_TOOL_CXX_TOOLCHAIN_MACHINE "${_ANDROID_TOOL_C_TOOLCHAIN_MACHINE}") @@ -238,9 +214,9 @@ set(_ANDROID_TOOL_CXX_TOOLCHAIN_SUFFIX "${_ANDROID_TOOL_C_TOOLCHAIN_SUFFIX}") if(_ANDROID_TOOL_CLANG_NAME) message(STATUS "Android: Selected Clang toolchain '${_ANDROID_TOOL_CLANG_NAME}' with GCC toolchain '${_ANDROID_TOOL_NAME}'") - set(_ANDROID_TOOL_C_COMPILER "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_LLVM_NAME}/prebuilt/${_ANDROID_HOST_DIR}/bin/clang${_ANDROID_HOST_EXT}") - set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN ${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_NAME}/prebuilt/${_ANDROID_HOST_DIR}) - set(_ANDROID_TOOL_CXX_COMPILER "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_LLVM_NAME}/prebuilt/${_ANDROID_HOST_DIR}/bin/clang++${_ANDROID_HOST_EXT}") + set(_ANDROID_TOOL_C_COMPILER "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_LLVM_NAME}/prebuilt/${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}/bin/clang${_ANDROID_HOST_EXT}") + set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN ${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_NAME}/prebuilt/${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}) + set(_ANDROID_TOOL_CXX_COMPILER "${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_LLVM_NAME}/prebuilt/${CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG}/bin/clang++${_ANDROID_HOST_EXT}") set(_ANDROID_TOOL_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN}") else() message(STATUS "Android: Selected GCC toolchain '${_ANDROID_TOOL_NAME}'") @@ -267,4 +243,3 @@ unset(_ANDROID_TOOL_PREFIX) unset(_ANDROID_TOOL_CLANG_NAME) unset(_ANDROID_TOOL_CLANG_VERS) unset(_ANDROID_TOOL_LLVM_NAME) -unset(_ANDROID_HOST_DIR) diff --git a/Modules/Platform/Android/Determine-Compiler-Standalone.cmake b/Modules/Platform/Android/Determine-Compiler-Standalone.cmake index 4c1ac1f..5095aff 100644 --- a/Modules/Platform/Android/Determine-Compiler-Standalone.cmake +++ b/Modules/Platform/Android/Determine-Compiler-Standalone.cmake @@ -62,5 +62,4 @@ 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 a03ebcc..5c6b97b 100644 --- a/Modules/Platform/Android/Determine-Compiler.cmake +++ b/Modules/Platform/Android/Determine-Compiler.cmake @@ -40,7 +40,6 @@ 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_MACHINE "") @@ -65,7 +64,6 @@ 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_MACHINE \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_MACHINE}\") set(CMAKE_${lang}_ANDROID_TOOLCHAIN_VERSION \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_VERSION}\") -- cgit v0.12