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

vcpkg dependency example #2274

Draft
wants to merge 25 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
23 changes: 18 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
cmake_minimum_required(VERSION 3.10)

option(USE_VCPKG "enable vcpkg dependency build" ON)
# needs before first project() call
set(VCPKG_OVERLAY_PORTS
"${CMAKE_CURRENT_LIST_DIR}/vcpkg-ports/alfons"
"${CMAKE_CURRENT_LIST_DIR}/vcpkg-ports/mapbox-earcut"
"${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()

project(tangram)

# Options
Expand All @@ -24,11 +42,6 @@ message(STATUS "Use vcpkg: ${TANGRAM_USE_VCPKG}")

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

# Check that submodules are present.
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/core/deps/isect2d/README.md")
message(SEND_ERROR "Missing submodules - Please run:\n 'git submodule update --init'")
return()
endif()

if(CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-DDEBUG)
Expand Down
125 changes: 125 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "default-builddir",
"hidden": true,
"binaryDir": "${sourceDir}/build/${presetName}"
},
{
"name": "generator-ninja",
"generator": "Ninja"
},
{
"name": "default-debug",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "default-release",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "windows-default",
"displayName": "Windows x64 Debug",
"hidden": true,
"inherits": [
"default-builddir",
"generator-ninja"
],
"architecture": {
"value": "x64",
"strategy": "external"
},
"toolset": {
"value": "host=x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"Windows"
]
}
}
},
{
"name": "windows-default-debug",
"displayName": "Windows x64 Debug",
"inherits": [
"default-debug",
"windows-default"
]
},
{
"name": "windows-default-release",
"displayName": "Windows x64 Release",
"inherits": [
"default-release",
"windows-default"
]
},
{
"name": "linux-default",
"hidden": true,
"inherits": [
"default-builddir",
"generator-ninja"
]
},
{
"name": "linux-default-debug",
"displayName": "linux debug",
"inherits": [
"default-debug",
"linux-default"
]
},
{
"name": "linux-default-release",
"displayName": "linux release",
"inherits": [
"default-release",
"linux-default"
]
}
],
"buildPresets": [
{
"name": "windows-default",
"configurePreset": "windows-default-debug"
},
{
"name": "linux-ci",
"configurePreset": "linux-default-release"
}
],
"testPresets": [
{
"name": "linux-ci",
"description": "Test",
"displayName": "Test Release",
"configurePreset": "linux-default-release"
},
{
"name": "windows-ci",
"description": "Test",
"displayName": "Test Release",
"configurePreset": "windows-default-release"
}
]
}
1 change: 0 additions & 1 deletion bench/benchmark
Submodule benchmark deleted from e776aa
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
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)
68 changes: 37 additions & 31 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
project(tangram-core)

# Build core library dependencies.
find_package(duktape CONFIG REQUIRED)
find_package (SQLite3 REQUIRED)
find_package(RapidJSON CONFIG REQUIRED)
find_path(STB_INCLUDE_DIRS "stb.h")
find_package(miniz CONFIG REQUIRED)
find_package(yaml-cpp CONFIG REQUIRED)
find_package(ZLIB REQUIRED)
find_package(double-conversion CONFIG REQUIRED)
find_package(SQLiteCpp CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
find_package(alfons CONFIG REQUIRED)

if (TANGRAM_USE_VCPKG)
find_package(yaml-cpp CONFIG REQUIRED)
endif()
find_path(MAPBOX_VARIANT_INCLUDE_DIRS "mapbox/optional.hpp")
find_path(GEOJSON_VT_CPP_INCLUDE_DIRS "mapbox/geojsonvt.hpp")
find_path(GEOJSON_CPP_INCLUDE_DIRS "mapbox/geojson.hpp")
find_path(MAPBOX_EARCUT_INCLUDE_DIRS "mapbox/earcut.hpp")

add_subdirectory(deps)

Expand Down Expand Up @@ -207,41 +217,37 @@ target_include_directories(tangram-core
include/tangram
# TODO: These headers shouldn't be public, but Platform classes use them.
src
# TODO: This header shouldn't be public, but we use it in propertyItem.h
deps/variant/include
PRIVATE
generated
deps
deps/earcut/include
deps/isect2d/include
deps/hash-library
deps/mapbox
deps/pbf
deps/rapidjson
deps/sdf
deps/SQLiteCpp
deps/stb
deps/miniz
deps/geojson-vt-cpp/geometry.hpp/include
deps/geojson-vt-cpp/geojson.hpp/include
deps/geojson-vt-cpp/include
deps/double-conversion/include
generated
deps/mapbox
${MAPBOX_VARIANT_INCLUDE_DIRS}
${GEOJSON_CPP_INCLUDE_DIRS}
${GEOJSON_VT_CPP_INCLUDE_DIRS}
${MAPBOX_EARCUT_INCLUDE_DIRS}
)

if (WIN32)
set(ZLIB_NAME ZLIB::ZLIB)
target_compile_definitions(tangram-core PUBLIC _USE_MATH_DEFINES)
else()
set(ZLIB_NAME z)
endif()

# Link core library dependencies.
target_link_libraries(tangram-core
PRIVATE
glm
target_link_libraries(tangram-core PRIVATE
sdf
pbf
isect2d
glm::glm
css-color-parser-cpp
yaml-cpp
alfons
double-conversion
miniz
ZLIB::ZLIB
alfons::alfons
alfons::linebreak
hashlib
double-conversion::double-conversion
miniz::miniz
rapidjson
${ZLIB_NAME}
)

# Add JavaScript implementation.
Expand All @@ -255,13 +261,13 @@ if(TANGRAM_JSCORE_ENABLED)
target_compile_definitions(tangram-core PRIVATE TANGRAM_USE_JSCORE=1)
else()
target_sources(tangram-core PRIVATE src/js/DuktapeContext.cpp src/js/DuktapeContext.h)
target_link_libraries(tangram-core PRIVATE duktape)
target_link_libraries(tangram-core PRIVATE ${DUKTAPE_LIBRARY})
endif()

# 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_link_libraries(tangram-core PRIVATE SQLiteCpp SQLite::SQLite3)
target_compile_definitions(tangram-core PRIVATE TANGRAM_MBTILES_DATASOURCE=1)
endif()

Expand Down
Loading