Repository: conan-io/conan

Issue:
Review Android variables and document the new libcxx
The purpose of this issue is to create a new PR with the small revisions on PR #4538:

- Rename `CONAN_CMAKE_ANDROID_NDK_HOME` to `CONAN_CMAKE_ANDROID_NDK` to follow the same name as in CMake: https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling-for-android

- Check if `CMAKE_SYSTEM_NAME` is Android before adjusting anything.

- Move code setting CMake vairables to ``def _cmake_cross_build_defines()``

- Remove unneeded imports

- Document settings of libcxx: ``c++_shared``, ``c++_static``

- Document ``CONAN_CMAKE_ANDROID_NDK``





Discussion:

Resolving patch:
diff --git a/conans/client/build/cmake_flags.py b/conans/client/build/cmake_flags.py
--- a/conans/client/build/cmake_flags.py
+++ b/conans/client/build/cmake_flags.py
@@ -174,6 +174,8 @@ def _cmake_cross_build_defines(self):
         cmake_system_name = env_sn or self._forced_cmake_system_name
 
         os_build, _, _, _ = get_cross_building_settings(self._conanfile.settings)
+        compiler = self._ss("compiler")
+        libcxx = self._ss("compiler.libcxx")
 
         ret = OrderedDict()
         os_ver = get_env("CONAN_CMAKE_SYSTEM_VERSION", op_system_version)
@@ -231,17 +233,25 @@ def _cmake_cross_build_defines(self):
                 ret["CMAKE_SYSROOT"] = sysroot_path.replace("\\", "/")
 
             # Adjust Android stuff
-            if os_ == "Android":
+            if str(os_) == "Android" and ret["CMAKE_SYSTEM_NAME"] == "Android":
                 arch_abi_settings = tools.to_android_abi(arch)
                 if arch_abi_settings:
                     ret["CMAKE_ANDROID_ARCH_ABI"] = arch_abi_settings
                     ret["ANDROID_ABI"] = arch_abi_settings
 
-                if 'CONAN_CMAKE_ANDROID_NDK_HOME' in os.environ:
-                    ret["ANDROID_NDK"] = os.environ['CONAN_CMAKE_ANDROID_NDK_HOME']
+                conan_cmake_android_ndk = os.getenv("CONAN_CMAKE_ANDROID_NDK")
+                if conan_cmake_android_ndk:
+                    ret["ANDROID_NDK"] = conan_cmake_android_ndk
 
                 ret["ANDROID_PLATFORM"] = "android-%s" % op_system_version
+                ret["ANDROID_TOOLCHAIN"] = compiler
 
+                # More details about supported stdc++ libraries here:
+                # https://developer.android.com/ndk/guides/cpp-support.html
+                if libcxx:
+                    ret["ANDROID_STL"] = libcxx
+                else:
+                    ret["ANDROID_STL"] = 'none'
 
         logger.info("Setting Cross build flags: %s"
                     % ", ".join(["%s=%s" % (k, v) for k, v in ret.items()]))
@@ -357,13 +367,4 @@ def get_definitions(self):
 
         # Disable CMake export registry #3070 (CMake installing modules in user home's)
         ret["CMAKE_EXPORT_NO_PACKAGE_REGISTRY"] = "ON"
-
-        if os_ == "Android":
-            ret["ANDROID_TOOLCHAIN"] = compiler
-            # More details about supported stdc++ libraries here https://developer.android.com/ndk/guides/cpp-support.html
-            if libcxx:
-                ret["ANDROID_STL"] = libcxx
-            else:
-                ret["ANDROID_STL"] = 'none'
-
         return ret
diff --git a/conans/client/tools/__init__.py b/conans/client/tools/__init__.py
--- a/conans/client/tools/__init__.py
+++ b/conans/client/tools/__init__.py
@@ -1,9 +1,8 @@
-
-# noinspection PyUnresolvedReferences
 # noinspection PyUnresolvedReferences
 from .android import *
 # noinspection PyUnresolvedReferences
 from .apple import *
