summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-11-10 14:41:39 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-11-10 14:42:31 (GMT)
commitf4f3fca99fd4dc473fba31f17c5d09b8b6e2d1fb (patch)
treec7cb3a561f44d5626bddce10806ef3c4ae4f4f64 /Modules
parent9321379d7ea2e43486a22aa3e0de4581ceac20c4 (diff)
parentcbc51a8be36b4448048c68106fd895eccee8b9fb (diff)
downloadCMake-f4f3fca99fd4dc473fba31f17c5d09b8b6e2d1fb.zip
CMake-f4f3fca99fd4dc473fba31f17c5d09b8b6e2d1fb.tar.gz
CMake-f4f3fca99fd4dc473fba31f17c5d09b8b6e2d1fb.tar.bz2
Merge topic 'android-root'
cbc51a8be3 Android: restructure android search paths Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: huangqinjin <huangqinjin@gmail.com> Merge-request: !5479
Diffstat (limited to 'Modules')
-rw-r--r--Modules/Platform/Android.cmake46
1 files changed, 14 insertions, 32 deletions
diff --git a/Modules/Platform/Android.cmake b/Modules/Platform/Android.cmake
index 2a1a7a3..e4b9a09 100644
--- a/Modules/Platform/Android.cmake
+++ b/Modules/Platform/Android.cmake
@@ -37,14 +37,14 @@ endif()
if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED)
# Tell CMake not to search host sysroots for headers/libraries.
- # CMAKE_FIND_ROOT_PATH must be non-empty for CMAKE_FIND_ROOT_PATH_MODE_* == ONLY
- # to be meaningful. The actual path used here is fairly meaningless since CMake
- # doesn't handle the NDK sysroot layout (per-arch and per-verion subdirectories for
- # libraries), so find_library is handled separately by CMAKE_SYSTEM_LIBRARY_PATH.
- # https://github.com/android-ndk/ndk/issues/890
- if(NOT CMAKE_FIND_ROOT_PATH)
- list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_ANDROID_NDK}")
- endif()
+
+ # 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
@@ -66,20 +66,6 @@ if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
endif()
- # find_library's default search paths below a prefix do not match the Android
- # sysroot layout, so we need to give the direct path to the libraries
- # via CMAKE_SYSTEM_*_PATH.
- #
- # Ideally we'd set CMAKE_SYSTEM_PREFIX_PATH. But that causes the
- # non-api-level-specific path to be searched first for find_library, which will
- # cause libdl.a to be found before libdl.so.
- # https://github.com/android/ndk/issues/929
-
- # Clears the paths set by UnixPaths.cmake.
- set(CMAKE_SYSTEM_PREFIX_PATH)
- set(CMAKE_SYSTEM_INCLUDE_PATH)
- set(CMAKE_SYSTEM_LIBRARY_PATH)
-
# 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)
@@ -88,17 +74,13 @@ if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED)
# Allows CMake to find headers in the architecture-specific include directories.
set(CMAKE_LIBRARY_ARCHITECTURE "${CMAKE_ANDROID_ARCH_TRIPLE}")
- set(_ANDROID_SYSROOT_PREFIX "${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/sysroot/usr")
-
- list(APPEND CMAKE_SYSTEM_INCLUDE_PATH
- "${_ANDROID_SYSROOT_PREFIX}/include/${CMAKE_LIBRARY_ARCHITECTURE}")
- list(APPEND CMAKE_SYSTEM_INCLUDE_PATH "${_ANDROID_SYSROOT_PREFIX}/include")
-
# Instructs CMake to search the correct API level for libraries.
- list(APPEND CMAKE_SYSTEM_LIBRARY_PATH
- "${_ANDROID_SYSROOT_PREFIX}/lib/${CMAKE_LIBRARY_ARCHITECTURE}/${CMAKE_SYSTEM_VERSION}")
- list(APPEND CMAKE_SYSTEM_LIBRARY_PATH
- "${_ANDROID_SYSROOT_PREFIX}/lib/${CMAKE_LIBRARY_ARCHITECTURE}")
+ # 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()