Repository: conan-io/conan

Issue:
Conan does not set define `CMAKE_SYSTEM_VERSION` when "os.api_level" specified

Discussion:

Patch:
diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py
index babb8f0e7..2702d2b9e 100644
--- a/conans/client/build/cmake.py
+++ b/conans/client/build/cmake.py
@@ -53,7 +53,10 @@ class CMake(object):
         self._compiler = self._settings.get_safe("compiler")
         self._compiler_version = self._settings.get_safe("compiler.version")
         self._arch = self._settings.get_safe("arch")
-        self._op_system_version = self._settings.get_safe("os.version")
+
+        os_ver_str = "os.api_level" if self._os == "Android" else "os.version"
+        self._op_system_version = self._settings.get_safe(os_ver_str)
+
         self._libcxx = self._settings.get_safe("compiler.libcxx")
         self._runtime = self._settings.get_safe("compiler.runtime")
         self._build_type = self._settings.get_safe("build_type")


Test patch:
diff --git a/conans/test/build_helpers/cmake_test.py b/conans/test/build_helpers/cmake_test.py
index b7f6cd6c3..85d1ba227 100644
--- a/conans/test/build_helpers/cmake_test.py
+++ b/conans/test/build_helpers/cmake_test.py
@@ -773,6 +773,27 @@ build_type: [ Release]
         cmake = CMake(conan_file)
         self.assertIn('-T "v140"', cmake.command_line)
 
+    def test_cmake_system_version_android(self):
+        with tools.environment_append({"CONAN_CMAKE_SYSTEM_NAME": "SomeSystem",
+                                       "CONAN_CMAKE_GENERATOR": "SomeGenerator"}):
+            settings = Settings.loads(default_settings_yml)
+            settings.os = "WindowsStore"
+            settings.os.version = "8.1"
+
+            conan_file = ConanFileMock()
+            conan_file.settings = settings
+            cmake = CMake(conan_file)
+            self.assertEquals(cmake.definitions["CMAKE_SYSTEM_VERSION"], "8.1")
+
+            settings = Settings.loads(default_settings_yml)
+            settings.os = "Android"
+            settings.os.api_level = "32"
+
+            conan_file = ConanFileMock()
+            conan_file.settings = settings
+            cmake = CMake(conan_file)
+            self.assertEquals(cmake.definitions["CMAKE_SYSTEM_VERSION"], "32")
+
     @staticmethod
     def scape(args):
         pattern = "%s" if sys.platform == "win32" else r"'%s'"