diff options
author | Haibo Huang <hhb@google.com> | 2020-10-14 02:23:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-10-23 13:36:48 (GMT) |
commit | a7f41a7ee4ba2564a03a1f9a752ff79828ef4b19 (patch) | |
tree | 187fd2d4ee56a6bc3402b4f6784cf44ac1333e7b /Modules/Platform/Android.cmake | |
parent | 5cdf37e4cccf85f7b4648591731c13d72d971c32 (diff) | |
download | CMake-a7f41a7ee4ba2564a03a1f9a752ff79828ef4b19.zip CMake-a7f41a7ee4ba2564a03a1f9a752ff79828ef4b19.tar.gz CMake-a7f41a7ee4ba2564a03a1f9a752ff79828ef4b19.tar.bz2 |
Android: Fix find_* search order within NDK for unified toolchains
Diffstat (limited to 'Modules/Platform/Android.cmake')
-rw-r--r-- | Modules/Platform/Android.cmake | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Modules/Platform/Android.cmake b/Modules/Platform/Android.cmake index 17d056a..80d81aa 100644 --- a/Modules/Platform/Android.cmake +++ b/Modules/Platform/Android.cmake @@ -59,4 +59,40 @@ if(CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED) if(NOT DEFINED CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 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) + endif() + + # 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}") + + list(APPEND CMAKE_SYSTEM_PROGRAM_PATH "${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/bin") endif() |