提交 f76207d3 编写于 作者: L liyin 提交者: 叶剑武

Used shared libc library

上级 61c71eaa
...@@ -24,12 +24,11 @@ ExternalProject_Add( ...@@ -24,12 +24,11 @@ ExternalProject_Add(
UPDATE_COMMAND "" UPDATE_COMMAND ""
BUILD_BYPRODUCTS ${GFLAGS_LIBRARIES} BUILD_BYPRODUCTS ${GFLAGS_LIBRARIES}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GFLAGS_INSTALL_DIR} CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GFLAGS_INSTALL_DIR}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
-DBUILD_STATIC_LIBS=ON -DBUILD_STATIC_LIBS=ON
-DBUILD_TESTING=OFF -DBUILD_TESTING=OFF
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_BUILD_TYPE=Release
-DCMAKE_GENERATOR=${CMAKE_GENERATOR} -DCMAKE_GENERATOR=${CMAKE_GENERATOR}
${THIRD_PARTY_EXTRA_CMAKE_ARGS} ${THIRD_PARTY_EXTRA_CMAKE_ARGS}
) )
......
...@@ -33,7 +33,7 @@ ExternalProject_Add( ...@@ -33,7 +33,7 @@ ExternalProject_Add(
BUILD_BYPRODUCTS ${PROTOBUF_LITE_LIBRARIES} BUILD_BYPRODUCTS ${PROTOBUF_LITE_LIBRARIES}
SOURCE_DIR "${PROTOBUF_SRCS_DIR}/src/protobuf" SOURCE_DIR "${PROTOBUF_SRCS_DIR}/src/protobuf"
CONFIGURE_COMMAND ${CMAKE_COMMAND} ../protobuf/cmake/ CONFIGURE_COMMAND ${CMAKE_COMMAND} ../protobuf/cmake/
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
-DCMAKE_INSTALL_PREFIX=${PROTOBUF_INSTALL_DIR} -DCMAKE_INSTALL_PREFIX=${PROTOBUF_INSTALL_DIR}
......
...@@ -5,7 +5,8 @@ rm -rf mace/codegen/engine ...@@ -5,7 +5,8 @@ rm -rf mace/codegen/engine
rm -rf mace/codegen/opencl rm -rf mace/codegen/opencl
for d in build/*; do for d in build/*; do
if [[ "$d" != "build/cmake-build*" ]]; then if [[ "$d" != "build/cmake-build" ]]; then
echo "remove $d"
rm -rf "$d" rm -rf "$d"
fi fi
done done
#!/usr/bin/env sh
set -e
# build for arm linux aarch64
BUILD_DIR=cmake-build/aarch64-linux-gnu-full
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DCROSSTOOL_ROOT=${LINARO_AARCH64_LINUX_GNU} \
-DCMAKE_TOOLCHAIN_FILE=../../cmake/toolchains/aarch64-linux-gnu.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=ON \
-DMACE_ENABLE_OPENCL=ON \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android arm64-v8a
BUILD_DIR=cmake-build/android-arm64-v8a-cpu
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DANDROID_ABI="arm64-v8a" \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_NATIVE_API_LEVEL=14 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=OFF \
-DMACE_ENABLE_OPENCL=OFF \
-DMACE_ENABLE_HEXAGON_DSP=OFF \
-DMACE_ENABLE_HEXAGON_HTA=OFF \
-DMACE_ENABLE_MTK_APU=OFF \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android arm64-v8a
BUILD_DIR=cmake-build/android-arm64-v8a-full
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DANDROID_ABI="arm64-v8a" \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_NATIVE_API_LEVEL=28 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=ON \
-DMACE_ENABLE_OPENCL=ON \
-DMACE_ENABLE_HEXAGON_DSP=ON \
-DMACE_ENABLE_HEXAGON_HTA=OFF \
-DMACE_ENABLE_MTK_APU=ON \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android armeabi-v7a
BUILD_DIR=cmake-build/android-armeabi-v7a-cpu
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DANDROID_ABI="armeabi-v7a" \
-DANDROID_ARM_NEON=ON \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_NATIVE_API_LEVEL=14 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=OFF \
-DMACE_ENABLE_OPENCL=OFF \
-DMACE_ENABLE_HEXAGON_DSP=OFF \
-DMACE_ENABLE_HEXAGON_HTA=OFF \
-DMACE_ENABLE_MTK_APU=OFF \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for android armeabi-v7a
BUILD_DIR=cmake-build/android-armeabi-v7a-full
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DANDROID_ABI="armeabi-v7a" \
-DANDROID_ARM_NEON=ON \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_NATIVE_API_LEVEL=28 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=ON \
-DMACE_ENABLE_OPENCL=ON \
-DMACE_ENABLE_HEXAGON_DSP=ON \
-DMACE_ENABLE_HEXAGON_HTA=OFF \
-DMACE_ENABLE_MTK_APU=OFF \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for arm linux gnueabihf
BUILD_DIR=cmake-build/arm-linux-gnueabihf-full
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DCROSSTOOL_ROOT=${LINARO_ARM_LINUX_GNUEABIHF} \
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/arm-linux-gnueabihf.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=ON \
-DMACE_ENABLE_OPENCL=ON \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for host
BUILD_DIR=cmake-build/host
rm -rf ${BUILD_DIR} && mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
cmake -DMACE_ENABLE_NEON=OFF \
-DMACE_ENABLE_QUANTIZE=OFF \
-DMACE_ENABLE_OPENCL=ON \
-DCMAKE_INSTALL_PREFIX=install \
../..
make -j6 VERBOSE=1 && make install
cd ../..
#!/usr/bin/env sh
set -e
# build for local host
sh tools/cmake-build-host.sh
# Nuild for Android arm64-v8a with NEON
sh tools/cmake-build-android-arm64-v8a-cpu.sh
# Build for Android arm64-v8a with NEON, Quantize, OpenCL, Hexagon HTA, Hexagon DSP
sh tools/cmake-build-android-arm64-v8a-full.sh
# Nuild for Android armeabi-v7a with NEON
sh tools/cmake-build-android-armeabi-v7a-cpu.sh
# Build for Android armeabi-v7a with NEON, Quantize, OpenCL, Hexagon HTA, Hexagon DSP
sh tools/cmake-build-android-armeabi-v7a-full.sh
# Build for arm-linux-gnueabihf with NEON, Quantize, OpenCL
sh tools/cmake-build-arm-linux-gnueabihf-full.sh
# Build for aarch64-linux-gnu with NEON, Quantize, OpenCL
sh tools/cmake-build-aarch64-linux-gnu-full.sh
...@@ -31,7 +31,7 @@ cmake -DANDROID_ABI="arm64-v8a" \ ...@@ -31,7 +31,7 @@ cmake -DANDROID_ABI="arm64-v8a" \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_NATIVE_API_LEVEL=28 \ -DANDROID_NATIVE_API_LEVEL=28 \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \ -DANDROID_STL=c++_shared \
-DMACE_ENABLE_NEON=ON \ -DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=ON \ -DMACE_ENABLE_QUANTIZE=ON \
-DMACE_ENABLE_OPENCL=${MACE_ENABLE_OPENCL} \ -DMACE_ENABLE_OPENCL=${MACE_ENABLE_OPENCL} \
......
...@@ -33,7 +33,7 @@ cmake -DANDROID_ABI="armeabi-v7a" \ ...@@ -33,7 +33,7 @@ cmake -DANDROID_ABI="armeabi-v7a" \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \
-DANDROID_NATIVE_API_LEVEL=28 \ -DANDROID_NATIVE_API_LEVEL=28 \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ANDROID_STL_TYPE=c++_shared \ -DANDROID_STL=c++_shared \
-DMACE_ENABLE_NEON=ON \ -DMACE_ENABLE_NEON=ON \
-DMACE_ENABLE_QUANTIZE=ON \ -DMACE_ENABLE_QUANTIZE=ON \
-DMACE_ENABLE_OPENCL=${MACE_ENABLE_OPENCL} \ -DMACE_ENABLE_OPENCL=${MACE_ENABLE_OPENCL} \
......
...@@ -48,7 +48,7 @@ def run_target(target_abi, install_dir, target_obj, device_ids="all"): ...@@ -48,7 +48,7 @@ def run_target(target_abi, install_dir, target_obj, device_ids="all"):
# reinstall target # reinstall target
print("Install target from %s to %s" % (target_obj.path, install_dir)) print("Install target from %s to %s" % (target_obj.path, install_dir))
device_target = dev.install(target_obj, install_dir) device_target = dev.install(target_obj, install_dir, install_deps=True)
print(device_target) print(device_target)
# run on device # run on device
......
...@@ -16,6 +16,7 @@ from __future__ import absolute_import ...@@ -16,6 +16,7 @@ from __future__ import absolute_import
from __future__ import division from __future__ import division
from __future__ import print_function from __future__ import print_function
import copy
import os import os
import re import re
import subprocess import subprocess
...@@ -60,10 +61,11 @@ def execute(cmd, verbose=True): ...@@ -60,10 +61,11 @@ def execute(cmd, verbose=True):
class Device(object): class Device(object):
def __init__(self, device_id): def __init__(self, device_id, target_abi):
self._device_id = device_id self._device_id = device_id
self._target_abi = target_abi
def install(self, target, install_dir): def install(self, target, install_dir, install_deps=False):
pass pass
def run(self, target): def run(self, target):
...@@ -80,14 +82,14 @@ class Device(object): ...@@ -80,14 +82,14 @@ class Device(object):
class HostDevice(Device): class HostDevice(Device):
def __init__(self, device_id): def __init__(self, device_id, target_abi):
super(HostDevice, self).__init__(device_id) super(HostDevice, self).__init__(device_id, target_abi)
@staticmethod @staticmethod
def list_devices(): def list_devices():
return ["host"] return ["host"]
def install(self, target, install_dir): def install(self, target, install_dir, install_deps=False):
install_dir = os.path.abspath(install_dir) install_dir = os.path.abspath(install_dir)
if install_dir.strip() and install_dir != os.path.dirname(target.path): if install_dir.strip() and install_dir != os.path.dirname(target.path):
...@@ -119,8 +121,8 @@ class HostDevice(Device): ...@@ -119,8 +121,8 @@ class HostDevice(Device):
class AndroidDevice(Device): class AndroidDevice(Device):
def __init__(self, device_id): def __init__(self, device_id, target_abi):
super(AndroidDevice, self).__init__(device_id) super(AndroidDevice, self).__init__(device_id, target_abi)
@staticmethod @staticmethod
def list_devices(): def list_devices():
...@@ -134,7 +136,7 @@ class AndroidDevice(Device): ...@@ -134,7 +136,7 @@ class AndroidDevice(Device):
return devices return devices
def install(self, target, install_dir): def install(self, target, install_dir, install_deps=False):
install_dir = os.path.abspath(install_dir) install_dir = os.path.abspath(install_dir)
sn = self._device_id sn = self._device_id
...@@ -149,12 +151,36 @@ class AndroidDevice(Device): ...@@ -149,12 +151,36 @@ class AndroidDevice(Device):
for lib in target.libs: for lib in target.libs:
execute("adb -s %s push %s %s" % (sn, lib, install_dir), False) execute("adb -s %s push %s %s" % (sn, lib, install_dir), False)
target.path = "%s/%s" % (install_dir, os.path.basename(target.path)) device_target = copy.deepcopy(target)
target.libs = ["%s/%s" % (install_dir, os.path.basename(lib)) device_target.path = "%s/%s" % (install_dir,
os.path.basename(target.path))
device_target.libs = ["%s/%s" % (install_dir, os.path.basename(lib))
for lib in target.libs] for lib in target.libs]
target.envs.append("LD_LIBRARY_PATH=%s" % install_dir) device_target.envs.append("LD_LIBRARY_PATH=%s" % install_dir)
return target if install_deps:
self.install_common_libs_for_target(target, install_dir)
return device_target
def install_common_libs_for_target(self, target, install_dir):
sn = self._device_id
dep_so_libs = execute(os.environ["ANDROID_NDK_HOME"] + "/ndk-depends "
+ target.path)
lib_file = ""
for dep in dep_so_libs.split("\n"):
if dep == "libgnustl_shared.so":
lib_file = "%s/sources/cxx-stl/gnu-libstdc++/4.9/libs/" \
"%s/libgnustl_shared.so" \
% (os.environ["ANDROID_NDK_HOME"], self._target_abi)
elif dep == "libc++_shared.so":
lib_file = "%s/sources/cxx-stl/llvm-libc++/libs/" \
"%s/libc++_shared.so" \
% (os.environ["ANDROID_NDK_HOME"], self._target_abi)
if lib_file:
execute("adb -s %s push %s %s" % (sn, lib_file, install_dir),
False)
def run(self, target): def run(self, target):
tmpdirname = tempfile.mkdtemp() tmpdirname = tempfile.mkdtemp()
...@@ -198,8 +224,8 @@ class AndroidDevice(Device): ...@@ -198,8 +224,8 @@ class AndroidDevice(Device):
class ArmLinuxDevice(Device): class ArmLinuxDevice(Device):
devices = {} devices = {}
def __init__(self, device_id): def __init__(self, device_id, target_abi):
super(ArmLinuxDevice, self).__init__(device_id) super(ArmLinuxDevice, self).__init__(device_id, target_abi)
@staticmethod @staticmethod
def list_devices(): def list_devices():
...@@ -215,7 +241,7 @@ class ArmLinuxDevice(Device): ...@@ -215,7 +241,7 @@ class ArmLinuxDevice(Device):
def set_devices(devices): def set_devices(devices):
ArmLinuxDevice.devices = devices ArmLinuxDevice.devices = devices
def install(self, target, install_dir): def install(self, target, install_dir, install_deps=False):
install_dir = os.path.abspath(install_dir) install_dir = os.path.abspath(install_dir)
ip = self._device_id ip = self._device_id
...@@ -260,7 +286,7 @@ def device_class(target_abi): ...@@ -260,7 +286,7 @@ def device_class(target_abi):
def crete_device(target_abi, device_id=None): def crete_device(target_abi, device_id=None):
return device_class(target_abi)(device_id) return device_class(target_abi)(device_id, target_abi)
def choose_devices(target_abi, target_ids): def choose_devices(target_abi, target_ids):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册