summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidPlatform.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidPlatform.cmake')
-rw-r--r--src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidPlatform.cmake124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidPlatform.cmake b/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidPlatform.cmake
new file mode 100644
index 0000000..fbe53c3
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/cmake/android/FindSdlAndroidPlatform.cmake
@@ -0,0 +1,124 @@
1#[=======================================================================[
2
3FindSdlAndroidPlatform
4----------------------
5
6Locate the Android SDK platform.
7
8
9Imported targets
10^^^^^^^^^^^^^^^^
11
12This module defines the following :prop_tgt:`IMPORTED` target(s):
13
14<none>
15
16Result variables
17^^^^^^^^^^^^^^^^
18
19This find module will set the following variables in your project:
20
21`` SdlAndroidPlatform_FOUND
22 if false, no Android platform has been found
23
24`` SDL_ANDROID_PLATFORM_ROOT
25 path of the Android SDK platform root directory if found
26
27`` SDL_ANDROID_PLATFORM_ANDROID_JAR
28 path of the Android SDK platform jar file if found
29
30`` SDL_ANDROID_PLATFORM_VERSION
31 the human-readable string containing the android platform version if found
32
33Cache variables
34^^^^^^^^^^^^^^^
35
36These variables may optionally be set to help this module find the correct files:
37
38``SDL_ANDROID_PLATFORM_ROOT``
39 path of the Android SDK platform root directory
40
41
42Variables for locating Android platform
43^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44
45This module responds to the flags:
46
47``SDL_ANDROID_HOME
48 First, this module will look for platforms in this CMake variable.
49
50``ANDROID_HOME
51 If no platform was found in `SDL_ANDROID_HOME`, then try `ANDROID_HOME`.
52
53``$ENV{ANDROID_HOME}
54 If no platform was found in neither `SDL_ANDROID_HOME` or `ANDROID_HOME`, then try `ANDROID_HOME}`
55
56#]=======================================================================]
57
58cmake_minimum_required(VERSION 3.7...3.28)
59
60if(NOT PROJECT_NAME MATCHES "^SDL.*")
61 message(WARNING "This module is internal to SDL and is currently not supported.")
62endif()
63
64function(_sdl_is_valid_android_platform_root RESULT VERSION PLATFORM_ROOT)
65 set(result FALSE)
66 set(version -1)
67
68 string(REGEX MATCH "/android-([0-9]+)$" root_match "${PLATFORM_ROOT}")
69 if(root_match AND EXISTS "${PLATFORM_ROOT}/android.jar")
70 set(result TRUE)
71 set(version "${CMAKE_MATCH_1}")
72 endif()
73
74 set(${RESULT} ${result} PARENT_SCOPE)
75 set(${VERSION} ${version} PARENT_SCOPE)
76endfunction()
77
78function(_sdl_find_android_platform_root ROOT)
79 cmake_parse_arguments(sfapr "" "" "" ${ARGN})
80 set(homes ${SDL_ANDROID_HOME} ${ANDROID_HOME} $ENV{ANDROID_HOME})
81 set(root ${ROOT}-NOTFOUND)
82 foreach(home IN LISTS homes)
83 if(NOT IS_DIRECTORY "${home}")
84 continue()
85 endif()
86 file(GLOB platform_roots LIST_DIRECTORIES true "${home}/platforms/*")
87 set(max_platform_version -1)
88 set(max_platform_root "")
89 foreach(platform_root IN LISTS platform_roots)
90 _sdl_is_valid_android_platform_root(is_valid platform_version "${platform_root}")
91 if(is_valid AND platform_version GREATER max_platform_version)
92 set(max_platform_version "${platform_version}")
93 set(max_platform_root "${platform_root}")
94 endif()
95 endforeach()
96 if(max_platform_version GREATER -1)
97 set(root ${max_platform_root})
98 break()
99 endif()
100 endforeach()
101 set(${ROOT} ${root} PARENT_SCOPE)
102endfunction()
103
104set(SDL_ANDROID_PLATFORM_ANDROID_JAR "SDL_ANDROID_PLATFORM_ANDROID_JAR-NOTFOUND")
105
106if(NOT DEFINED SDL_ANDROID_PLATFORM_ROOT)
107 _sdl_find_android_platform_root(_new_sdl_android_platform_root)
108 set(SDL_ANDROID_PLATFORM_ROOT "${_new_sdl_android_platform_root}" CACHE PATH "Path of Android platform")
109 unset(_new_sdl_android_platform_root)
110endif()
111if(SDL_ANDROID_PLATFORM_ROOT)
112 _sdl_is_valid_android_platform_root(_valid SDL_ANDROID_PLATFORM_VERSION "${SDL_ANDROID_PLATFORM_ROOT}")
113 if(_valid)
114 set(SDL_ANDROID_PLATFORM_ANDROID_JAR "${SDL_ANDROID_PLATFORM_ROOT}/android.jar")
115 endif()
116 unset(_valid)
117endif()
118
119include(FindPackageHandleStandardArgs)
120
121find_package_handle_standard_args(SdlAndroidPlatform
122 VERSION_VAR SDL_ANDROID_PLATFORM_VERSION
123 REQUIRED_VARS SDL_ANDROID_PLATFORM_ROOT SDL_ANDROID_PLATFORM_ANDROID_JAR
124)