diff options
-rw-r--r-- | Makefile | 39 | ||||
-rw-r--r-- | platform/android/config.cmake | 113 | ||||
-rwxr-xr-x | platform/android/scripts/toolchain.sh | 24 |
3 files changed, 162 insertions, 14 deletions
@@ -367,6 +367,45 @@ test-node: node npm test npm run test-suite +#### Android targets ########################################################### + +ANDROID_ENV = platform/android/scripts/toolchain.sh +ANDROID_ABIS = arm-v5 arm-v7 arm-v8 x86 x86-64 mips + +define ANDROID_RULES + +build/android-$1/$(BUILDTYPE): $(BUILD_DEPS) + mkdir -p build/android-$1/$(BUILDTYPE) + +build/android-$1/$(BUILDTYPE)/toolchain.cmake: platform/android/scripts/toolchain.sh build/android-$1/$(BUILDTYPE) + $(ANDROID_ENV) $1 > build/android-$1/$(BUILDTYPE)/toolchain.cmake + +build/android-$1/$(BUILDTYPE)/Makefile: build/android-$1/$(BUILDTYPE)/toolchain.cmake platform/android/config.cmake + cd build/android-$1/$(BUILDTYPE) && cmake ../../.. \ + -DCMAKE_TOOLCHAIN_FILE=build/android-$1/$(BUILDTYPE)/toolchain.cmake \ + -DCMAKE_BUILD_TYPE=$(BUILDTYPE) \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DMBGL_PLATFORM=android + +android-lib-$1: build/android-$1/$(BUILDTYPE)/Makefile + $(MAKE) -j$(JOBS) -C build/android-$1/$(BUILDTYPE) all + +android-$1: android-lib-$1 + cd platform/android && ./gradlew --parallel --max-workers=$(JOBS) assemble$(BUILDTYPE) + +apackage: android-lib-$1 +endef + +$(foreach abi,$(ANDROID_ABIS),$(eval $(call ANDROID_RULES,$(abi)))) + +android: android-arm-v7 + +test-android: + cd platform/android && ./gradlew testReleaseUnitTest --continue + +apackage: + cd platform/android && ./gradlew --parallel-threads=$(JOBS) assemble$(BUILDTYPE) + #### Miscellaneous targets ##################################################### style-code: diff --git a/platform/android/config.cmake b/platform/android/config.cmake new file mode 100644 index 0000000000..e4976930f7 --- /dev/null +++ b/platform/android/config.cmake @@ -0,0 +1,113 @@ +#Include to use build specific variables +include(${CMAKE_CURRENT_BINARY_DIR}/toolchain.cmake) + +mason_use(geojson 0.1.4) +mason_use(jni.hpp 2.0.0) +mason_use(libjpeg-turbo 1.4.2) +mason_use(libpng 1.6.20) +mason_use(libzip 0.11.2) +mason_use(nunicode 1.6) +mason_use(sqlite 3.9.1) +mason_use(zlib system) + +macro(mbgl_platform_core) + + target_sources(mbgl-core + # Loop + PRIVATE platform/android/src/thread.cpp + PRIVATE platform/android/src/async_task.cpp + PRIVATE platform/android/src/run_loop.cpp + PRIVATE platform/android/src/timer.cpp + + # File source + PRIVATE platform/android/src/http_file_source.cpp + PRIVATE platform/android/src/asset_file_source.cpp + PRIVATE platform/default/default_file_source.cpp + PRIVATE platform/default/online_file_source.cpp + + # Offline + # PRIVATE include/mbgl/storage/offline.hpp + PRIVATE platform/default/mbgl/storage/offline.cpp + PRIVATE platform/default/mbgl/storage/offline_database.cpp + PRIVATE platform/default/mbgl/storage/offline_database.hpp + PRIVATE platform/default/mbgl/storage/offline_download.cpp + PRIVATE platform/default/mbgl/storage/offline_download.hpp + PRIVATE platform/default/sqlite3.cpp + PRIVATE platform/default/sqlite3.hpp + + # Misc + PRIVATE platform/android/src/native_map_view.cpp + PRIVATE platform/android/src/log_android.cpp + PRIVATE platform/default/string_stdlib.cpp + + # Image handling + PRIVATE platform/default/image.cpp + PRIVATE platform/default/png_reader.cpp + PRIVATE platform/default/jpeg_reader.cpp + + # Headless view + # TODO + ) + + target_include_directories(mbgl-core + PRIVATE platform/default + ) + + target_add_mason_package(mbgl-core PUBLIC sqlite) + target_add_mason_package(mbgl-core PUBLIC nunicode) + target_add_mason_package(mbgl-core PUBLIC libpng) + target_add_mason_package(mbgl-core PUBLIC libjpeg-turbo) + target_add_mason_package(mbgl-core PUBLIC zlib) + target_add_mason_package(mbgl-core PUBLIC libzip) + target_add_mason_package(mbgl-core PUBLIC geojson) + target_add_mason_package(mbgl-core PUBLIC jni.hpp) + + target_link_libraries(mbgl-core + PUBLIC -llog + PUBLIC -landroid + PUBLIC -lEGL + PUBLIC -lGLESv2 + PUBLIC -lstdc++ + PUBLIC -latomic + ) +endmacro() + +add_library(mapbox-gl SHARED + platform/android/src/jni.cpp + platform/android/src/attach_env.cpp +) + +target_link_libraries(mapbox-gl + PUBLIC mbgl-core +) + +add_library(example-custom-layer SHARED + platform/android/src/example_custom_layer.cpp +) + +target_link_libraries(example-custom-layer + PRIVATE mbgl-core +) + +set(ANDROID_SDK_PROJECT_DIR ${CMAKE_SOURCE_DIR}/platform/android/MapboxGLAndroidSDK) +set(ANDROID_JNI_TARGET_DIR ${ANDROID_SDK_PROJECT_DIR}/src/main/jniLibs/${ANDROID_JNIDIR}/) +set(ANDROID_ASSETS_TARGET_DIR ${ANDROID_SDK_PROJECT_DIR}/src/main/assets/) + +add_custom_target(copy-files + DEPENDS mapbox-gl + DEPENDS example-custom-layer + COMMAND ${CMAKE_COMMAND} -E make_directory ${ANDROID_JNI_TARGET_DIR} + COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:mapbox-gl> ${ANDROID_JNI_TARGET_DIR} + COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:example-custom-layer> ${ANDROID_JNI_TARGET_DIR} + COMMAND ${CMAKE_COMMAND} -E make_directory ${ANDROID_ASSETS_TARGET_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/common/ca-bundle.crt ${ANDROID_ASSETS_TARGET_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/platform/default/resources/api_mapbox_com-digicert.der ${ANDROID_ASSETS_TARGET_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/platform/default/resources/api_mapbox_com-geotrust.der ${ANDROID_ASSETS_TARGET_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/platform/default/resources/star_tilestream_net.der ${ANDROID_ASSETS_TARGET_DIR} +) + +add_custom_target(_all ALL + DEPENDS mapbox-gl + DEPENDS example-custom-layer + DEPENDS copy-files +) diff --git a/platform/android/scripts/toolchain.sh b/platform/android/scripts/toolchain.sh index 6eb6a229fe..0f78200803 100755 --- a/platform/android/scripts/toolchain.sh +++ b/platform/android/scripts/toolchain.sh @@ -10,17 +10,13 @@ export MASON_DIR="`pwd`/.mason" export PATH=`mason env PATH` -echo MASON_PLATFORM=\"${MASON_PLATFORM}\" -echo MASON_ANDROID_ABI=\"${MASON_ANDROID_ABI}\" -echo CXX=\"`which $(mason env CXX)`\" -echo CC=\"`which $(mason env CC)`\" -echo LD=\"`which $(mason env LD)`\" -echo LINK=\"`which $(mason env CXX)`\" -echo AR=\"`which $(mason env AR)`\" -echo RANLIB=\"`which $(mason env RANLIB)`\" -echo STRIP=\"`which $(mason env STRIP)`\" -echo LDFLAGS=\"`mason env LDFLAGS` \${LDFLAGS:-}\" -echo CFLAGS=\"`mason env CFLAGS` \${CFLAGS:-}\" -echo CXXFLAGS=\"`mason env CXXFLAGS` \${CXXFLAGS:-}\" -echo CPPFLAGS=\"`mason env CPPFLAGS` \${CPPFLAGS:-}\" -echo JNIDIR=\"`mason env JNIDIR`\" +echo "set(CMAKE_SYSTEM_NAME Android)" +echo "set(CMAKE_SYSTEM_VERSION 1)" +echo "set(CMAKE_CXX_COMPILER \"`which $(mason env CXX)`\")" +echo "set(CMAKE_C_COMPILER \"`which $(mason env CC)`\")" +echo "set(ANDROID_JNIDIR \"`mason env JNIDIR`\")" +echo "set(ANDROID_ABI \"${1:-arm-v7}\")" +echo "set(ENV{MASON_ANDROID_ABI} \"${1:-arm-v7}\")" +echo "set(CMAKE_EXE_LINKER_FLAGS \"`mason env LDFLAGS` \${CMAKE_EXE_LINKER_FLAGS}\")" +echo "set(CMAKE_CXX_FLAGS \"-s -fvisibility=hidden -Os `mason env CXXFLAGS` \${CMAKE_CXX_FLAGS}\")" +echo "set(CMAKE_C_FLAGS \"-s -fvisibility=hidden -Os `mason env CPPFLAGS` \${CMAKE_C_FLAGS}\")" |