Skip to content

Commit

Permalink
Pass ANDROID_{ABI|NDK|STL|PLATFORM|TOOLCHAIN} variables to cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
CAMOBAP committed Mar 12, 2019
1 parent 7fdd871 commit 79c6ee0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
17 changes: 17 additions & 0 deletions conans/client/build/cmake_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ def _cmake_cross_build_defines(self):
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 'ANDROID_NDK_HOME' in os.environ:
ret["ANDROID_NDK"] = os.environ['ANDROID_NDK_HOME']
elif 'ANDROID_NDK_ROOT' in os.environ:
ret["ANDROID_NDK"] = os.environ['ANDROID_NDK_ROOT']

ret["ANDROID_PLATFORM"] = "android-%s" % op_system_version


logger.info("Setting Cross build flags: %s"
% ", ".join(["%s=%s" % (k, v) for k, v in ret.items()]))
Expand Down Expand Up @@ -301,4 +310,12 @@ 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
2 changes: 1 addition & 1 deletion conans/client/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
version: ["3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "4.0",
"5.0", "6.0", "7.0",
"8"]
libcxx: [libstdc++, libstdc++11, libc++]
libcxx: [libstdc++, libstdc++11, libc++, c++_shared, c++_static]
apple-clang:
version: ["5.0", "5.1", "6.0", "6.1", "7.0", "7.3", "8.0", "8.1", "9.0", "9.1", "10.0"]
libcxx: [libstdc++, libc++]
Expand Down
20 changes: 13 additions & 7 deletions conans/test/unittests/client/build/cmake_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ def test_cores_ancient_visual(self):
def convenient_functions_test(self):
settings = Settings.loads(default_settings_yml)
settings.os = "Android"
settings.os.api_level = 16
settings.os_build = "Windows" # Here we are declaring we are cross building
settings.compiler = "gcc"
settings.compiler.version = "5.4"
Expand All @@ -706,18 +707,22 @@ def convenient_functions_test(self):
cmake = CMake(conan_file)

cross = '-DCMAKE_SYSTEM_NAME="Android"' \
' -DCMAKE_SYSTEM_VERSION="{0}"' \
' -DCMAKE_SYSROOT="/path/to/sysroot"' \
' -DCMAKE_ANDROID_ARCH_ABI="armeabi-v7a"' \
' -DANDROID_ABI="armeabi-v7a"'
' -DANDROID_ABI="armeabi-v7a"' \
' -DANDROID_PLATFORM="android-{0}"'.format(settings.os.api_level)
target_test = CMakeTest.scape('--target test')

cmake.configure()

self.assertEqual('cd {0} && cmake -G "MinGW Makefiles" '
'{1} -DCONAN_EXPORTED="1" -DCONAN_IN_LOCAL_CACHE="OFF"'
' -DCONAN_COMPILER="gcc" -DCONAN_COMPILER_VERSION="5.4"'
' -DCONAN_COMPILER="{2}" -DCONAN_COMPILER_VERSION="{3}"'
' -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON"'
' -Wno-dev {0}'.format(dot_dir, cross),
' -DANDROID_TOOLCHAIN="{2}"'
' -DANDROID_STL="none"'
' -Wno-dev {0}'.format(dot_dir, cross, settings.compiler, settings.compiler.version),
conan_file.command)

cmake.build()
Expand Down Expand Up @@ -752,11 +757,12 @@ def convenient_functions_test(self):
else:
escaped_args = "'--foo \"bar\"' -DSHARED=\"True\" '/source'"

self.assertEqual('cd %s && cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE="Debug" '
'%s -DCONAN_EXPORTED="1" -DCONAN_IN_LOCAL_CACHE="OFF" '
'-DCONAN_COMPILER="gcc" -DCONAN_COMPILER_VERSION="5.4" '
self.assertEqual('cd {0} && cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE="Debug" '
'{1} -DCONAN_EXPORTED="1" -DCONAN_IN_LOCAL_CACHE="OFF" '
'-DCONAN_COMPILER="{2}" -DCONAN_COMPILER_VERSION="{3}" '
'-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" '
'-Wno-dev %s' % (tempdir, cross, escaped_args),
'-DANDROID_TOOLCHAIN="{2}" -DANDROID_STL="none" '
'-Wno-dev {4}'.format(tempdir, cross, settings.compiler, settings.compiler.version, escaped_args),
conan_file.command)

cmake.build(args=["--bar 'foo'"], target="install")
Expand Down

0 comments on commit 79c6ee0

Please sign in to comment.