diff options
author | Brad King <brad.king@kitware.com> | 2020-12-02 13:21:12 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-12-02 13:21:12 (GMT) |
commit | bdfa5ac7f6cfc961665064f1b7a1395cfd0b2281 (patch) | |
tree | 9f9c8f4ef0db863fb6adc0ae70891477d66d1cdb /Modules/Platform | |
parent | f7ff0d34f0750387f5c56483ab6ba3fb4825b62d (diff) | |
parent | 628d7ef67258f67e0b4086905011d90727d8b9a1 (diff) | |
download | CMake-bdfa5ac7f6cfc961665064f1b7a1395cfd0b2281.zip CMake-bdfa5ac7f6cfc961665064f1b7a1395cfd0b2281.tar.gz CMake-bdfa5ac7f6cfc961665064f1b7a1395cfd0b2281.tar.bz2 |
Merge branch 'master' into llvm-rc-preprocess-as-c
Diffstat (limited to 'Modules/Platform')
22 files changed, 323 insertions, 94 deletions
diff --git a/Modules/Platform/Android-Clang.cmake b/Modules/Platform/Android-Clang.cmake index 160eada..3a279ca 100644 --- a/Modules/Platform/Android-Clang.cmake +++ b/Modules/Platform/Android-Clang.cmake @@ -7,6 +7,23 @@ if(__ANDROID_COMPILER_CLANG) endif() set(__ANDROID_COMPILER_CLANG 1) +# Include the NDK hook. +# It can be used by NDK to inject necessary fixes for an earlier cmake. +if(CMAKE_ANDROID_NDK) + include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/pre/Android-Clang.cmake OPTIONAL) +endif() + +# Load flags from NDK. This file may provides the following variables: +# _ANDROID_NDK_INIT_CFLAGS +# _ANDROID_NDK_INIT_CFLAGS_DEBUG +# _ANDROID_NDK_INIT_CFLAGS_RELEASE +# _ANDROID_NDK_INIT_LDFLAGS +# _ANDROID_NDK_INIT_LDFLAGS_EXE +if(CMAKE_ANDROID_NDK) + include(${CMAKE_ANDROID_NDK}/build/cmake/flags.cmake OPTIONAL + RESULT_VARIABLE _INCLUDED_FLAGS) +endif() + # Support for NVIDIA Nsight Tegra Visual Studio Edition was previously # implemented in the CMake VS IDE generators. Avoid interfering with # that functionality for now. Later we may try to integrate this. @@ -34,20 +51,29 @@ endif() include(Platform/Android-Common) -# The NDK toolchain configuration files at: -# -# <ndk>/[build/core/]toolchains/*-clang*/setup.mk -# -# contain logic to set LLVM_TRIPLE for Clang-based toolchains for each target. -# We need to produce the same target here to produce compatible binaries. -include(Platform/Android/abi-${CMAKE_ANDROID_ARCH_ABI}-Clang) +if(_INCLUDED_FLAGS) + # NDK provides the flags. + set(_ANDROID_ABI_INIT_CFLAGS "${_ANDROID_NDK_INIT_CFLAGS}") + set(_ANDROID_ABI_INIT_CFLAGS_DEBUG "${_ANDROID_NDK_INIT_CFLAGS_DEBUG}") + set(_ANDROID_ABI_INIT_CFLAGS_RELEASE "${_ANDROID_NDK_INIT_CFLAGS_RELEASE}") + set(_ANDROID_ABI_INIT_LDFLAGS "${_ANDROID_NDK_INIT_LDFLAGS}") + set(_ANDROID_ABI_INIT_EXE_LDFLAGS "${_ANDROID_NDK_INIT_LDFLAGS_EXE}") +else() + # The NDK toolchain configuration files at: + # + # <ndk>/[build/core/]toolchains/*-clang*/setup.mk + # + # contain logic to set LLVM_TRIPLE for Clang-based toolchains for each target. + # We need to produce the same target here to produce compatible binaries. + include(Platform/Android/abi-${CMAKE_ANDROID_ARCH_ABI}-Clang) +endif() macro(__android_compiler_clang lang) if(NOT "x${lang}" STREQUAL "xASM") __android_compiler_common(${lang}) endif() if(NOT CMAKE_${lang}_COMPILER_TARGET) - set(CMAKE_${lang}_COMPILER_TARGET "${_ANDROID_ABI_CLANG_TARGET}") + set(CMAKE_${lang}_COMPILER_TARGET "${CMAKE_ANDROID_ARCH_LLVM_TRIPLE}") if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED) string(APPEND CMAKE_${lang}_COMPILER_TARGET "${CMAKE_SYSTEM_VERSION}") endif() @@ -57,3 +83,9 @@ macro(__android_compiler_clang lang) set(_ANDROID_STL_NOSTDLIBXX 1) endif() endmacro() + +# Include the NDK hook. +# It can be used by NDK to inject necessary fixes for an earlier cmake. +if(CMAKE_ANDROID_NDK) + include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/post/Android-Clang.cmake OPTIONAL) +endif() diff --git a/Modules/Platform/Android-Common.cmake b/Modules/Platform/Android-Common.cmake index 581fde4..39da933 100644 --- a/Modules/Platform/Android-Common.cmake +++ b/Modules/Platform/Android-Common.cmake @@ -53,6 +53,12 @@ if(CMAKE_ANDROID_STL_TYPE) set(_ANDROID_STL_RTTI 0) macro(__android_stl lang) string(APPEND CMAKE_${lang}_FLAGS_INIT " -stdlib=libstdc++") + if(_ANDROID_STL_EXCEPTIONS OR _ANDROID_STL_RTTI) + string(APPEND CMAKE_${lang}_STANDARD_LIBRARIES " -lc++abi") + if(CMAKE_SYSTEM_VERSION LESS 21) + list(APPEND CMAKE_${lang}_STANDARD_LIBRARIES "-landroid_support") + endif() + endif() endmacro() elseif(CMAKE_ANDROID_STL_TYPE STREQUAL "c++_static") set(_ANDROID_STL_EXCEPTIONS 1) @@ -81,6 +87,12 @@ if(CMAKE_ANDROID_STL_TYPE) "Android: STL '${CMAKE_ANDROID_STL_TYPE}' not supported by this NDK." ) endif() + if(DEFINED CMAKE_ANDROID_RTTI) + set(_ANDROID_STL_RTTI ${CMAKE_ANDROID_RTTI}) + endif() + if(DEFINED CMAKE_ANDROID_EXCEPTIONS) + set(_ANDROID_STL_EXCEPTIONS ${CMAKE_ANDROID_EXCEPTIONS}) + endif() elseif(CMAKE_ANDROID_NDK) macro(__android_stl_inc lang dir req) diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake index bc66ba1..c279086 100644 --- a/Modules/Platform/Android-Determine.cmake +++ b/Modules/Platform/Android-Determine.cmake @@ -5,6 +5,12 @@ # This module detects platform-wide information about the Android target # in order to store it in "CMakeSystem.cmake". +# Include the NDK hook. +# It can be used by NDK to inject necessary fixes for an earlier cmake. +if(CMAKE_ANDROID_NDK) + include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/pre/Android-Determine.cmake OPTIONAL) +endif() + # Support for NVIDIA Nsight Tegra Visual Studio Edition was previously # implemented in the CMake VS IDE generators. Avoid interfering with # that functionality for now. @@ -209,6 +215,14 @@ if(CMAKE_ANDROID_NDK) # NDK >= 18 has abis.cmake. It provides: # NDK_KNOWN_DEVICE_ABI32S # NDK_KNOWN_DEVICE_ABI64S + # NDK >= 23 also provides: + # NDK_KNOWN_DEVICE_ABIS + # NDK_ABI_<abi>_PROC + # NDK_ABI_<abi>_ARCH + # NDK_ABI_<abi>_TRIPLE + # NDK_ABI_<abi>_LLVM_TRIPLE + # NDK_PROC_<processor>_ABI + # NDK_ARCH_<arch>_ABI include("${CMAKE_ANDROID_NDK}/build/cmake/abis.cmake" OPTIONAL RESULT_VARIABLE _INCLUDED_ABIS) endif() @@ -247,60 +261,75 @@ else() endif() if(_INCLUDED_ABIS) - set(_ANDROID_KNOWN_ABIS ${NDK_KNOWN_DEVICE_ABI32S} ${NDK_KNOWN_DEVICE_ABI64S}) + if(NDK_KNOWN_DEVICE_ABIS) + set(_ANDROID_KNOWN_ABIS ${NDK_KNOWN_DEVICE_ABIS}) + else() + set(_ANDROID_KNOWN_ABIS ${NDK_KNOWN_DEVICE_ABI32S} ${NDK_KNOWN_DEVICE_ABI64S}) + endif() endif() -# https://developer.android.com/ndk/guides/abis.html - -set(_ANDROID_ABI_arm64-v8a_PROC "aarch64") -set(_ANDROID_ABI_arm64-v8a_ARCH "arm64") -set(_ANDROID_ABI_arm64-v8a_TRIPLE "aarch64-linux-android") -set(_ANDROID_ABI_armeabi-v7a_PROC "armv7-a") -set(_ANDROID_ABI_armeabi-v7a_ARCH "arm") -set(_ANDROID_ABI_armeabi-v7a_TRIPLE "arm-linux-androideabi") -set(_ANDROID_ABI_armeabi-v6_PROC "armv6") -set(_ANDROID_ABI_armeabi-v6_ARCH "arm") -set(_ANDROID_ABI_armeabi-v6_TRIPLE "arm-linux-androideabi") -set(_ANDROID_ABI_armeabi_PROC "armv5te") -set(_ANDROID_ABI_armeabi_ARCH "arm") -set(_ANDROID_ABI_armeabi_TRIPLE "arm-linux-androideabi") -set(_ANDROID_ABI_mips_PROC "mips") -set(_ANDROID_ABI_mips_ARCH "mips") -set(_ANDROID_ABI_mips_TRIPLE "mipsel-linux-android") -set(_ANDROID_ABI_mips64_PROC "mips64") -set(_ANDROID_ABI_mips64_ARCH "mips64") -set(_ANDROID_ABI_mips64_TRIPLE "mips64el-linux-android") -set(_ANDROID_ABI_x86_PROC "i686") -set(_ANDROID_ABI_x86_ARCH "x86") -set(_ANDROID_ABI_x86_TRIPLE "i686-linux-android") -set(_ANDROID_ABI_x86_64_PROC "x86_64") -set(_ANDROID_ABI_x86_64_ARCH "x86_64") -set(_ANDROID_ABI_x86_64_TRIPLE "x86_64-linux-android") - -set(_ANDROID_PROC_aarch64_ARCH_ABI "arm64-v8a") -set(_ANDROID_PROC_armv7-a_ARCH_ABI "armeabi-v7a") -set(_ANDROID_PROC_armv6_ARCH_ABI "armeabi-v6") -set(_ANDROID_PROC_armv5te_ARCH_ABI "armeabi") -set(_ANDROID_PROC_i686_ARCH_ABI "x86") -set(_ANDROID_PROC_mips_ARCH_ABI "mips") -set(_ANDROID_PROC_mips64_ARCH_ABI "mips64") -set(_ANDROID_PROC_x86_64_ARCH_ABI "x86_64") - -set(_ANDROID_ARCH_arm64_ABI "arm64-v8a") -set(_ANDROID_ARCH_arm_ABI "armeabi") -set(_ANDROID_ARCH_mips_ABI "mips") -set(_ANDROID_ARCH_mips64_ABI "mips64") -set(_ANDROID_ARCH_x86_ABI "x86") -set(_ANDROID_ARCH_x86_64_ABI "x86_64") +if(NOT DEFINED NDK_KNOWN_DEVICE_ABIS) + # The NDK is not new enough to provide ABI information. + # https://developer.android.com/ndk/guides/abis.html + + set(NDK_ABI_arm64-v8a_PROC "aarch64") + set(NDK_ABI_arm64-v8a_ARCH "arm64") + set(NDK_ABI_arm64-v8a_TRIPLE "aarch64-linux-android") + set(NDK_ABI_arm64-v8a_LLVM_TRIPLE "aarch64-none-linux-android") + set(NDK_ABI_armeabi-v7a_PROC "armv7-a") + set(NDK_ABI_armeabi-v7a_ARCH "arm") + set(NDK_ABI_armeabi-v7a_TRIPLE "arm-linux-androideabi") + set(NDK_ABI_armeabi-v7a_LLVM_TRIPLE "armv7-none-linux-androideabi") + set(NDK_ABI_armeabi-v6_PROC "armv6") + set(NDK_ABI_armeabi-v6_ARCH "arm") + set(NDK_ABI_armeabi-v6_TRIPLE "arm-linux-androideabi") + set(NDK_ABI_armeabi-v6_LLVM_TRIPLE "armv6-none-linux-androideabi") + set(NDK_ABI_armeabi_PROC "armv5te") + set(NDK_ABI_armeabi_ARCH "arm") + set(NDK_ABI_armeabi_TRIPLE "arm-linux-androideabi") + set(NDK_ABI_armeabi_LLVM_TRIPLE "armv5te-none-linux-androideabi") + set(NDK_ABI_mips_PROC "mips") + set(NDK_ABI_mips_ARCH "mips") + set(NDK_ABI_mips_TRIPLE "mipsel-linux-android") + set(NDK_ABI_mips_LLVM_TRIPLE "mipsel-none-linux-android") + set(NDK_ABI_mips64_PROC "mips64") + set(NDK_ABI_mips64_ARCH "mips64") + set(NDK_ABI_mips64_TRIPLE "mips64el-linux-android") + set(NDK_ABI_mips64_LLVM_TRIPLE "mips64el-none-linux-android") + set(NDK_ABI_x86_PROC "i686") + set(NDK_ABI_x86_ARCH "x86") + set(NDK_ABI_x86_TRIPLE "i686-linux-android") + set(NDK_ABI_x86_LLVM_TRIPLE "i686-none-linux-android") + set(NDK_ABI_x86_64_PROC "x86_64") + set(NDK_ABI_x86_64_ARCH "x86_64") + set(NDK_ABI_x86_64_TRIPLE "x86_64-linux-android") + set(NDK_ABI_x86_64_LLVM_TRIPLE "x86_64-none-linux-android") + + set(NDK_PROC_aarch64_ABI "arm64-v8a") + set(NDK_PROC_armv7-a_ABI "armeabi-v7a") + set(NDK_PROC_armv6_ABI "armeabi-v6") + set(NDK_PROC_armv5te_ABI "armeabi") + set(NDK_PROC_i686_ABI "x86") + set(NDK_PROC_mips_ABI "mips") + set(NDK_PROC_mips64_ABI "mips64") + set(NDK_PROC_x86_64_ABI "x86_64") + + set(NDK_ARCH_arm64_ABI "arm64-v8a") + set(NDK_ARCH_arm_ABI "armeabi") + set(NDK_ARCH_mips_ABI "mips") + set(NDK_ARCH_mips64_ABI "mips64") + set(NDK_ARCH_x86_ABI "x86") + set(NDK_ARCH_x86_64_ABI "x86_64") +endif() # Validate inputs. -if(CMAKE_ANDROID_ARCH_ABI AND NOT DEFINED "_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_PROC") +if(CMAKE_ANDROID_ARCH_ABI AND NOT DEFINED "NDK_ABI_${CMAKE_ANDROID_ARCH_ABI}_PROC") message(FATAL_ERROR "Android: Unknown ABI CMAKE_ANDROID_ARCH_ABI='${CMAKE_ANDROID_ARCH_ABI}'.") endif() -if(CMAKE_SYSTEM_PROCESSOR AND NOT DEFINED "_ANDROID_PROC_${CMAKE_SYSTEM_PROCESSOR}_ARCH_ABI") +if(CMAKE_SYSTEM_PROCESSOR AND NOT DEFINED "NDK_PROC_${CMAKE_SYSTEM_PROCESSOR}_ABI") message(FATAL_ERROR "Android: Unknown processor CMAKE_SYSTEM_PROCESSOR='${CMAKE_SYSTEM_PROCESSOR}'.") endif() -if(_ANDROID_SYSROOT_ARCH AND NOT DEFINED "_ANDROID_ARCH_${_ANDROID_SYSROOT_ARCH}_ABI") +if(_ANDROID_SYSROOT_ARCH AND NOT DEFINED "NDK_ARCH_${_ANDROID_SYSROOT_ARCH}_ABI") message(FATAL_ERROR "Android: Unknown architecture '${_ANDROID_SYSROOT_ARCH}' specified in CMAKE_SYSROOT:\n" " ${CMAKE_SYSROOT}" @@ -310,9 +339,9 @@ endif() # Select an ABI. if(NOT CMAKE_ANDROID_ARCH_ABI) if(CMAKE_SYSTEM_PROCESSOR) - set(CMAKE_ANDROID_ARCH_ABI "${_ANDROID_PROC_${CMAKE_SYSTEM_PROCESSOR}_ARCH_ABI}") + set(CMAKE_ANDROID_ARCH_ABI "${NDK_PROC_${CMAKE_SYSTEM_PROCESSOR}_ABI}") elseif(_ANDROID_SYSROOT_ARCH) - set(CMAKE_ANDROID_ARCH_ABI "${_ANDROID_ARCH_${_ANDROID_SYSROOT_ARCH}_ABI}") + set(CMAKE_ANDROID_ARCH_ABI "${NDK_ARCH_${_ANDROID_SYSROOT_ARCH}_ABI}") elseif(_INCLUDED_ABIS) # Default to the oldest ARM ABI. foreach(abi armeabi armeabi-v7a arm64-v8a) @@ -368,7 +397,7 @@ if(_INCLUDED_ABIS AND NOT CMAKE_ANDROID_ARCH_ABI IN_LIST _ANDROID_KNOWN_ABIS) "Supported ABIS: ${_ANDROID_KNOWN_ABIS}." ) endif() -set(CMAKE_ANDROID_ARCH "${_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_ARCH}") +set(CMAKE_ANDROID_ARCH "${NDK_ABI_${CMAKE_ANDROID_ARCH_ABI}_ARCH}") if(_ANDROID_SYSROOT_ARCH AND NOT "x${_ANDROID_SYSROOT_ARCH}" STREQUAL "x${CMAKE_ANDROID_ARCH}") message(FATAL_ERROR "Android: Architecture '${_ANDROID_SYSROOT_ARCH}' specified in CMAKE_SYSROOT:\n" @@ -376,15 +405,17 @@ if(_ANDROID_SYSROOT_ARCH AND NOT "x${_ANDROID_SYSROOT_ARCH}" STREQUAL "x${CMAKE_ "does not match architecture '${CMAKE_ANDROID_ARCH}' for the ABI '${CMAKE_ANDROID_ARCH_ABI}'." ) endif() -set(CMAKE_ANDROID_ARCH_TRIPLE "${_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_TRIPLE}") +set(CMAKE_ANDROID_ARCH_TRIPLE "${NDK_ABI_${CMAKE_ANDROID_ARCH_ABI}_TRIPLE}") +set(CMAKE_ANDROID_ARCH_LLVM_TRIPLE + "${NDK_ABI_${CMAKE_ANDROID_ARCH_ABI}_LLVM_TRIPLE}") # Select a processor. if(NOT CMAKE_SYSTEM_PROCESSOR) - set(CMAKE_SYSTEM_PROCESSOR "${_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_PROC}") + set(CMAKE_SYSTEM_PROCESSOR "${NDK_ABI_${CMAKE_ANDROID_ARCH_ABI}_PROC}") endif() # If the user specified both an ABI and a processor then they might not match. -if(NOT _ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_PROC STREQUAL CMAKE_SYSTEM_PROCESSOR) +if(NOT NDK_ABI_${CMAKE_ANDROID_ARCH_ABI}_PROC STREQUAL CMAKE_SYSTEM_PROCESSOR) message(FATAL_ERROR "Android: The specified CMAKE_ANDROID_ARCH_ABI='${CMAKE_ANDROID_ARCH_ABI}' and CMAKE_SYSTEM_PROCESSOR='${CMAKE_SYSTEM_PROCESSOR}' is not a valid combination.") endif() @@ -491,6 +522,7 @@ set(CMAKE_ANDROID_ARCH_ABI \"${CMAKE_ANDROID_ARCH_ABI}\") if(CMAKE_ANDROID_NDK) string(APPEND CMAKE_SYSTEM_CUSTOM_CODE "set(CMAKE_ANDROID_ARCH_TRIPLE \"${CMAKE_ANDROID_ARCH_TRIPLE}\")\n" + "set(CMAKE_ANDROID_ARCH_LLVM_TRIPLE \"${CMAKE_ANDROID_ARCH_LLVM_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" "set(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED \"${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}\")\n" @@ -528,3 +560,9 @@ endif() message(STATUS "Android: Targeting API '${CMAKE_SYSTEM_VERSION}' with architecture '${CMAKE_ANDROID_ARCH}', ABI '${CMAKE_ANDROID_ARCH_ABI}', and processor '${CMAKE_SYSTEM_PROCESSOR}'") cmake_policy(POP) + +# Include the NDK hook. +# It can be used by NDK to inject necessary fixes for an earlier cmake. +if(CMAKE_ANDROID_NDK) + include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/post/Android-Determine.cmake OPTIONAL) +endif() diff --git a/Modules/Platform/Android-Initialize.cmake b/Modules/Platform/Android-Initialize.cmake index 5019c28..6116ae1 100644 --- a/Modules/Platform/Android-Initialize.cmake +++ b/Modules/Platform/Android-Initialize.cmake @@ -4,6 +4,12 @@ # When CMAKE_SYSTEM_NAME is "Android", CMakeSystemSpecificInitialize loads this # module. +# Include the NDK hook. +# It can be used by NDK to inject necessary fixes for an earlier cmake. +if(CMAKE_ANDROID_NDK) + include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/pre/Android-Initialize.cmake OPTIONAL) +endif() + # Support for NVIDIA Nsight Tegra Visual Studio Edition was previously # implemented in the CMake VS IDE generators. Avoid interfering with # that functionality for now. @@ -17,7 +23,7 @@ if(CMAKE_SYSTEM_VERSION EQUAL 1) return() endif() -set(CMAKE_BUILD_TYPE_INIT Debug) +set(CMAKE_BUILD_TYPE_INIT "RelWithDebInfo") # Skip sysroot selection if the NDK has a unified toolchain. if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED) @@ -53,3 +59,9 @@ else() "Android: No CMAKE_SYSROOT was selected." ) endif() + +# Include the NDK hook. +# It can be used by NDK to inject necessary fixes for an earlier cmake. +if(CMAKE_ANDROID_NDK) + include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/post/Android-Initialize.cmake OPTIONAL) +endif() diff --git a/Modules/Platform/Android.cmake b/Modules/Platform/Android.cmake index 8ffa1b2..e4b9a09 100644 --- a/Modules/Platform/Android.cmake +++ b/Modules/Platform/Android.cmake @@ -1,3 +1,9 @@ +# Include the NDK hook. +# It can be used by NDK to inject necessary fixes for an earlier cmake. +if(CMAKE_ANDROID_NDK) + include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/pre/Android.cmake OPTIONAL) +endif() + include(Platform/Linux) set(ANDROID 1) @@ -22,3 +28,65 @@ set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "") if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android") set(CMAKE_LINK_LIBRARY_FLAG "") endif() + +# Commonly used Android toolchain files that pre-date CMake upstream support +# set CMAKE_SYSTEM_VERSION to 1. Avoid interfering with them. +if(CMAKE_SYSTEM_VERSION EQUAL 1) + return() +endif() + +if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED) + # Tell CMake not to search host sysroots for headers/libraries. + + # All paths added to CMAKE_SYSTEM_*_PATH below will be rerooted under + # CMAKE_FIND_ROOT_PATH. This is set because: + # 1. Users may structure their libraries in a way similar to NDK. When they do that, + # they can simply append another path to CMAKE_FIND_ROOT_PATH. + # 2. CMAKE_FIND_ROOT_PATH must be non-empty for CMAKE_FIND_ROOT_PATH_MODE_* == ONLY + # to be meaningful. https://github.com/android-ndk/ndk/issues/890 + list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/sysroot") + + # Allow users to override these values in case they want more strict behaviors. + # For example, they may want to prevent the NDK's libz from being picked up so + # they can use their own. + # https://github.com/android-ndk/ndk/issues/517 + if(NOT DEFINED CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + endif() + + if(NOT DEFINED CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + endif() + + if(NOT DEFINED CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + endif() + + if(NOT DEFINED CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + endif() + + # Don't search paths in PATH environment variable. + if(NOT DEFINED CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH) + set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH OFF) + endif() + + # Allows CMake to find headers in the architecture-specific include directories. + set(CMAKE_LIBRARY_ARCHITECTURE "${CMAKE_ANDROID_ARCH_TRIPLE}") + + # Instructs CMake to search the correct API level for libraries. + # Besides the paths like <root>/<prefix>/lib/<arch>, cmake also searches <root>/<prefix>. + # So we can add the API level specific directory directly. + # https://github.com/android/ndk/issues/929 + list(PREPEND CMAKE_SYSTEM_PREFIX_PATH + "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/${CMAKE_SYSTEM_VERSION}" + ) + + list(APPEND CMAKE_SYSTEM_PROGRAM_PATH "${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/bin") +endif() + +# Include the NDK hook. +# It can be used by NDK to inject necessary fixes for an earlier cmake. +if(CMAKE_ANDROID_NDK) + include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/post/Android.cmake OPTIONAL) +endif() diff --git a/Modules/Platform/Android/Determine-Compiler.cmake b/Modules/Platform/Android/Determine-Compiler.cmake index f9c2d89..f8eae62 100644 --- a/Modules/Platform/Android/Determine-Compiler.cmake +++ b/Modules/Platform/Android/Determine-Compiler.cmake @@ -7,6 +7,12 @@ if(__ANDROID_DETERMINE_COMPILER) endif() set(__ANDROID_DETERMINE_COMPILER 1) +# Include the NDK hook. +# It can be used by NDK to inject necessary fixes for an earlier cmake. +if(CMAKE_ANDROID_NDK) + include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/pre/Determine-Compiler.cmake OPTIONAL) +endif() + # Support for NVIDIA Nsight Tegra Visual Studio Edition was previously # implemented in the CMake VS IDE generators. Avoid interfering with # that functionality for now. Later we may try to integrate this. @@ -83,3 +89,9 @@ set(CMAKE_${lang}_ANDROID_TOOLCHAIN_SUFFIX \"${_ANDROID_TOOL_${lang}_TOOLCHAIN_S ") endif() endmacro() + +# Include the NDK hook. +# It can be used by NDK to inject necessary fixes for an earlier cmake. +if(CMAKE_ANDROID_NDK) + include(${CMAKE_ANDROID_NDK}/build/cmake/hooks/post/Determine-Compiler.cmake OPTIONAL) +endif() diff --git a/Modules/Platform/Android/abi-arm64-v8a-Clang.cmake b/Modules/Platform/Android/abi-arm64-v8a-Clang.cmake index f4717d5..c18c0a2 100644 --- a/Modules/Platform/Android/abi-arm64-v8a-Clang.cmake +++ b/Modules/Platform/Android/abi-arm64-v8a-Clang.cmake @@ -1,6 +1,3 @@ -# <ndk>/build/core/toolchains/aarch64-linux-android-clang/setup.mk -set(_ANDROID_ABI_CLANG_TARGET "aarch64-none-linux-android") - # Suppress -Wl,-z,nocopyreloc flag on arm64-v8a set(_ANDROID_ABI_INIT_EXE_LDFLAGS_NO_nocopyreloc 1) diff --git a/Modules/Platform/Android/abi-armeabi-Clang.cmake b/Modules/Platform/Android/abi-armeabi-Clang.cmake index b857bd3..2b1de03 100644 --- a/Modules/Platform/Android/abi-armeabi-Clang.cmake +++ b/Modules/Platform/Android/abi-armeabi-Clang.cmake @@ -1,6 +1,3 @@ -# <ndk>/build/core/toolchains/arm-linux-androideabi-clang/setup.mk -set(_ANDROID_ABI_CLANG_TARGET "armv5te-none-linux-androideabi") - string(APPEND _ANDROID_ABI_INIT_CFLAGS " -march=armv5te" ) diff --git a/Modules/Platform/Android/abi-armeabi-v6-Clang.cmake b/Modules/Platform/Android/abi-armeabi-v6-Clang.cmake index a7412f5..bb176ae 100644 --- a/Modules/Platform/Android/abi-armeabi-v6-Clang.cmake +++ b/Modules/Platform/Android/abi-armeabi-v6-Clang.cmake @@ -1,6 +1,3 @@ -# <ndk>/build/core/toolchains/arm-linux-androideabi-clang/setup.mk -set(_ANDROID_ABI_CLANG_TARGET "armv6-none-linux-androideabi") - string(APPEND _ANDROID_ABI_INIT_CFLAGS " -march=armv6" ) diff --git a/Modules/Platform/Android/abi-armeabi-v7a-Clang.cmake b/Modules/Platform/Android/abi-armeabi-v7a-Clang.cmake index e2ab58b..6feeef6 100644 --- a/Modules/Platform/Android/abi-armeabi-v7a-Clang.cmake +++ b/Modules/Platform/Android/abi-armeabi-v7a-Clang.cmake @@ -1,6 +1,3 @@ -# <ndk>/build/core/toolchains/arm-linux-androideabi-clang/setup.mk -set(_ANDROID_ABI_CLANG_TARGET "armv7-none-linux-androideabi") - string(APPEND _ANDROID_ABI_INIT_CFLAGS " -march=armv7-a" ) diff --git a/Modules/Platform/Android/abi-mips-Clang.cmake b/Modules/Platform/Android/abi-mips-Clang.cmake index 73addde..7df6a36 100644 --- a/Modules/Platform/Android/abi-mips-Clang.cmake +++ b/Modules/Platform/Android/abi-mips-Clang.cmake @@ -1,4 +1 @@ -# <ndk>/build/core/toolchains/mipsel-linux-android-clang/setup.mk -set(_ANDROID_ABI_CLANG_TARGET "mipsel-none-linux-android") - include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Android/abi-mips64-Clang.cmake b/Modules/Platform/Android/abi-mips64-Clang.cmake index 603f1b2..7df6a36 100644 --- a/Modules/Platform/Android/abi-mips64-Clang.cmake +++ b/Modules/Platform/Android/abi-mips64-Clang.cmake @@ -1,4 +1 @@ -# <ndk>/build/core/toolchains/mips64el-linux-android-clang/setup.mk -set(_ANDROID_ABI_CLANG_TARGET "mips64el-none-linux-android") - include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Android/abi-x86-Clang.cmake b/Modules/Platform/Android/abi-x86-Clang.cmake index fe7eace..7df6a36 100644 --- a/Modules/Platform/Android/abi-x86-Clang.cmake +++ b/Modules/Platform/Android/abi-x86-Clang.cmake @@ -1,4 +1 @@ -# <ndk>/build/core/toolchains/x86-clang/setup.mk -set(_ANDROID_ABI_CLANG_TARGET "i686-none-linux-android") - include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Android/abi-x86_64-Clang.cmake b/Modules/Platform/Android/abi-x86_64-Clang.cmake index 3cbcd49..7df6a36 100644 --- a/Modules/Platform/Android/abi-x86_64-Clang.cmake +++ b/Modules/Platform/Android/abi-x86_64-Clang.cmake @@ -1,4 +1 @@ -# <ndk>/build/core/toolchains/x86_64-clang/setup.mk -set(_ANDROID_ABI_CLANG_TARGET "x86_64-none-linux-android") - include(Platform/Android/abi-common-Clang) diff --git a/Modules/Platform/Windows-Clang-C.cmake b/Modules/Platform/Windows-Clang-C.cmake index d007105..322e3fb 100644 --- a/Modules/Platform/Windows-Clang-C.cmake +++ b/Modules/Platform/Windows-Clang-C.cmake @@ -1,2 +1,18 @@ include(Platform/Windows-Clang) __windows_compiler_clang(C) + +if("x${MAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC") + if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER) + AND CMAKE_GENERATOR MATCHES "Makefiles|WMake" + AND CMAKE_DEPFILE_FLAGS_C) + set(CMAKE_C_DEPENDS_USE_COMPILER TRUE) + endif() +elseif("x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") + if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER) + AND CMAKE_GENERATOR MATCHES "Makefiles|WMake" + AND CMAKE_DEPFILE_FLAGS_C) + # dependencies are computed by the compiler itself + set(CMAKE_C_DEPFILE_FORMAT gcc) + set(CMAKE_C_DEPENDS_USE_COMPILER TRUE) + endif() +endif() diff --git a/Modules/Platform/Windows-Clang-CXX.cmake b/Modules/Platform/Windows-Clang-CXX.cmake index f1d40f2..b4aaf1e 100644 --- a/Modules/Platform/Windows-Clang-CXX.cmake +++ b/Modules/Platform/Windows-Clang-CXX.cmake @@ -1,3 +1,19 @@ include(Platform/Windows-Clang) set(_COMPILE_CXX_MSVC " -TP") __windows_compiler_clang(CXX) + +if("x${MAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC") + if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER) + AND CMAKE_GENERATOR MATCHES "Makefiles|WMake" + AND CMAKE_DEPFILE_FLAGS_CXX) + set(CMAKE_CXX_DEPENDS_USE_COMPILER TRUE) + endif() +elseif("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") + if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER) + AND CMAKE_GENERATOR MATCHES "Makefiles|WMake" + AND CMAKE_DEPFILE_FLAGS_CXX) + # dependencies are computed by the compiler itself + set(CMAKE_CXX_DEPFILE_FORMAT gcc) + set(CMAKE_CXX_DEPENDS_USE_COMPILER TRUE) + endif() +endif() diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake index 389d6ab..51e9e81 100644 --- a/Modules/Platform/Windows-Clang.cmake +++ b/Modules/Platform/Windows-Clang.cmake @@ -27,7 +27,7 @@ macro(__windows_compiler_clang_gnu lang) set(CMAKE_SHARED_MODULE_SUFFIX ".dll") set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib") if(NOT "${lang}" STREQUAL "ASM") - set(CMAKE_DEPFILE_FLAGS_${lang} "-MD -MT <OBJECT> -MF <DEPFILE>") + set(CMAKE_DEPFILE_FLAGS_${lang} "-MD -MT <DEP_TARGET> -MF <DEP_FILE>") endif() set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "") @@ -114,8 +114,10 @@ macro(__enable_llvm_rc_preprocessing clang_option_prefix extra_pp_flags) set(CMAKE_RC_PREPROCESSOR CMAKE_CXX_COMPILER) endif() if(DEFINED CMAKE_RC_PREPROCESSOR) - set(CMAKE_DEPFILE_FLAGS_RC "${clang_option_prefix}-MD ${clang_option_prefix}-MF ${clang_option_prefix}<DEPFILE>") - set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_COMMAND> -E cmake_llvm_rc <SOURCE> <OBJECT>.pp <${CMAKE_RC_PREPROCESSOR}> <DEFINES> -DRC_INVOKED <INCLUDES> <FLAGS> ${extra_pp_flags} -E -- <SOURCE> ++ <CMAKE_RC_COMPILER> <DEFINES> -I <SOURCE_DIR> <INCLUDES> /fo <OBJECT> <OBJECT>.pp") + set(CMAKE_DEPFILE_FLAGS_RC "${clang_option_prefix}-MD ${clang_option_prefix}-MF ${clang_option_prefix}<DEP_FILE>") + # The <FLAGS> are passed to the preprocess and the resource compiler to pick + # up the eventual -D / -C options passed through the CMAKE_RC_FLAGS. + set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_COMMAND> -E cmake_llvm_rc <SOURCE> <OBJECT>.pp <${CMAKE_RC_PREPROCESSOR}> <DEFINES> -DRC_INVOKED <INCLUDES> <FLAGS> ${extra_pp_flags} -E -- <SOURCE> ++ <CMAKE_RC_COMPILER> <DEFINES> -I <SOURCE_DIR> <INCLUDES> <FLAGS> /fo <OBJECT> <OBJECT>.pp") if(CMAKE_GENERATOR MATCHES "Ninja") set(CMAKE_NINJA_CMCLDEPS_RC 0) set(CMAKE_NINJA_DEP_TYPE_RC gcc) diff --git a/Modules/Platform/Windows-Intel-C.cmake b/Modules/Platform/Windows-Intel-C.cmake index 06d8f50..3cbc7a5 100644 --- a/Modules/Platform/Windows-Intel-C.cmake +++ b/Modules/Platform/Windows-Intel-C.cmake @@ -1,4 +1,11 @@ include(Platform/Windows-Intel) __windows_compiler_intel(C) set(CMAKE_NINJA_DEPTYPE_C intel) # special value handled by CMake -set(CMAKE_DEPFILE_FLAGS_C "-QMMD -QMT <OBJECT> -QMF <DEPFILE>") +set(CMAKE_DEPFILE_FLAGS_C "-QMMD -QMT <DEP_TARGET> -QMF <DEP_FILE>") + +if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER) + AND CMAKE_GENERATOR MATCHES "Makefiles|WMake") + # dependencies are computed by the compiler itself + set(CMAKE_C_DEPFILE_FORMAT gcc) + set(CMAKE_C_DEPENDS_USE_COMPILER TRUE) +endif() diff --git a/Modules/Platform/Windows-Intel-CXX.cmake b/Modules/Platform/Windows-Intel-CXX.cmake index 666de6e..6539f64 100644 --- a/Modules/Platform/Windows-Intel-CXX.cmake +++ b/Modules/Platform/Windows-Intel-CXX.cmake @@ -2,4 +2,11 @@ include(Platform/Windows-Intel) set(_COMPILE_CXX " /TP") __windows_compiler_intel(CXX) set(CMAKE_NINJA_DEPTYPE_CXX intel) # special value handled by CMake -set(CMAKE_DEPFILE_FLAGS_CXX "-QMMD -QMT <OBJECT> -QMF <DEPFILE>") +set(CMAKE_DEPFILE_FLAGS_CXX "-QMMD -QMT <DEP_TARGET> -QMF <DEP_FILE>") + +if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER) + AND CMAKE_GENERATOR MATCHES "Makefiles|WMake") + # dependencies are computed by the compiler itself + set(CMAKE_CXX_DEPFILE_FORMAT gcc) + set(CMAKE_CXX_DEPENDS_USE_COMPILER TRUE) +endif() diff --git a/Modules/Platform/Windows-MSVC-C.cmake b/Modules/Platform/Windows-MSVC-C.cmake index cbe1586..67b6827 100644 --- a/Modules/Platform/Windows-MSVC-C.cmake +++ b/Modules/Platform/Windows-MSVC-C.cmake @@ -3,3 +3,10 @@ if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 18.0) set(_FS_C " /FS") endif() __windows_compiler_msvc(C) + +if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER) + AND CMAKE_GENERATOR MATCHES "Makefiles|WMake" + AND CMAKE_DEPFILE_FLAGS_C) + # dependencies are computed by the compiler itself + set(CMAKE_C_DEPENDS_USE_COMPILER TRUE) +endif() diff --git a/Modules/Platform/Windows-MSVC-CXX.cmake b/Modules/Platform/Windows-MSVC-CXX.cmake index 0e85005..6fea617 100644 --- a/Modules/Platform/Windows-MSVC-CXX.cmake +++ b/Modules/Platform/Windows-MSVC-CXX.cmake @@ -4,3 +4,10 @@ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0) set(_FS_CXX " /FS") endif() __windows_compiler_msvc(CXX) + +if((NOT DEFINED CMAKE_DEPENDS_USE_COMPILER OR CMAKE_DEPENDS_USE_COMPILER) + AND CMAKE_GENERATOR MATCHES "Makefiles|WMake" + AND CMAKE_DEPFILE_FLAGS_CXX) + # dependencies are computed by the compiler itself + set(CMAKE_CXX_DEPENDS_USE_COMPILER TRUE) +endif() diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake index bd08718..ec5758c 100644 --- a/Modules/Platform/Windows-MSVC.cmake +++ b/Modules/Platform/Windows-MSVC.cmake @@ -163,6 +163,14 @@ foreach(lang C CXX) endif() endforeach() +cmake_policy(GET CMP0117 __WINDOWS_MSVC_CMP0117) +if(__WINDOWS_MSVC_CMP0117 STREQUAL "NEW") + set(_GR "") +else() + set(_GR " /GR") +endif() +unset(__WINDOWS_MSVC_CMP0117) + if(WINCE) foreach(lang C CXX) string(TOUPPER "${_MSVC_${lang}_ARCHITECTURE_FAMILY}" _MSVC_${lang}_ARCHITECTURE_FAMILY_UPPER) @@ -182,7 +190,7 @@ if(WINCE) set(_RTC1 "") set(_FLAGS_C "") - set(_FLAGS_CXX " /GR /EHsc") + set(_FLAGS_CXX "${_GR} /EHsc") foreach(lang C CXX) if(_MSVC_${lang}_ARCHITECTURE_FAMILY STREQUAL "ARM") @@ -204,7 +212,7 @@ if(WINCE) elseif(WINDOWS_PHONE OR WINDOWS_STORE) set(_PLATFORM_DEFINES "/DWIN32") set(_FLAGS_C " /DUNICODE /D_UNICODE") - set(_FLAGS_CXX " /DUNICODE /D_UNICODE /GR /EHsc") + set(_FLAGS_CXX " /DUNICODE /D_UNICODE${_GR} /EHsc") if(WINDOWS_STORE AND MSVC_VERSION GREATER 1899) set(CMAKE_C_STANDARD_LIBRARIES_INIT "WindowsApp.lib") elseif(WINDOWS_PHONE) @@ -226,12 +234,12 @@ else() set(_FLAGS_CXX " -frtti -fexceptions") else() set(_RTC1 "/RTC1") - set(_FLAGS_CXX " /GR /EHsc") + set(_FLAGS_CXX "${_GR} /EHsc") endif() set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib") else() set(_RTC1 "/GZ") - set(_FLAGS_CXX " /GR /GX") + set(_FLAGS_CXX "${_GR} /GX") set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib") endif() @@ -241,6 +249,8 @@ else() endif() endif() +unset(_GR) + set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}") # executable linker flags @@ -427,6 +437,13 @@ macro(__windows_compiler_msvc lang) set(CMAKE_${lang}_LINKER_SUPPORTS_PDB ON) set(CMAKE_NINJA_DEPTYPE_${lang} msvc) __windows_compiler_msvc_enable_rc("${_PLATFORM_DEFINES} ${_PLATFORM_DEFINES_${lang}}") + + # define generic information about compiler dependencies + # activation is done on per language platform configuration basis + if (MSVC_VERSION GREATER 1300) + set(CMAKE_DEPFILE_FLAGS_${lang} "/showIncludes") + set(CMAKE_${lang}_DEPFILE_FORMAT msvc) + endif() endmacro() macro(__windows_compiler_msvc_enable_rc flags) |