Skip to content

Commit

Permalink
Merge pull request #1955 from tangrams/mbtiles-build-options
Browse files Browse the repository at this point in the history
Add TANGRAM_MBTILES_DATASOURCE and TANGRAM_USE_SYSTEM_SQLITE_LIBS build options
  • Loading branch information
hjanetzek authored Dec 7, 2018
2 parents b4db37e + e8bfdff commit 014c3c5
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 42 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ option(TANGRAM_USE_JSCORE_STATIC "Build with pre-compiled static libraries for J

option(TANGRAM_USE_SYSTEM_FONT_LIBS "Use system libraries Freetype, ICU and Harfbuzz via pkgconfig" OFF)
option(TANGRAM_USE_SYSTEM_GLFW_LIBS "Use system libraries for GLFW3 via pkgconfig" OFF)
option(TANGRAM_USE_SYSTEM_SQLITE_LIBS "Use system libraries for SQLite via pkgconfig" OFF)
option(TANGRAM_MBTILES_DATASOURCE "Build MBTiles Datasource" ON)

option(TANGRAM_BUILD_TESTS "Build unit tests" OFF)
option(TANGRAM_BUNDLE_TESTS "Compile all tests into a single binary" ON)
Expand Down
31 changes: 17 additions & 14 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ add_library(tangram-core
src/map.cpp
src/platform.cpp
src/data/clientGeoJsonSource.cpp
src/data/mbtilesDataSource.cpp
src/data/memoryCacheDataSource.cpp
src/data/networkDataSource.cpp
src/data/properties.cpp
Expand Down Expand Up @@ -126,6 +125,17 @@ target_include_directories(tangram-core
deps/double-conversion/include
)

# Link core library dependencies.
target_link_libraries(tangram-core
PRIVATE
css-color-parser-cpp
yaml-cpp
alfons
double-conversion
miniz
z
)

# Add JavaScript implementation.
if(TANGRAM_JSCORE_ENABLED)
target_sources(tangram-core PRIVATE src/js/JSCoreContext.cpp)
Expand All @@ -140,19 +150,12 @@ else()
target_link_libraries(tangram-core PRIVATE duktape)
endif()

# Link core library dependencies.
target_link_libraries(tangram-core
PRIVATE
css-color-parser-cpp
yaml-cpp
alfons
SQLiteCpp
sqlite3
double-conversion
miniz
z
)

# Add MBTiles implementation.
if(TANGRAM_MBTILES_DATASOURCE)
target_sources(tangram-core PRIVATE src/data/mbtilesDataSource.cpp)
target_link_libraries(tangram-core PRIVATE SQLiteCpp sqlite3)
target_compile_definitions(tangram-core PRIVATE TANGRAM_MBTILES_DATASOURCE=1)
endif()

if(UNIX AND NOT APPLE)
# SQLite needs dl dynamic library loader when Linux
Expand Down
38 changes: 22 additions & 16 deletions core/deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,29 @@ endif()
set(GLM_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glm)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/alfons)

## SQLiteCpp ##
###############
set(SQLITECPP_RUN_CPPLINT OFF CACHE BOOL "")
set(SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "")
set(SQLITE_ENABLE_COLUMN_METADATA OFF CACHE BOOL "")

add_subdirectory(SQLiteCpp)

# Extensions aren't needed for MBTiles and aren't available in older versions of sqlite3.
target_compile_definitions(SQLiteCpp PRIVATE SQLITE_OMIT_LOAD_EXTENSION)

# needed for sqlite3 to work for ndk15c+ and android api level < 21
# refer:
# https://github.com/android-ndk/ndk/issues/477 and
# https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
if (ANDROID)
if (TANGRAM_MBTILES_DATASOURCE)
## SQLiteCpp ##
###############
set(SQLITECPP_RUN_CPPLINT OFF CACHE BOOL "")
set(SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "")
set(SQLITE_ENABLE_COLUMN_METADATA OFF CACHE BOOL "")

if (TANGRAM_USE_SYSTEM_SQLITE_LIBS)
set(SQLITECPP_INTERNAL_SQLITE OFF CACHE BOOL "")
endif()

add_subdirectory(SQLiteCpp)

# Extensions aren't needed for MBTiles and aren't available in older versions of sqlite3.
target_compile_definitions(SQLiteCpp PRIVATE SQLITE_OMIT_LOAD_EXTENSION)

# needed for sqlite3 to work for ndk15c+ and android api level < 21
# refer:
# https://github.com/android-ndk/ndk/issues/477 and
# https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
if (ANDROID)
target_compile_definitions(sqlite3 PRIVATE _FILE_OFFSET_BITS=32)
endif()
endif()

## double-conversion ##
Expand Down
4 changes: 4 additions & 0 deletions core/src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,12 @@ SceneID Map::updateSceneAsync(const std::vector<SceneUpdate>& _sceneUpdates) {
}

void Map::setMBTiles(const char* _dataSourceName, const char* _mbtilesFilePath) {
#ifdef TANGRAM_MBTILES_DATASOURCE
std::string scenePath = std::string("sources.") + _dataSourceName + ".mbtiles";
updateSceneAsync({SceneUpdate{scenePath.c_str(), _mbtilesFilePath}});
#else
LOGE("MBTiles support is disabled. This source will be ignored: %s", _dataSourceName);
#endif
}

void Map::resize(int _newWidth, int _newHeight) {
Expand Down
5 changes: 5 additions & 0 deletions core/src/scene/sceneLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,10 +1038,15 @@ void SceneLoader::loadSource(const std::shared_ptr<Platform>& platform, const st
rawSources->setCacheSize(CACHE_SIZE);

if (isMBTilesFile) {
#ifdef TANGRAM_MBTILES_DATASOURCE
// If we have MBTiles, we know the source is tiled.
tiled = true;
// Create an MBTiles data source from the file at the url and add it to the source chain.
rawSources->setNext(std::make_unique<MBTilesDataSource>(platform, name, url, ""));
#else
LOGE("MBTiles support is disabled. This source will be ignored: %s", name.c_str());
return;
#endif
} else if (tiled) {
rawSources->setNext(std::make_unique<NetworkDataSource>(platform, url, std::move(subdomains), isTms));
}
Expand Down
10 changes: 5 additions & 5 deletions platforms/android/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ add_library(tangram SHARED
platforms/common/platform_gl.cpp
platforms/android/tangram/src/main/cpp/jniExports.cpp
platforms/android/tangram/src/main/cpp/androidPlatform.cpp
platforms/android/tangram/src/main/cpp/sqlite3ndk.cpp
)

target_include_directories(tangram
PRIVATE
core/deps/SQLiteCpp/sqlite3 # sqlite3ndk.cpp needs sqlite3.h
)
if(TANGRAM_MBTILES_DATASOURCE)
target_sources(tangram PRIVATE platforms/android/tangram/src/main/cpp/sqlite3ndk.cpp)
target_include_directories(tangram PRIVATE core/deps/SQLiteCpp/sqlite3) # sqlite3ndk.cpp needs sqlite3.h
target_compile_definitions(tangram PRIVATE TANGRAM_MBTILES_DATASOURCE=1)
endif()

target_link_libraries(tangram
PRIVATE
Expand Down
5 changes: 4 additions & 1 deletion platforms/android/tangram/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ android {
'-Wignored-qualifiers',
'-Wtype-limits',
'-Wmissing-field-initializers',
'-Wno-format-pedantic'
'-Wno-format-pedantic',
'-Wno-gnu-statement-expression',
'-Wgnu-anonymous-struct',
'-Wno-nested-anon-types'

if (abi == 'all') {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86'
Expand Down
5 changes: 4 additions & 1 deletion platforms/android/tangram/src/main/cpp/androidPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
#include <codecvt>
#include <locale>

#ifdef TANGRAM_MBTILES_DATASOURCE
#include "sqlite3ndk.h"

#endif

PFNGLBINDVERTEXARRAYOESPROC glBindVertexArrayOESEXT = 0;
PFNGLDELETEVERTEXARRAYSOESPROC glDeleteVertexArraysOESEXT = 0;
Expand Down Expand Up @@ -182,7 +183,9 @@ AndroidPlatform::AndroidPlatform(JNIEnv* _jniEnv, jobject _assetManager, jobject
return;
}

#ifdef TANGRAM_MBTILES_DATASOURCE
sqlite3_ndk_init(m_assetManager);
#endif
}

void AndroidPlatform::dispose(JNIEnv* _jniEnv) {
Expand Down
8 changes: 5 additions & 3 deletions platforms/ios/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ set(NEXTZEN_API_KEY $ENV{NEXTZEN_API_KEY})
configure_file(${PROJECT_SOURCE_DIR}/platforms/ios/demo/Info.plist.in ${PROJECT_BINARY_DIR}/Info.plist)

# Tell SQLiteCpp to not build its own copy of SQLite, we will use the system library instead.
set(SQLITECPP_INTERNAL_SQLITE OFF CACHE BOOL "")
if (IOS_SDK_VERSION VERSION_LESS 11.0)
set(SQLITE_USE_LEGACY_STRUCT ON CACHE BOOL "")
endif()
set(SQLITECPP_INTERNAL_SQLITE OFF CACHE BOOL "")

# Headers must be absolute paths for the copy_if_different command on the
# static library target, relative paths cause it to fail with an error.
Expand Down Expand Up @@ -149,14 +149,16 @@ set(TANGRAM_STATIC_DEPENDENCIES "\
$<TARGET_FILE:harfbuzz>
$<TARGET_FILE:freetype>
$<TARGET_FILE:icucommon>
$<TARGET_FILE:SQLiteCpp>
$<TARGET_FILE:double-conversion>
$<TARGET_FILE:miniz>
"
)
if (NOT TANGRAM_USE_JSCORE)
if(NOT TANGRAM_USE_JSCORE)
set(TANGRAM_STATIC_DEPENDENCIES "${TANGRAM_STATIC_DEPENDENCIES} $<TARGET_FILE:duktape>")
endif()
if(TANGRAM_MBTILES_DATASOURCE)
set(TANGRAM_STATIC_DEPENDENCIES "${TANGRAM_STATIC_DEPENDENCIES} $<TARGET_FILE:SQLiteCpp>")
endif()

set_target_properties(tangram-static PROPERTIES
XCODE_ATTRIBUTE_CURRENT_PROJECT_VERSION "${TANGRAM_FRAMEWORK_VERSION}"
Expand Down
8 changes: 6 additions & 2 deletions platforms/linux/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ check_unsupported_compiler_version()

add_definitions(-DTANGRAM_LINUX)

get_nextzen_api_key(NEXTZEN_API_KEY)
add_definitions(-DNEXTZEN_API_KEY="${NEXTZEN_API_KEY}")

find_package(OpenGL REQUIRED)

Expand Down Expand Up @@ -75,4 +73,10 @@ target_compile_options(tangram
-Wmissing-field-initializers
)

get_nextzen_api_key(NEXTZEN_API_KEY)
target_compile_definitions(tangram
PRIVATE
NEXTZEN_API_KEY="${NEXTZEN_API_KEY}")


add_resources(tangram "${PROJECT_SOURCE_DIR}/scenes" "res")

0 comments on commit 014c3c5

Please sign in to comment.