[qt] Build improvements and better handling of map settings (#197)

* QMapboxGLSettings functions for changing default options and getting default styles

* [qt] allow to build without widgets and other cmake improvements

* [qt] Install include/mbgl for development

* [qt] library static/shared install+export

* [qt] Add missing mbgl-compiler-options dependency for 'qmapboxgl'

* [qt] Raise CMAKE_OSX_DEPLOYMENT_TARGET from 10.13 to 13.0

* [qt] Add Qt::Sql dependency also to the final library. Build qmapboxgl as OBJECT lib inside QtLocation plugin.

* Remove Qt::Sql dependency from 'qmapboxgl'. Not really needed.

* Set CMake config files path back to ${CMAKE_INSTALL_LIBDIR}/cmake/QMapboxGL/

* [qt] Set CMAKE_OSX_DEPLOYMENT_TARGET only if it is not yet set

* [qt] Support CMake v3.11 and earlier versions

* [qt] Comment out 'iOS_static' from CI until it is fixed.

Co-authored-by: Rinigus <rinigus.git@gmail.com>
This commit is contained in:
kiibimees
2022-02-14 18:18:29 +02:00
committed by GitHub
parent 13983337f6
commit 747eb3a440
10 changed files with 192 additions and 82 deletions

View File

@@ -38,11 +38,11 @@ jobs:
static: ON
qt: 5.15.2
qt_target: desktop
- name: iOS_static
os: macos-latest
static: ON
qt: 5.15.2
qt_target: ios
# - name: iOS_static
# os: macos-latest
# static: ON
# qt: 5.15.2
# qt_target: ios
- name: macOS
os: macos-latest
static: ON
@@ -133,7 +133,7 @@ jobs:
mkdir build && cd build
cmake ../source/ \
-DCMAKE_TOOLCHAIN_FILE=../source/platform/ios/platform/ios/toolchain.cmake \
-G Xcode \
-G XCode \
-DPLATFORM=OS64COMBINED \
-DDEPLOYMENT_TARGET=12.0 \
-DENABLE_BITCODE=ON \

View File

@@ -3,14 +3,15 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
option(MBGL_WITH_CORE_ONLY "Build only the core bits, no platform code" OFF)
option(MBGL_WITH_COVERAGE "Enable code coverage collection" OFF)
option(MBGL_WITH_QT "Build Mapbox GL Qt bindings" OFF)
option(MBGL_QT_STATIC "Build Mapbox GL Qt bindings staticly" OFF)
option(MBGL_WITH_SANITIZER "Use [address|thread|undefined] here" OFF)
option(MBGL_WITH_RTTI "Compile with runtime type information" OFF)
option(MBGL_WITH_OPENGL "Build with OpenGL renderer" ON)
option(MBGL_WITH_EGL "Build with EGL renderer" OFF)
option(MBGL_WITH_WERROR "Make all compilation warnings errors" ON)
if (MBGL_WITH_QT)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13)
if (MBGL_WITH_QT AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET 13.0)
endif()
project("Mapbox GL Native" LANGUAGES CXX C)
@@ -97,8 +98,13 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
add_library(
mbgl-core STATIC
if(MBGL_QT_STATIC)
add_library(mbgl-core OBJECT)
else()
add_library(mbgl-core STATIC)
endif()
target_sources(
mbgl-core PRIVATE
${PROJECT_SOURCE_DIR}/include/mbgl/actor/actor.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/actor/actor_ref.hpp
${PROJECT_SOURCE_DIR}/include/mbgl/actor/aspiring_actor.hpp

View File

@@ -0,0 +1,15 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(Qt@QT_VERSION_MAJOR@
COMPONENTS Gui @REQUIRED_QT_VERSION@)
find_dependency(Qt@QT_VERSION_MAJOR@
COMPONENTS Network @REQUIRED_QT_VERSION@)
if(@MBGL_WITH_QT_HEADLESS@ OR NOT @MBGL_WITH_QT_LIB_ONLY@)
find_dependency(Qt@QT_VERSION_MAJOR@
COMPONENTS OpenGL @REQUIRED_QT_VERSION@)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/QMapboxGLTargets.cmake")
@PACKAGE_INCLUDE_QCHTARGETS@

View File

@@ -9,14 +9,10 @@
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
#if !defined(QT_MAPBOXGL_STATIC)
# if defined(QT_BUILD_MAPBOXGL_LIB)
# define Q_MAPBOXGL_EXPORT Q_DECL_EXPORT
# else
# define Q_MAPBOXGL_EXPORT Q_DECL_IMPORT
# endif
#if defined(QT_BUILD_MAPBOXGL_LIB)
# define Q_MAPBOXGL_EXPORT Q_DECL_EXPORT
#else
# define Q_MAPBOXGL_EXPORT
# define Q_MAPBOXGL_EXPORT Q_DECL_IMPORT
#endif
namespace QMapbox {

View File

@@ -49,6 +49,13 @@ public:
FlippedYViewport
};
enum SettingsTemplate {
DefaultSettings = 0,
MapLibreSettings,
MapTilerSettings,
MapboxSettings
};
GLContextMode contextMode() const;
void setContextMode(GLContextMode);
@@ -82,6 +89,10 @@ public:
std::function<std::string(const std::string &)> resourceTransform() const;
void setResourceTransform(const std::function<std::string(const std::string &)> &);
void resetToTemplate(SettingsTemplate);
QVector<QPair<QString, QString>> defaultStyles();
mbgl::TileServerOptions *tileServerOptionsInternal() const;
private:

View File

@@ -7,21 +7,27 @@ set(MBGL_QT_VERSION_COMPATIBILITY 2.0.0)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Version ${MBGL_QT_VERSION}")
option(MBGL_QT_STATIC "Build Mapbox GL Qt bindings staticly" OFF)
option(MBGL_QT_LIBRARY_ONLY "Build only libraries" OFF)
option(MBGL_QT_INSIDE_QT_PLUGIN "Build qmapboxgl as OBJECT library, so it can be bundled into separate single plugin lib." OFF)
option(MBGL_WITH_QT_HEADLESS "Build Mapbox GL Qt with headless support" ON)
option(MBGL_QT_WITH_INTERNAL_SQLITE "Build Mapbox GL Qt bindings with internal sqlite" $<NOT:$<BOOL:${MBGL_QT_STATIC}>>)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}
COMPONENTS Gui
Network
OpenGL
Widgets
REQUIRED)
if (Qt6_FOUND)
find_package(Qt${QT_VERSION_MAJOR}OpenGLWidgets REQUIRED)
endif()
if(MBGL_WITH_QT_HEADLESS OR NOT MBGL_QT_LIBRARY_ONLY)
find_package(Qt${QT_VERSION_MAJOR}
COMPONENTS OpenGL
Widgets
REQUIRED)
endif()
if(NOT MBGL_QT_WITH_INTERNAL_SQLITE)
find_package(Qt${QT_VERSION_MAJOR}Sql REQUIRED)
else()
@@ -95,7 +101,6 @@ target_sources(
${PROJECT_SOURCE_DIR}/platform/qt/src/async_task_impl.hpp
${PROJECT_SOURCE_DIR}/platform/qt/src/number_format.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/gl_functions.cpp
${PROJECT_SOURCE_DIR}/platform/qt/src/headless_backend_qt.cpp
$<$<BOOL:${MBGL_PUBLIC_BUILD}>:${PROJECT_SOURCE_DIR}/platform/qt/src/http_file_source.cpp>
$<$<BOOL:${MBGL_PUBLIC_BUILD}>:${PROJECT_SOURCE_DIR}/platform/qt/src/http_file_source.hpp>
$<$<BOOL:${MBGL_PUBLIC_BUILD}>:${PROJECT_SOURCE_DIR}/platform/qt/src/http_request.cpp>
@@ -113,6 +118,19 @@ target_sources(
${PROJECT_SOURCE_DIR}/platform/qt/src/utf.cpp
)
if(MBGL_WITH_QT_HEADLESS OR NOT MBGL_QT_LIBRARY_ONLY)
target_sources(
mbgl-core
PRIVATE
${PROJECT_SOURCE_DIR}/platform/qt/src/headless_backend_qt.cpp
)
target_link_libraries(
mbgl-core
PRIVATE
Qt${QT_VERSION_MAJOR}::OpenGL
)
endif()
target_compile_definitions(
mbgl-core
PRIVATE QT_IMAGE_DECODERS
@@ -124,18 +142,8 @@ target_include_directories(
PRIVATE ${PROJECT_SOURCE_DIR}/platform/default/include
)
include(GNUInstallDirs)
include(${PROJECT_SOURCE_DIR}/vendor/nunicode.cmake)
if(MBGL_QT_STATIC)
install(TARGETS mbgl-vendor-csscolorparser
ARCHIVE DESTINATION lib
)
install(TARGETS mbgl-vendor-nunicode
ARCHIVE DESTINATION lib
)
install(TARGETS mbgl-vendor-parsedate
ARCHIVE DESTINATION lib
)
endif()
set_property(TARGET mbgl-core PROPERTY AUTOMOC ON)
@@ -146,18 +154,11 @@ target_link_libraries(
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::OpenGL
$<IF:$<BOOL:${MBGL_QT_WITH_INTERNAL_SQLITE}>,mbgl-vendor-sqlite,Qt${QT_VERSION_MAJOR}::Sql>
$<$<PLATFORM_ID:Linux>:$<IF:$<BOOL:${MBGL_QT_WITH_INTERNAL_ICU}>,mbgl-vendor-icu,ICU::uc>>
mbgl-vendor-nunicode
)
if(MBGL_QT_STATIC)
install(TARGETS mbgl-core
ARCHIVE DESTINATION lib
)
endif()
set(qmapboxgl_headers
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapbox
${PROJECT_SOURCE_DIR}/platform/qt/include/QMapboxGL
@@ -166,7 +167,11 @@ set(qmapboxgl_headers
)
if(MBGL_QT_STATIC)
add_library(qmapboxgl STATIC)
if(MBGL_QT_INSIDE_QT_PLUGIN)
add_library(qmapboxgl OBJECT)
else()
add_library(qmapboxgl STATIC)
endif()
else()
add_library(qmapboxgl SHARED)
endif()
@@ -195,6 +200,7 @@ target_sources(
set_target_properties(
qmapboxgl PROPERTIES
AUTOMOC ON
EXPORT_NAME QMapboxGL
OUTPUT_NAME QMapboxGL
VERSION ${MBGL_QT_VERSION}
SOVERSION ${MBGL_QT_VERSION_COMPATIBILITY}
@@ -208,59 +214,75 @@ if (NOT MBGL_QT_STATIC)
)
endif()
include(CMakePackageConfigHelpers)
set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/QMapboxGL/)
configure_package_config_file(
"platform/qt/QMapboxGLConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_INCLUDEDIR
CMAKE_INSTALL_LIBDIR NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfigVersion.cmake
VERSION ${MBGL_QT_VERSION}
COMPATIBILITY AnyNewerVersion)
install(EXPORT QMapboxGLTargets
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
COMPONENT development)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfigVersion.cmake"
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
COMPONENT development)
install(
DIRECTORY include/mbgl
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT development
)
# FIXME: Because of rapidjson conversion
target_include_directories(
qmapboxgl
PRIVATE ${PROJECT_SOURCE_DIR}/src
)
target_include_directories(
qmapboxgl
PUBLIC ${PROJECT_SOURCE_DIR}/platform/qt/include
PRIVATE
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/platform/qt/include
INTERFACE
"$<INSTALL_INTERFACE:include>"
)
target_compile_definitions(
qmapboxgl
PRIVATE
$<IF:$<BOOL:${MBGL_QT_STATIC}>,QT_MAPBOXGL_STATIC,QT_BUILD_MAPBOXGL_LIB>
QT_BUILD_MAPBOXGL_LIB
)
target_link_libraries(
qmapboxgl
PRIVATE
PUBLIC
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
mbgl-compiler-options
mbgl-core
Qt${QT_VERSION_MAJOR}::Network
PRIVATE
"$<BUILD_INTERFACE:mbgl-compiler-options>"
"$<BUILD_INTERFACE:mbgl-core>"
"$<BUILD_INTERFACE:mbgl-vendor-parsedate>"
"$<BUILD_INTERFACE:mbgl-vendor-nunicode>"
"$<BUILD_INTERFACE:mbgl-vendor-csscolorparser>"
)
if(MSVC)
if(MBGL_QT_STATIC)
set_target_properties(mbgl-vendor-csscolorparser PROPERTIES COMPILE_PDB_NAME mbgl-vendor-csscolorparserd)
set_target_properties(mbgl-vendor-nunicode PROPERTIES COMPILE_PDB_NAME mbgl-vendor-nunicoded)
set_target_properties(mbgl-vendor-parsedate PROPERTIES COMPILE_PDB_NAME mbgl-vendor-parsedated)
set_target_properties(mbgl-core PROPERTIES COMPILE_PDB_NAME mbgl-cored)
set_target_properties(qmapboxgl PROPERTIES COMPILE_PDB_NAME QMapboxGLd)
install(FILES $<TARGET_FILE_DIR:mbgl-vendor-csscolorparser>/mbgl-vendor-csscolorparserd.pdb CONFIGURATIONS "Debug" DESTINATION lib)
install(FILES $<TARGET_FILE_DIR:mbgl-vendor-nunicode>/mbgl-vendor-nunicoded.pdb CONFIGURATIONS "Debug" DESTINATION lib)
install(FILES $<TARGET_FILE_DIR:mbgl-vendor-parsedate>/mbgl-vendor-parsedated.pdb CONFIGURATIONS "Debug" DESTINATION lib)
install(FILES $<TARGET_FILE_DIR:mbgl-core>/mbgl-cored.pdb CONFIGURATIONS "Debug" DESTINATION lib)
install(FILES $<TARGET_FILE_DIR:qmapboxgl>/QMapboxGLd.pdb CONFIGURATIONS "Debug" DESTINATION lib)
else()
install(FILES $<TARGET_PDB_FILE:qmapboxgl> CONFIGURATIONS "Debug" DESTINATION bin)
endif()
endif()
install(TARGETS qmapboxgl
RUNTIME DESTINATION bin
FRAMEWORK DESTINATION lib
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
INCLUDES DESTINATION include
PUBLIC_HEADER DESTINATION include
EXPORT QMapboxGLTargets
# Explicit set of DESTINATION is needed for older CMake versions.
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
FRAMEWORK DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
if(NOT MBGL_QT_LIBRARY_ONLY)
@@ -292,6 +314,11 @@ if(NOT MBGL_QT_LIBRARY_ONLY)
qmapboxgl
)
target_include_directories(
mbgl-qt
PUBLIC ${PROJECT_SOURCE_DIR}/platform/qt/include
)
add_executable(
mbgl-test-runner
${PROJECT_SOURCE_DIR}/platform/qt/test/main.cpp

View File

@@ -459,6 +459,43 @@ void QMapboxGLSettings::setResourceTransform(const std::function<std::string(con
m_resourceTransform = transform;
}
/*!
Reset all settings based on the given template.
MapLibre can support servers with different resource path structure.
Some of the most common servers like Maptiler and Mapbox are defined
in the library. This function will re-initialise all settings based
on the default values of specific service provider defaults.
*/
void QMapboxGLSettings::resetToTemplate(SettingsTemplate settings_template)
{
if(m_tileServerOptionsInternal) delete m_tileServerOptionsInternal;
if(settings_template == MapLibreSettings){
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapLibreConfiguration());
}else if(settings_template == MapTilerSettings){
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapTilerConfiguration());
}else if(settings_template == MapboxSettings){
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::MapboxConfiguration());
}else{
m_tileServerOptionsInternal = new mbgl::TileServerOptions(mbgl::TileServerOptions::DefaultConfiguration());
}
}
/*!
All predefined styles.
Return all styles that are defined in default settings.
*/
QVector<QPair<QString, QString> > QMapboxGLSettings::defaultStyles(){
QVector<QPair<QString, QString>> styles;
for (const auto &style : tileServerOptionsInternal()->defaultStyles()) {
styles.append(QPair<QString, QString>(
QString::fromStdString(style.getUrl()), QString::fromStdString(style.getName())));
}
return styles;
}
mbgl::TileServerOptions *QMapboxGLSettings::tileServerOptionsInternal() const {
return m_tileServerOptionsInternal;
}

View File

@@ -2,8 +2,14 @@ if(TARGET mbgl-vendor-csscolorparser)
return()
endif()
add_library(
mbgl-vendor-csscolorparser STATIC
if(MBGL_QT_STATIC)
add_library(mbgl-vendor-csscolorparser OBJECT)
else()
add_library(mbgl-vendor-csscolorparser STATIC)
endif()
target_sources(
mbgl-vendor-csscolorparser PRIVATE
${CMAKE_CURRENT_LIST_DIR}/csscolorparser/csscolorparser.cpp
)

10
vendor/nunicode.cmake vendored
View File

@@ -2,8 +2,14 @@ if(TARGET mbgl-vendor-nunicode)
return()
endif()
add_library(
mbgl-vendor-nunicode STATIC
if(MBGL_QT_STATIC)
add_library(mbgl-vendor-nunicode OBJECT)
else()
add_library(mbgl-vendor-nunicode STATIC)
endif()
target_sources(
mbgl-vendor-nunicode PRIVATE
${CMAKE_CURRENT_LIST_DIR}/nunicode/src/libnu/ducet.c
${CMAKE_CURRENT_LIST_DIR}/nunicode/src/libnu/strcoll.c
${CMAKE_CURRENT_LIST_DIR}/nunicode/src/libnu/strings.c

View File

@@ -2,8 +2,14 @@ if(TARGET mbgl-vendor-parsedate)
return()
endif()
add_library(
mbgl-vendor-parsedate STATIC
if(MBGL_QT_STATIC)
add_library(mbgl-vendor-parsedate OBJECT)
else()
add_library(mbgl-vendor-parsedate STATIC)
endif()
target_sources(
mbgl-vendor-parsedate PRIVATE
${CMAKE_CURRENT_LIST_DIR}/parsedate/parsedate.cpp
)