Skip to content

Commit 632e7a7

Browse files
committed
[android] Detect the NDK version by reading source.properties, not by checking the NDK name
1 parent 643cbd1 commit 632e7a7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,22 @@ function(_add_target_variant_link_flags)
555555
list(APPEND link_libraries "dl" "log")
556556
# We need to add the math library, which is linked implicitly by libc++
557557
list(APPEND result "-lm")
558-
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows)
558+
if(NOT CMAKE_HOST_SYSTEM MATCHES Windows AND NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
559559
# The Android resource dir is specified from build.ps1 on windows.
560-
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
561-
if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "r26|r27")
560+
if(EXISTS "${SWIFT_ANDROID_NDK_PATH}/source.properties")
561+
file(READ "${SWIFT_ANDROID_NDK_PATH}/source.properties" NDK_VERSION)
562+
if(NOT NDK_VERSION MATCHES "Pkg\\.Revision = ([0-9\\.]+)")
563+
message(FATAL_ERROR "Could not find NDK version in source.properties: ${NDK_VERSION}")
564+
endif()
565+
566+
if("${CMAKE_MATCH_1}" VERSION_GREATER_EQUAL "26")
562567
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib/clang/*)
563568
else()
564569
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)
565570
endif()
566571
list(APPEND result "-resource-dir=${RESOURCE_DIR}")
572+
else()
573+
message(FATAL_ERROR "Could not detect NDK version: ${SWIFT_ANDROID_NDK_PATH}/source.properties not found")
567574
endif()
568575
endif()
569576

0 commit comments

Comments
 (0)