Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[build] #5359 cmake android
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Jul 25, 2016
1 parent f31fd6f commit b361c6a
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 14 deletions.
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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:
Expand Down
113 changes: 113 additions & 0 deletions platform/android/config.cmake
Original file line number Diff line number Diff line change
@@ -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
)
24 changes: 10 additions & 14 deletions platform/android/scripts/toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 `mason env CXXFLAGS` \${CMAKE_CXX_FLAGS}\")"
echo "set(CMAKE_C_FLAGS \"-s `mason env CPPFLAGS` \${CMAKE_C_FLAGS}\")"

0 comments on commit b361c6a

Please sign in to comment.