File: DetectAndroidNDKVersion.cmake

package info (click to toggle)
qcoro 0.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,700 kB
  • sloc: cpp: 8,573; python: 32; xml: 26; makefile: 23; sh: 15
file content (32 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# SPDX-FileCopyrightText: 2023 Daniel Vrátil <dvratil@kde.org>
#
# SPDX-License-Identifier: MIT

cmake_policy(SET CMP0140 NEW)

function(detectAndroidNDKVersion outVar)
    if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.20)
        # CMAKE_ANDROID_NDK_VERSION introduced in CMake 3.20
        set(${outVar} "${CMAKE_ANDROID_NDK_VERSION}")
    else()
        if (NOT CMAKE_ANDROID_NDK)
            message(STATUS "Couldn't detect Android NDK version: CMAKE_ANDROID_NDK not set")
            return()
        endif()
        if (NOT EXISTS "${CMAKE_ANDROID_NDK}/source.properties")
            message(STATUS "Couldn't detect Android NDK version: ${CMAKE_ANDROID_NDK}/source.properties doesn't exist")
            return()
        endif()
        file(STRINGS "${CMAKE_ANDROID_NDK}/source.properties" _sources REGEX "^Pkg\.Revision = [0-9]+\.[0-9]+\.[0-9]+$")
        string(REGEX MATCH "= ([0-9]+\.[0-9]+)\." _match "${_sources}")
        set(${outVar} "${CMAKE_MATCH_1}")
        if (NOT ${outVar})
            message(STATUS "Couldn't detect Android NDK version: ${CMAKE_ANDROID_NDK}/source.properties doesn't contain Pkg.Revision")
            return()
        endif()

    endif()

    message(STATUS "Detected Android NDK version ${${outVar}}")
    return(PROPAGATE ${outVar})
endfunction()