summaryrefslogtreecommitdiffstats
path: root/Modules/Platform/Android-Determine.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-06-09 17:30:37 (GMT)
committerBrad King <brad.king@kitware.com>2017-06-09 18:19:52 (GMT)
commit5f93bf787d0ccccf1aa6dc3f6f1d0df3855a55f6 (patch)
tree49bfbfb63dac03872a5d8666ed5e8ff1900606eb /Modules/Platform/Android-Determine.cmake
parentd025faf436c86ee9cc033fbb324a9bc2c18757fa (diff)
downloadCMake-5f93bf787d0ccccf1aa6dc3f6f1d0df3855a55f6.zip
CMake-5f93bf787d0ccccf1aa6dc3f6f1d0df3855a55f6.tar.gz
CMake-5f93bf787d0ccccf1aa6dc3f6f1d0df3855a55f6.tar.bz2
Android: Detect API version of standalone toolchain with unified headers
A standalone toolchain with unified headers keeps the `__ANDROID_API__` macro in the `bin/clang` launcher instead of in `api-level.h`. Issue: #16954
Diffstat (limited to 'Modules/Platform/Android-Determine.cmake')
-rw-r--r--Modules/Platform/Android-Determine.cmake33
1 files changed, 28 insertions, 5 deletions
diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake
index 6d370ab..076be85 100644
--- a/Modules/Platform/Android-Determine.cmake
+++ b/Modules/Platform/Android-Determine.cmake
@@ -100,11 +100,34 @@ endif()
set(_ANDROID_STANDALONE_TOOLCHAIN_API "")
if(CMAKE_ANDROID_STANDALONE_TOOLCHAIN)
- set(_ANDROID_API_LEVEL_H_REGEX "^[\t ]*#[\t ]*define[\t ]+__ANDROID_API__[\t ]+([0-9]+)")
- file(STRINGS "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h"
- _ANDROID_API_LEVEL_H_CONTENT REGEX "${_ANDROID_API_LEVEL_H_REGEX}")
- if(_ANDROID_API_LEVEL_H_CONTENT MATCHES "${_ANDROID_API_LEVEL_H_REGEX}")
- set(_ANDROID_STANDALONE_TOOLCHAIN_API "${CMAKE_MATCH_1}")
+ # Try to read the API level from the toolchain launcher.
+ if(EXISTS "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/clang")
+ set(_ANDROID_API_LEVEL_CLANG_REGEX "__ANDROID_API__=([0-9]+)")
+ file(STRINGS "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/clang" _ANDROID_STANDALONE_TOOLCHAIN_BIN_CLANG
+ REGEX "${_ANDROID_API_LEVEL_CLANG_REGEX}" LIMIT_COUNT 1 LIMIT_INPUT 65536)
+ if(_ANDROID_STANDALONE_TOOLCHAIN_BIN_CLANG MATCHES "${_ANDROID_API_LEVEL_CLANG_REGEX}")
+ set(_ANDROID_STANDALONE_TOOLCHAIN_API "${CMAKE_MATCH_1}")
+ endif()
+ unset(_ANDROID_STANDALONE_TOOLCHAIN_BIN_CLANG)
+ unset(_ANDROID_API_LEVEL_CLANG_REGEX)
+ endif()
+ if(NOT _ANDROID_STANDALONE_TOOLCHAIN_API)
+ # The compiler launcher does not know __ANDROID_API__. Assume this
+ # is not unified headers and look for it in the api-level.h header.
+ set(_ANDROID_API_LEVEL_H_REGEX "^[\t ]*#[\t ]*define[\t ]+__ANDROID_API__[\t ]+([0-9]+)")
+ file(STRINGS "${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h"
+ _ANDROID_API_LEVEL_H_CONTENT REGEX "${_ANDROID_API_LEVEL_H_REGEX}")
+ if(_ANDROID_API_LEVEL_H_CONTENT MATCHES "${_ANDROID_API_LEVEL_H_REGEX}")
+ set(_ANDROID_STANDALONE_TOOLCHAIN_API "${CMAKE_MATCH_1}")
+ endif()
+ endif()
+ if(NOT _ANDROID_STANDALONE_TOOLCHAIN_API)
+ message(WARNING
+ "Android: Did not detect API level from\n"
+ " ${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/bin/clang\n"
+ "or\n"
+ " ${CMAKE_ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h\n"
+ )
endif()
endif()