Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[do-not-review] Export tangram as a library #2280

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,5 @@ core/generated/*.h
# CLion build directories
/cmake-build-debug/
/cmake-build-release/

.vscode
33 changes: 3 additions & 30 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,6 @@
[submodule "core/dependencies/csscolorparser"]
path = core/deps/css-color-parser-cpp
url = https://github.com/tangrams/css-color-parser-cpp
[submodule "core/include/variant"]
path = core/deps/variant
url = https://github.com/tangrams/variant
[submodule "core/include/earcut.hpp"]
path = core/deps/earcut
url = https://github.com/tangrams/earcut.hpp
[submodule "core/dependencies/geojson-vt-cpp"]
path = core/deps/geojson-vt-cpp
url = https://github.com/tangrams/geojson-vt-cpp.git
[submodule "external/duktape"]
path = core/deps/duktape
url = https://github.com/tangrams/duktape.git
[submodule "external/yaml-cpp"]
path = core/deps/yaml-cpp
url = https://github.com/tangrams/yaml-cpp
[submodule "external/glfw"]
path = platforms/common/glfw
url = https://github.com/glfw/glfw
[submodule "external/benchmark"]
path = bench/benchmark
url = https://github.com/google/benchmark
[submodule "external/alfons"]
path = core/deps/alfons
url = https://github.com/hjanetzek/alfons
[submodule "external/harfbuzz-icu-freetype"]
path = core/deps/harfbuzz-icu-freetype
url = https://github.com/tangrams/harfbuzz-icu-freetype.git
[submodule "external/SQLiteCpp"]
path = core/deps/SQLiteCpp
url = https://github.com/SRombauts/SQLiteCpp.git
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg
66 changes: 59 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.14)
include(cmake/get_tangram_version.cmake)
include(cmake/vcpkg_setup.cmake)
get_tangram_version()
vcpkg_setup()

project(tangram)
project(tangram VERSION ${TANGRAM_VERSION})

# set debug prefix for multi configuration generators
set(CMAKE_DEBUG_POSTFIX "d")

if(WIN32)
set(DEFAULT_BIN_DIR bin)
set(DEFAULT_LIB_DIR lib)
set(DEFAULT_ARCHIVE_DIR lib)
else()
include(GNUInstallDirs)
set(DEFAULT_BIN_DIR ${CMAKE_INSTALL_BINDIR})
set(DEFAULT_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
set(DEFAULT_ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR})
endif()
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#runtime-output-artifacts
set(TANGRAM_BIN_DIR ${DEFAULT_BIN_DIR} CACHE STRING "Install directory for binaries")
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#library-output-artifacts
set(TANGRAM_LIB_DIR ${DEFAULT_LIB_DIR} CACHE STRING "Install directory for libraries")
# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#archive-output-artifacts
set(TANGRAM_ARCHIVE_DIR ${DEFAULT_ARCHIVE_DIR} CACHE STRING "Install directory for archives")
set(INSTALL_CMAKE_DIR ${TANGRAM_LIB_DIR}/cmake/tangram CACHE STRING "Install directory of the cmake targets")

# Options
option(TANGRAM_USE_JSCORE "Use system libraries for JavaScriptCore and enable it on iOS and macOS" OFF)
Expand All @@ -18,11 +43,7 @@ option(TANGRAM_DEV_MODE "For developers only: Don't omit the frame pointer" OFF)

message(STATUS "Build type configuration: ${CMAKE_BUILD_TYPE}")

# Check that submodules are present.
if(NOT MSVC AND NOT EXISTS "${PROJECT_SOURCE_DIR}/core/deps/harfbuzz-icu-freetype/harfbuzz/README")
message(SEND_ERROR "Missing submodules - Please run:\n 'git submodule update --init'")
return()
endif()
include(cmake/tangram_install.cmake)

if(CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DDEBUG)
Expand Down Expand Up @@ -94,3 +115,34 @@ if(TANGRAM_BUILD_BENCHMARKS)
message(STATUS "Building benchmarks")
add_subdirectory(bench)
endif()


# start package tangram
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/tangramConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion
)

set(INCLUDE_INSTALL_DIR include/)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/tangramConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/tangramConfig.cmake"
INSTALL_DESTINATION ${INSTALL_CMAKE_DIR}
PATH_VARS INCLUDE_INSTALL_DIR
)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/tangramConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/tangramConfigVersion.cmake"
DESTINATION ${INSTALL_CMAKE_DIR}
)

install(EXPORT tangramTargets
FILE tangramTargets.cmake
NAMESPACE tangram::
DESTINATION ${INSTALL_CMAKE_DIR}
)

install(DIRECTORY vcpkg-ports/ DESTINATION ${CMAKE_INSTALL_PREFIX}/tangram-vcpkg-overlays)
14 changes: 14 additions & 0 deletions cmake/get_tangram_version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
macro(get_tangram_version)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/core/include/tangram/tangram.h VERSION_FILE)

string(REGEX MATCH "TANGRAM_VERSION_MAJOR ([0-9]*)" _ ${VERSION_FILE})
set(TANGRAM_VERSION_MAJOR ${CMAKE_MATCH_1})

string(REGEX MATCH "TANGRAM_VERSION_MINOR ([0-9]*)" _ ${VERSION_FILE})
set(TANGRAM_VERSION_MINOR ${CMAKE_MATCH_1})

string(REGEX MATCH "TANGRAM_VERSION_PATCH ([0-9]*)" _ ${VERSION_FILE})
set(TANGRAM_VERSION_PATCH ${CMAKE_MATCH_1})

set(TANGRAM_VERSION ${TANGRAM_VERSION_MAJOR}.${TANGRAM_VERSION_MINOR}.${TANGRAM_VERSION_PATCH})
endmacro()
2 changes: 1 addition & 1 deletion cmake/glfw.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ else()
set(GLFW_BUILD_TESTS OFF CACHE BOOL "Build the GLFW test programs")
set(GLFW_BUILD_DOCS OFF CACHE BOOL "Build the GLFW documentation")
set(GLFW_INSTALL OFF CACHE BOOL "Generate installation target")
add_subdirectory(platforms/common/glfw)
find_package(glfw3 CONFIG REQUIRED)
if(APPLE)
# Turn off noisy warnings from clang on macOS.
target_compile_options(glfw PRIVATE "-Wno-deprecated-declarations")
Expand Down
3 changes: 3 additions & 0 deletions cmake/tangramConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include ("${CMAKE_CURRENT_LIST_DIR}/tangramTargets.cmake")
19 changes: 19 additions & 0 deletions cmake/tangram_install.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function(tangram_install TARGET)
install(TARGETS ${TARGET}
EXPORT tangramTargets
LIBRARY DESTINATION ${TANGRAM_LIB_DIR}
ARCHIVE DESTINATION ${TANGRAM_ARCHIVE_DIR}
RUNTIME DESTINATION ${TANGRAM_BIN_DIR}
INCLUDES DESTINATION include/
PUBLIC_HEADER DESTINATION include/
COMPONENT tangram
)
endfunction()

function(tangram_install_dir DIR)
install(DIRECTORY ${DIR} TYPE INCLUDE)
endfunction()

function(tangram_install_files INSTALL_FILES)
install(FILES ${INSTALL_FILES} TYPE INCLUDE)
endfunction()
76 changes: 76 additions & 0 deletions cmake/vcpkg_android.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#
# vcpkg_android.cmake
#
# Helper script when using vcpkg with cmake. It should be triggered via the variable VCPKG_TARGET_ANDROID
#
# For example:
# if (VCPKG_TARGET_ANDROID)
# include("cmake/vcpkg_android.cmake")
# endif()
#
# This script will:
# 1 & 2. check the presence of needed env variables: ANDROID_NDK_HOME and VCPKG_ROOT
# 3. set VCPKG_TARGET_TRIPLET according to ANDROID_ABI
# 4. Combine vcpkg and Android toolchains by setting CMAKE_TOOLCHAIN_FILE
# and VCPKG_CHAINLOAD_TOOLCHAIN_FILE

# Note: VCPKG_TARGET_ANDROID is not an official Vcpkg variable.
# it is introduced for the need of this script

if (VCPKG_TARGET_ANDROID)

#
# 3. Set VCPKG_TARGET_TRIPLET according to ANDROID_ABI
#
# There are four different Android ABI, each of which maps to
# a vcpkg triplet. The following table outlines the mapping from vcpkg architectures to android architectures
#
# |VCPKG_TARGET_TRIPLET | ANDROID_ABI |
# |---------------------------|----------------------|
# |arm64-android | arm64-v8a |
# |arm-android | armeabi-v7a |
# |x64-android | x86_64 |
# |x86-android | x86 |
#
# The variable must be stored in the cache in order to successfully the two toolchains.
#
if (ANDROID_ABI MATCHES "arm64-v8a")
set(VCPKG_TARGET_TRIPLET "arm64-android" CACHE STRING "" FORCE)
elseif(ANDROID_ABI MATCHES "armeabi-v7a")
set(VCPKG_TARGET_TRIPLET "arm-android" CACHE STRING "" FORCE)
elseif(ANDROID_ABI MATCHES "x86_64")
set(VCPKG_TARGET_TRIPLET "x64-android" CACHE STRING "" FORCE)
elseif(ANDROID_ABI MATCHES "x86")
set(VCPKG_TARGET_TRIPLET "x86-android" CACHE STRING "" FORCE)
else()
message(FATAL_ERROR "
Please specify ANDROID_ABI
For example
cmake ... -DANDROID_ABI=armeabi-v7a

Possible ABIs are: arm64-v8a, armeabi-v7a, x64-android, x86-android
")
endif()
message("vcpkg_android.cmake: VCPKG_TARGET_TRIPLET was set to ${VCPKG_TARGET_TRIPLET}")


#
# 4. Combine vcpkg and Android toolchains
#

# vcpkg and android both provide dedicated toolchains:
#
# vcpkg_toolchain_file=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
# android_toolchain_file=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake
#
# When using vcpkg, the vcpkg toolchain shall be specified first.
# However, vcpkg provides a way to preload and additional toolchain,
# with the VCPKG_CHAINLOAD_TOOLCHAIN_FILE option.
get_filename_component(ANDROID_NDK_HOME "${CMAKE_TOOLCHAIN_FILE}/../../../" ABSOLUTE)
set(ENV{ANDROID_NDK_HOME} ${ANDROID_NDK_HOME})
message("vcpkg_android.cmake: ANDROID_NDK_HOME was set to ${ANDROID_NDK_HOME}")
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE})
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)
message("vcpkg_android.cmake: CMAKE_TOOLCHAIN_FILE was set to ${CMAKE_TOOLCHAIN_FILE}")
message("vcpkg_android.cmake: VCPKG_CHAINLOAD_TOOLCHAIN_FILE was set to ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
endif(VCPKG_TARGET_ANDROID)
17 changes: 17 additions & 0 deletions cmake/vcpkg_setup.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
macro(vcpkg_setup)
option(USE_VCPKG "enable vcpkg dependency build" ON)
# needs before first project() call
set(VCPKG_OVERLAY_PORTS
"${CMAKE_CURRENT_LIST_DIR}/vcpkg-ports/mapbox-geojson-vt-cpp"
"${CMAKE_CURRENT_LIST_DIR}/vcpkg-ports/mapbox-geojson-cpp"
"${CMAKE_CURRENT_LIST_DIR}/vcpkg-ports/mapbox-geometry"
"${CMAKE_CURRENT_LIST_DIR}/vcpkg-ports/mapbox-variant"
"${CMAKE_CURRENT_LIST_DIR}/vcpkg-ports/glm"
)
if(USE_VCPKG AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
endif()
if (VCPKG_TARGET_ANDROID)
include("cmake/vcpkg_android.cmake")
endif()
endmacro()
Loading