mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
Merge pull request #17474 from komakai:ndk-side-by-side
This commit is contained in:
commit
b03ed532cf
@ -109,6 +109,10 @@ def copytree_smart(src, dst):
|
|||||||
shutil.copy2(s, d)
|
shutil.copy2(s, d)
|
||||||
copy_recurse('')
|
copy_recurse('')
|
||||||
|
|
||||||
|
def get_highest_version(subdirs):
|
||||||
|
return max(subdirs, key=lambda dir: [int(comp) for comp in os.path.split(dir)[-1].split('.')])
|
||||||
|
|
||||||
|
|
||||||
#===================================================================================================
|
#===================================================================================================
|
||||||
|
|
||||||
class ABI:
|
class ABI:
|
||||||
@ -162,8 +166,8 @@ class Builder:
|
|||||||
if os.path.exists(android_cmake):
|
if os.path.exists(android_cmake):
|
||||||
cmake_subdirs = [f for f in os.listdir(android_cmake) if check_executable([os.path.join(android_cmake, f, 'bin', 'cmake'), '--version'])]
|
cmake_subdirs = [f for f in os.listdir(android_cmake) if check_executable([os.path.join(android_cmake, f, 'bin', 'cmake'), '--version'])]
|
||||||
if len(cmake_subdirs) > 0:
|
if len(cmake_subdirs) > 0:
|
||||||
# there could be more than one - just take the first one
|
# there could be more than one - get the most recent
|
||||||
cmake_from_sdk = os.path.join(android_cmake, cmake_subdirs[0], 'bin', 'cmake')
|
cmake_from_sdk = os.path.join(android_cmake, get_highest_version(cmake_subdirs), 'bin', 'cmake')
|
||||||
log.info("Using cmake from Android SDK: %s", cmake_from_sdk)
|
log.info("Using cmake from Android SDK: %s", cmake_from_sdk)
|
||||||
return cmake_from_sdk
|
return cmake_from_sdk
|
||||||
raise Fail("Can't find cmake")
|
raise Fail("Can't find cmake")
|
||||||
@ -311,6 +315,22 @@ class Builder:
|
|||||||
else:
|
else:
|
||||||
shutil.move(src, dst)
|
shutil.move(src, dst)
|
||||||
|
|
||||||
|
def get_ndk_dir():
|
||||||
|
# look to see if Android NDK is installed
|
||||||
|
android_sdk_ndk = os.path.join(os.environ["ANDROID_SDK"], 'ndk')
|
||||||
|
android_sdk_ndk_bundle = os.path.join(os.environ["ANDROID_SDK"], 'ndk-bundle')
|
||||||
|
if os.path.exists(android_sdk_ndk):
|
||||||
|
ndk_subdirs = [f for f in os.listdir(android_sdk_ndk) if os.path.exists(os.path.join(android_sdk_ndk, f, 'package.xml'))]
|
||||||
|
if len(ndk_subdirs) > 0:
|
||||||
|
# there could be more than one - get the most recent
|
||||||
|
ndk_from_sdk = os.path.join(android_sdk_ndk, get_highest_version(ndk_subdirs))
|
||||||
|
log.info("Using NDK (side-by-side) from Android SDK: %s", ndk_from_sdk)
|
||||||
|
return ndk_from_sdk
|
||||||
|
if os.path.exists(os.path.join(android_sdk_ndk_bundle, 'package.xml')):
|
||||||
|
log.info("Using NDK bundle from Android SDK: %s", android_sdk_ndk_bundle)
|
||||||
|
return android_sdk_ndk_bundle
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
#===================================================================================================
|
#===================================================================================================
|
||||||
|
|
||||||
@ -349,12 +369,20 @@ if __name__ == "__main__":
|
|||||||
raise Fail("SDK location not set. Either pass --sdk_path or set ANDROID_SDK environment variable")
|
raise Fail("SDK location not set. Either pass --sdk_path or set ANDROID_SDK environment variable")
|
||||||
|
|
||||||
# look for an NDK installed with the Android SDK
|
# look for an NDK installed with the Android SDK
|
||||||
if not 'ANDROID_NDK' in os.environ and 'ANDROID_SDK' in os.environ and os.path.exists(os.path.join(os.environ["ANDROID_SDK"], 'ndk-bundle')):
|
if not 'ANDROID_NDK' in os.environ and 'ANDROID_SDK' in os.environ:
|
||||||
os.environ['ANDROID_NDK'] = os.path.join(os.environ["ANDROID_SDK"], 'ndk-bundle')
|
sdk_ndk_dir = get_ndk_dir()
|
||||||
|
if sdk_ndk_dir:
|
||||||
|
os.environ['ANDROID_NDK'] = sdk_ndk_dir
|
||||||
|
|
||||||
if not 'ANDROID_NDK' in os.environ:
|
if not 'ANDROID_NDK' in os.environ:
|
||||||
raise Fail("NDK location not set. Either pass --ndk_path or set ANDROID_NDK environment variable")
|
raise Fail("NDK location not set. Either pass --ndk_path or set ANDROID_NDK environment variable")
|
||||||
|
|
||||||
|
show_samples_build_warning = False
|
||||||
|
#also set ANDROID_NDK_HOME (needed by the gradle build)
|
||||||
|
if not 'ANDROID_NDK_HOME' in os.environ and 'ANDROID_NDK' in os.environ:
|
||||||
|
os.environ['ANDROID_NDK_HOME'] = os.environ["ANDROID_NDK"]
|
||||||
|
show_samples_build_warning = True
|
||||||
|
|
||||||
if not check_executable(['ccache', '--version']):
|
if not check_executable(['ccache', '--version']):
|
||||||
log.info("ccache not found - disabling ccache support")
|
log.info("ccache not found - disabling ccache support")
|
||||||
args.no_ccache = True
|
args.no_ccache = True
|
||||||
@ -411,5 +439,8 @@ if __name__ == "__main__":
|
|||||||
log.info("=====")
|
log.info("=====")
|
||||||
log.info("===== Build finished")
|
log.info("===== Build finished")
|
||||||
log.info("=====")
|
log.info("=====")
|
||||||
|
if show_samples_build_warning:
|
||||||
|
#give a hint how to solve "Gradle sync failed: NDK not configured."
|
||||||
|
log.info("ANDROID_NDK_HOME environment variable required by the samples project is not set")
|
||||||
log.info("SDK location: %s", builder.resultdest)
|
log.info("SDK location: %s", builder.resultdest)
|
||||||
log.info("Documentation location: %s", builder.docdest)
|
log.info("Documentation location: %s", builder.docdest)
|
||||||
|
Loading…
Reference in New Issue
Block a user