+# noinspection PyUnresolvedReferences
 from .env import *
 # noinspection PyUnresolvedReferences
 from .files import *
@@ -19,4 +18,3 @@
 from .system_pm import *
 # noinspection PyUnresolvedReferences
 from .win import *
-
diff --git a/conans/client/tools/android.py b/conans/client/tools/android.py
--- a/conans/client/tools/android.py
+++ b/conans/client/tools/android.py
@@ -1,7 +1,3 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-import os
-import subprocess
 
 
 def to_android_abi(arch):


Test patch:
diff --git a/conans/test/unittests/client/build/cmake_test.py b/conans/test/unittests/client/build/cmake_test.py
--- a/conans/test/unittests/client/build/cmake_test.py
+++ b/conans/test/unittests/client/build/cmake_test.py
@@ -331,7 +331,7 @@ def assert_fpic(the_settings, input_shared, input_fpic, expected_option):
             cmake.configure()
             if expected_option is not None:
                 self.assertEqual(cmake.definitions["CONAN_CMAKE_POSITION_INDEPENDENT_CODE"],
-                                  expected_option)
+                                 expected_option)
             else:
                 self.assertNotIn("CONAN_CMAKE_POSITION_INDEPENDENT_CODE", cmake.definitions)
 
@@ -856,7 +856,9 @@ def convenient_functions_test(self):
                 ' -DCMAKE_SYSROOT="/path/to/sysroot"' \
                 ' -DCMAKE_ANDROID_ARCH_ABI="armeabi-v7a"' \
                 ' -DANDROID_ABI="armeabi-v7a"' \
-                ' -DANDROID_PLATFORM="android-{0}"'.format(settings.os.api_level)
+                ' -DANDROID_PLATFORM="android-{0}"' \
+                ' -DANDROID_TOOLCHAIN="{1}"' \
+                ' -DANDROID_STL="none"'.format(settings.os.api_level, settings.compiler)
         target_test = CMakeTest.scape('--target test')
 
         cmake.configure()
@@ -865,9 +867,8 @@ def convenient_functions_test(self):
                          '{1} -DCONAN_EXPORTED="1" -DCONAN_IN_LOCAL_CACHE="OFF"'
                          ' -DCONAN_COMPILER="{2}" -DCONAN_COMPILER_VERSION="{3}"'
                          ' -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON"'
-                         ' -DANDROID_TOOLCHAIN="{2}"'
-                         ' -DANDROID_STL="none"'
-                         ' -Wno-dev {0}'.format(dot_dir, cross, settings.compiler, settings.compiler.version),
+                         ' -Wno-dev {0}'.format(dot_dir, cross, settings.compiler,
+                                                settings.compiler.version),
                          conan_file.command)
 
         cmake.build()
@@ -906,8 +907,8 @@ def convenient_functions_test(self):
                          '{1} -DCONAN_EXPORTED="1" -DCONAN_IN_LOCAL_CACHE="OFF" '
                          '-DCONAN_COMPILER="{2}" -DCONAN_COMPILER_VERSION="{3}" '
                          '-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" '
-                         '-DANDROID_TOOLCHAIN="{2}" -DANDROID_STL="none" '
-                         '-Wno-dev {4}'.format(tempdir, cross, settings.compiler, settings.compiler.version, escaped_args),
+                         '-Wno-dev {4}'.format(tempdir, cross, settings.compiler,
+                                               settings.compiler.version, escaped_args),
                          conan_file.command)
 
         cmake.build(args=["--bar 'foo'"], target="install")
diff --git a/conans/test/unittests/util/android_test.py b/conans/test/unittests/util/android_test.py
--- a/conans/test/unittests/util/android_test.py
+++ b/conans/test/unittests/util/android_test.py
@@ -1,8 +1,3 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-import os
-import platform
 import unittest
 
 from conans.client import tools