From 9cd70bfe7fce7205654d8fab2eb89424ce25acf9 Mon Sep 17 00:00:00 2001 From: Tadej Novak Date: Thu, 16 Jun 2022 20:52:52 +0200 Subject: [PATCH] Qt build improvements and documentation (#277) * Qt build improvements and documentation * Update include/mbgl/actor/actor_ref.hpp Co-authored-by: Oliver Wipfli --- .github/actions/qt5-build/Dockerfile | 5 + .github/actions/qt5-build/action.yml | 6 + .github/actions/qt5-build/entrypoint.sh | 19 +++ .github/workflows/qt-ci.yml | 48 ++++--- CMakeLists.txt | 46 ++++++- include/mbgl/actor/actor_ref.hpp | 4 + platform/qt/README.md | 124 +++++------------- platform/qt/include/qmapbox.hpp | 10 +- platform/qt/qt.cmake | 36 ++--- .../scripts/configure_Qt5_Android_static.sh | 34 +++++ platform/qt/scripts/configure_Qt5_Linux.sh | 17 +++ platform/qt/scripts/configure_Qt5_Windows.ps1 | 8 ++ .../scripts/configure_Qt5_Windows_static.ps1 | 10 ++ .../qt/scripts/configure_Qt5_iOS_static.sh | 29 ++++ platform/qt/scripts/configure_Qt5_macOS.sh | 18 +++ .../qt/scripts/configure_Qt5_macOS_static.sh | 20 +++ platform/qt/scripts/configure_Qt6_Windows.ps1 | 8 ++ platform/qt/scripts/configure_Qt6_macOS.sh | 19 +++ .../qt/scripts/configure_Qt6_macOS_static.sh | 21 +++ platform/qt/src/qmapboxgl.cpp | 12 +- platform/qt/src/qt_geojson.cpp | 3 - platform/qt/src/timer.cpp | 12 +- platform/qt/test/main.cpp | 4 + test/CMakeLists.txt | 7 + vendor/csscolorparser.cmake | 6 +- vendor/icu.cmake | 5 + vendor/nunicode.cmake | 11 +- vendor/parsedate.cmake | 2 +- vendor/sqlite.cmake | 5 + 29 files changed, 401 insertions(+), 148 deletions(-) create mode 100644 .github/actions/qt5-build/Dockerfile create mode 100644 .github/actions/qt5-build/action.yml create mode 100755 .github/actions/qt5-build/entrypoint.sh create mode 100755 platform/qt/scripts/configure_Qt5_Android_static.sh create mode 100755 platform/qt/scripts/configure_Qt5_Linux.sh create mode 100644 platform/qt/scripts/configure_Qt5_Windows.ps1 create mode 100644 platform/qt/scripts/configure_Qt5_Windows_static.ps1 create mode 100755 platform/qt/scripts/configure_Qt5_iOS_static.sh create mode 100755 platform/qt/scripts/configure_Qt5_macOS.sh create mode 100755 platform/qt/scripts/configure_Qt5_macOS_static.sh create mode 100644 platform/qt/scripts/configure_Qt6_Windows.ps1 create mode 100755 platform/qt/scripts/configure_Qt6_macOS.sh create mode 100755 platform/qt/scripts/configure_Qt6_macOS_static.sh diff --git a/.github/actions/qt5-build/Dockerfile b/.github/actions/qt5-build/Dockerfile new file mode 100644 index 000000000..80df6eb69 --- /dev/null +++ b/.github/actions/qt5-build/Dockerfile @@ -0,0 +1,5 @@ +FROM ghcr.io/maplibre/linux-builder:centos7 + +# Copy and set the entry point +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/actions/qt5-build/action.yml b/.github/actions/qt5-build/action.yml new file mode 100644 index 000000000..c0dcb6668 --- /dev/null +++ b/.github/actions/qt5-build/action.yml @@ -0,0 +1,6 @@ +# action.yml +name: 'Qt5 Linux Builder' +description: 'Helper action to build in a specific Docker container' +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/.github/actions/qt5-build/entrypoint.sh b/.github/actions/qt5-build/entrypoint.sh new file mode 100755 index 000000000..aacd44a7f --- /dev/null +++ b/.github/actions/qt5-build/entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/bash -l + +source scl_source enable devtoolset-8 rh-git218 + +set -e +set -x + +export CCACHE_DIR="$GITHUB_WORKSPACE/.ccache" +export PATH="$Qt5_Dir/bin:$PATH" + +mkdir build && cd build +cmake ../source/ \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DMBGL_WITH_QT=ON \ + -DMBGL_QT_LIBRARY_ONLY=ON \ + -DCMAKE_INSTALL_PREFIX="../install/" +ninja +ninja install diff --git a/.github/workflows/qt-ci.yml b/.github/workflows/qt-ci.yml index 5dab5993e..c669ce685 100644 --- a/.github/workflows/qt-ci.yml +++ b/.github/workflows/qt-ci.yml @@ -70,6 +70,11 @@ jobs: strategy: matrix: include: + - name: Linux + os: ubuntu-latest + static: OFF + qt: 5.15.2 + qt_target: desktop - name: macOS os: macos-latest static: OFF @@ -80,11 +85,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 @@ -97,7 +102,7 @@ jobs: qt_target: desktop runs-on: ${{ matrix.os }} env: - BUILD_TYPE: Debug + BUILD_TYPE: RelWithDebInfo BUILD_MODE: ${{ matrix.static }} QT_VERSION: ${{ matrix.qt }} @@ -109,7 +114,7 @@ jobs: submodules: recursive fetch-depth: 0 - - name: Install dependencies + - name: Install macOS dependencies if: runner.os == 'macOS' env: HOMEBREW_NO_AUTO_UPDATE: 1 @@ -120,6 +125,7 @@ jobs: brew list ninja || brew install ninja - name: Setup Xcode + if: runner.os == 'macOS' uses: maxim-lobanov/setup-xcode@v1 with: xcode-version: latest-stable @@ -128,9 +134,11 @@ jobs: uses: jurplel/install-qt-action@v2 with: version: ${{ env.QT_VERSION }} + dir: ${{ github.workspace }} target: ${{ matrix.qt_target }} - name: Prepare ccache + if: runner.os == 'macOS' run: | ccache --clear ccache --set-config cache_dir=~/.ccache @@ -148,6 +156,7 @@ jobs: ${{ env.cache-name }}-${{ runner.os }}-${{ matrix.name }}-${{ matrix.qt }}-${{ github.job }} - name: Clear ccache statistics + if: runner.os == 'macOS' run: | ccache --zero-stats ccache --max-size=2G @@ -161,7 +170,6 @@ jobs: -G Ninja \ -DMBGL_WITH_QT=ON \ -DMBGL_QT_STATIC=${BUILD_MODE} \ - -DMBGL_QT_WITH_INTERNAL_SQLITE=OFF \ -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ -DCMAKE_INSTALL_PREFIX=../install \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ @@ -174,22 +182,25 @@ jobs: run: | mkdir build && cd build cmake ../source/ \ - -DCMAKE_TOOLCHAIN_FILE=../source/platform/ios/platform/ios/toolchain.cmake \ - -G XCode \ - -DPLATFORM=OS64COMBINED \ - -DDEPLOYMENT_TARGET=12.0 \ - -DENABLE_BITCODE=ON \ + -G"Ninja Multi-Config" \ + -DCMAKE_SYSTEM_NAME=iOS \ + -DCMAKE_CONFIGURATION_TYPES="Release;Debug" \ + -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \ + -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0 \ -DMBGL_WITH_QT=ON \ - -DMBGL_WITH_WERROR=OFF \ - -DMBGL_QT_LIBRARY_ONLY=ON \ -DMBGL_QT_STATIC=${BUILD_MODE} \ - -DMBGL_QT_WITH_INTERNAL_SQLITE=OFF \ + -DMBGL_QT_LIBRARY_ONLY=ON \ -DMBGL_QT_WITH_IOS_CCACHE=ON \ - -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ - -DCMAKE_INSTALL_PREFIX=../install + -DCMAKE_INSTALL_PREFIX=../install \ + -DCMAKE_FIND_ROOT_PATH="$Qt5_Dir" \ + -DCMAKE_PREFIX_PATH="$Qt5_Dir" cmake --build . --config Release cmake --install . --config Release + - name: Build maplibre-gl-native (Linux) + if: runner.os == 'Linux' + uses: ./source/.github/actions/qt5-build + - name: Upload artifacts uses: actions/upload-artifact@v2 with: @@ -197,5 +208,6 @@ jobs: path: install - name: Show ccache statistics + if: runner.os == 'macOS' run: | ccache --show-stats -v diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c923b02b..ca18c2c6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,6 @@ 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) @@ -55,6 +54,7 @@ target_compile_options( -fsanitize-blacklist=${UBSAN_BLACKLIST}> $<$:-fsanitize=float-divide-by-zero, -fsanitize-blacklist=${UBSAN_BLACKLIST}> + $<$:-fembed-bitcode> $<$,$,$>>>:-fno-rtti> $<$,$>>:-Wall> $<$,$>>:-Wshadow> @@ -68,10 +68,10 @@ target_compile_options( $<$,$>>:-Wno-error=unused-parameter> $<$,$>>:-Wno-error=unused-property-ivar> $<$:/utf-8> - # $<$:/WX> # all warnings as errors + $<$:/WX> # all warnings as errors + $<$:/EHsc> # exceptions $<$:/wd4068> # pragma - $<$:/wd4244> # types - $<$:/wd4828> # encoding + $<$:/D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS> $<$:/D_CRT_SECURE_NO_WARNINGS> ) @@ -93,12 +93,16 @@ set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_VISIBILITY_PRESET hidden) +if (CMAKE_GENERATOR STREQUAL "Ninja Multi-Config") + set(CMAKE_CROSS_CONFIGS "all") + set(CMAKE_DEFAULT_CONFIGS "all") +endif() set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) -if(MBGL_QT_STATIC) +if(MBGL_WITH_QT AND ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0") add_library(mbgl-core OBJECT) else() add_library(mbgl-core STATIC) @@ -1020,6 +1024,38 @@ target_link_libraries( Mapbox::Base::variant ) +export(TARGETS + mbgl-core + + mapbox-base + mapbox-base-cheap-ruler-cpp + mapbox-base-extras-expected-lite + mapbox-base-extras-kdbush.hpp + mapbox-base-extras-rapidjson + mapbox-base-geojson-vt-cpp + mapbox-base-geojson.hpp + mapbox-base-geometry.hpp + mapbox-base-jni.hpp + mapbox-base-optional + mapbox-base-pixelmatch-cpp + mapbox-base-shelf-pack-cpp + mapbox-base-supercluster.hpp + mapbox-base-variant + mbgl-compiler-options + mbgl-vendor-boost + mbgl-vendor-csscolorparser + mbgl-vendor-earcut.hpp + mbgl-vendor-eternal + mbgl-vendor-parsedate + mbgl-vendor-polylabel + mbgl-vendor-protozero + mbgl-vendor-unique_resource + mbgl-vendor-vector-tile + mbgl-vendor-wagyu + + FILE MapboxCoreTargets.cmake +) + set_target_properties( mbgl-core PROPERTIES diff --git a/include/mbgl/actor/actor_ref.hpp b/include/mbgl/actor/actor_ref.hpp index d700a86d1..c44ca0ea4 100644 --- a/include/mbgl/actor/actor_ref.hpp +++ b/include/mbgl/actor/actor_ref.hpp @@ -38,7 +38,11 @@ public: template auto ask(Fn fn, Args&&... args) const { // Result type is deduced from the function's return type +#if __cplusplus >= 201703L + using ResultType = std::invoke_result_t; +#else using ResultType = typename std::result_of::type; +#endif std::promise promise; auto future = promise.get_future(); diff --git a/platform/qt/README.md b/platform/qt/README.md index f779a70f4..8c501258e 100644 --- a/platform/qt/README.md +++ b/platform/qt/README.md @@ -1,108 +1,44 @@ # MapLibre Maps SDK for Qt -## Developing +This is a community maintained MapLibre SDK for usage in Qt apps. +Both Qt5 (minimal 5.6) and Qt6 are supported. +Note that only OpenGL rendering is supported at the moment. -This is the foundation for the [Mapbox GL plugin](https://doc.qt.io/qt-5/location-plugin-mapboxgl.html) -available in the Qt SDK since Qt 5.9. Use the [Qt bugtracker](https://bugreports.qt.io) for bugs related -to the plugin and this GitHub repository for bugs related to MapLibre GL Native and the Qt bindings. +## Supported platforms -You should build this repository if you want to develop/contribute using the low level Qt C++ bindings or -want to contribute to the MapLibre GL Native project using the Qt port for debugging. +- macOS +- iOS +- Android +- Linux +- Windows -### Build dependencies +## Building -#### Linux +This project uses out of source build. CMake 3.10 or later is used to generate +make files. Ninja is recommended. -For Linux (tested on Ubuntu) desktop, together with these [build instructions](../linux/README.md), you also need: +Before the project can be built Qt installation needs to be added to the `PATH`: -``` -$ sudo apt-get install qt5-default +```shell +export PATH=/Qt///bin:$PATH ``` -#### macOS +A minimal set of commands to build and install is -For macOS desktop, you can install Qt 5 via [Homebrew](https://brew.sh): - -``` -$ brew install qt5 +```shell +mkdir build && cd build +cmake ../maplibre-gl-native/ \ + -GNinja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX= \ + -DMBGL_WITH_QT=ON +ninja +ninja install ``` -Since Homebrew doesn't add Qt to the path, you'll have to do that manually before running any Make target: +`` above should be replaced with a wished installation path. +Files installed there can later be used as the dependency for your app. -``` -export PATH=/usr/local/opt/qt5/bin:$PATH -``` - -### Windows - -The Windows build will assume you have installed and on the default path: - -- Microsoft Visual Studio 2019 -- [CMake 3.10.1+](https://cmake.org/download/) -- [Ninja](https://github.com/ninja-build/ninja/releases) -- [Qt 5.4+](https://www.qt.io/download) with "msvc2019" (or later) support. - -At runtime, you will also need installed: - -- [OpenSSL 1.0.2+](https://slproweb.com/products/Win32OpenSSL.html) -- DirectX - -#### QNX 7.0 - -To build for QNX 7.0, you need to install the QNX Software Development Platform (SDP) on a Linux host. - -http://www.qnx.com/developers/docs/7.0.0/#com.qnx.doc.qnxsdp.nav/topic/bookset.html - -After installing the SDP, you need to source the QNX environment script: - -``` -source /qnxsdp-env.sh -``` - -You also need to Build Qt for QNX. - -http://wiki.qt.io/Building_Qt_for_QNX_Neutrino_OS - -After building Qt for QNX, you need to add Qt installation's bin directory to the path. - -``` -export PATH=/bin:$PATH -``` - -### Build instructions - -Public API headers can be found in the [platform/qt/include](include) directory. - -#### Linux and macOS - -#### QMapboxGL example application - -``` -$ make qt-lib # Will build libqmapboxgl.so -$ make qt-app # Will build the test app and libqmapboxgl.so if not built yet -$ make run-qt-app # Will build and run the test app -``` - -#### Windows - -``` -$ mkdir build -$ cd build -$ cmake -G Ninja -DMBGL_WITH_QT=ON -DCMAKE_BUILD_TYPE=Release .. -$ ninja -``` - -You may need to specify the path to Qt: - -``` -$ cmake -G Ninja -DMBGL_WITH_QT=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=C:\Qt\5.15.2\msvc2019_64\lib\cmake .. -``` - - -#### QNX 7.0 - -Building the repository for QNX 7.0 is very similar to other platforms (e.g. Linux and macOS). - -``` -$ make qnx-qt-lib # Will build libqmapboxgl.so -``` +For platform-specific details look at build scripts provided +in the [scripts](scripts) folder. Each script requires (at least) paths +to source and installation locations. diff --git a/platform/qt/include/qmapbox.hpp b/platform/qt/include/qmapbox.hpp index 3093e46d2..e9642343b 100644 --- a/platform/qt/include/qmapbox.hpp +++ b/platform/qt/include/qmapbox.hpp @@ -9,10 +9,14 @@ // This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style -#if defined(QT_BUILD_MAPBOXGL_LIB) -# define Q_MAPBOXGL_EXPORT Q_DECL_EXPORT +#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 #else -# define Q_MAPBOXGL_EXPORT Q_DECL_IMPORT +# define Q_MAPBOXGL_EXPORT #endif namespace QMapbox { diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index 06548632b..3f98b5b6a 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -4,13 +4,13 @@ message(STATUS "Configuring GL-Native with Qt bindings") file(READ "${PROJECT_SOURCE_DIR}/platform/qt/VERSION" MBGL_QT_VERSION) string(REGEX REPLACE "\n" "" MBGL_QT_VERSION "${MBGL_QT_VERSION}") # get rid of the newline at the end set(MBGL_QT_VERSION_COMPATIBILITY 2.0.0) -message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") message(STATUS "Version ${MBGL_QT_VERSION}") 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_QT_STATIC "Build Mapbox GL Qt bindings staticly" OFF) +option(MBGL_QT_INSIDE_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" $>) +option(MBGL_QT_WITH_INTERNAL_SQLITE "Build Mapbox GL Qt bindings with internal sqlite" OFF) find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) find_package(Qt${QT_VERSION_MAJOR} @@ -63,10 +63,10 @@ endif() if(ANDROID) message(STATUS "Building for ABI: ${ANDROID_ABI}") set(CMAKE_STATIC_LIBRARY_SUFFIX "_${ANDROID_ABI}.a") -elseif(MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_STATIC_LIBRARY_SUFFIX "d.lib") -elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_STATIC_LIBRARY_SUFFIX "d.a") +elseif(CMAKE_SYSTEM_NAME STREQUAL iOS) + set(CMAKE_DEBUG_POSTFIX "_debug") +elseif(MSVC OR CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(CMAKE_DEBUG_POSTFIX "d") endif() target_sources( @@ -150,7 +150,7 @@ set_property(TARGET mbgl-core PROPERTY AUTOMOC ON) target_link_libraries( mbgl-core PRIVATE - $<$>:z> + $<$,$>>:z> Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Network @@ -166,12 +166,10 @@ set(qmapboxgl_headers ${PROJECT_SOURCE_DIR}/platform/qt/include/qmapboxgl.hpp ) -if(MBGL_QT_STATIC) - if(MBGL_QT_INSIDE_QT_PLUGIN) - add_library(qmapboxgl OBJECT) - else() - add_library(qmapboxgl STATIC) - endif() +if (MBGL_QT_INSIDE_PLUGIN) + add_library(qmapboxgl OBJECT) +elseif(MBGL_QT_STATIC) + add_library(qmapboxgl STATIC) else() add_library(qmapboxgl SHARED) endif() @@ -206,7 +204,7 @@ set_target_properties( SOVERSION ${MBGL_QT_VERSION_COMPATIBILITY} PUBLIC_HEADER "${qmapboxgl_headers}" ) -if (NOT MBGL_QT_STATIC) +if (NOT MBGL_QT_STATIC AND NOT MBGL_QT_INSIDE_PLUGIN) set_target_properties( qmapboxgl PROPERTIES FRAMEWORK ON @@ -232,6 +230,8 @@ install(EXPORT QMapboxGLTargets DESTINATION ${CMAKECONFIG_INSTALL_DIR} COMPONENT development) +export(EXPORT QMapboxGLTargets) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/QMapboxGLConfigVersion.cmake" @@ -305,7 +305,7 @@ if(NOT MBGL_QT_LIBRARY_ONLY) target_compile_definitions( mbgl-qt PRIVATE - $<$:QT_MAPBOXGL_STATIC> + $<$,$>:QT_MAPBOXGL_STATIC> ) target_link_libraries( @@ -320,7 +320,7 @@ if(NOT MBGL_QT_LIBRARY_ONLY) target_include_directories( mbgl-qt - PUBLIC ${PROJECT_SOURCE_DIR}/platform/qt/include + PRIVATE ${PROJECT_SOURCE_DIR}/platform/qt/include ) add_executable( @@ -330,7 +330,7 @@ if(NOT MBGL_QT_LIBRARY_ONLY) target_include_directories( mbgl-test-runner - PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/test/include + PRIVATE ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/test/include ) target_compile_definitions( diff --git a/platform/qt/scripts/configure_Qt5_Android_static.sh b/platform/qt/scripts/configure_Qt5_Android_static.sh new file mode 100755 index 000000000..f0692a0c5 --- /dev/null +++ b/platform/qt/scripts/configure_Qt5_Android_static.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +if [[ -z ${1+x} ]]; then + echo "Error: Pass the path to maplibre-gl-native as first argument" 1>&2 + exit 1 +fi + +if [[ -z ${2+x} ]]; then + echo "Error: Pass the install prefix as the second argument" 1>&2 + exit 2 +fi + +if [[ -z ${3+x} ]]; then + echo "Error: Pass Qt installation path as the third argument" 1>&2 + exit 3 +fi + +if [[ -z ${4+x} ]]; then + echo "Error: Pass Android ABI as the fourth argument" 1>&2 + exit 3 +fi + +cmake "$1" \ +-DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake" \ +-DANDROID_ABI="$4" \ +-DANDROID_NATIVE_API_LEVEL=21 \ +-G Ninja \ +-DMBGL_WITH_QT=ON \ +-DMBGL_QT_STATIC=ON \ +-DMBGL_QT_LIBRARY_ONLY=ON \ +-DCMAKE_CXX_FLAGS_RELEASE=-g0 \ +-DCMAKE_INSTALL_PREFIX="$2" \ +-DCMAKE_FIND_ROOT_PATH="$3/android" \ +-DCMAKE_PREFIX_PATH="$3/android" diff --git a/platform/qt/scripts/configure_Qt5_Linux.sh b/platform/qt/scripts/configure_Qt5_Linux.sh new file mode 100755 index 000000000..8f5b88cb8 --- /dev/null +++ b/platform/qt/scripts/configure_Qt5_Linux.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +if [[ -z ${1+x} ]]; then + echo "Error: Pass the path to maplibre-gl-native as first argument" 1>&2 + exit 1 +fi + +if [[ -z ${2+x} ]]; then + echo "Error: Pass the install prefix as the second argument" 1>&2 + exit 2 +fi + +cmake "$1" \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DMBGL_WITH_QT=ON \ + -DCMAKE_INSTALL_PREFIX="$2" diff --git a/platform/qt/scripts/configure_Qt5_Windows.ps1 b/platform/qt/scripts/configure_Qt5_Windows.ps1 new file mode 100644 index 000000000..62cf0b6cc --- /dev/null +++ b/platform/qt/scripts/configure_Qt5_Windows.ps1 @@ -0,0 +1,8 @@ +$path = $args[0] +$install = $args[1] + +cmake -S "$path" ` + -GNinja ` + -DCMAKE_BUILD_TYPE="Release" ` + -DCMAKE_INSTALL_PREFIX="$install" ` + -DMBGL_WITH_QT=ON diff --git a/platform/qt/scripts/configure_Qt5_Windows_static.ps1 b/platform/qt/scripts/configure_Qt5_Windows_static.ps1 new file mode 100644 index 000000000..060ca3644 --- /dev/null +++ b/platform/qt/scripts/configure_Qt5_Windows_static.ps1 @@ -0,0 +1,10 @@ +$path = $args[0] +$install = $args[1] + +cmake -S "$path" ` + -GNinja ` + -DCMAKE_BUILD_TYPE="Release" ` + -DCMAKE_INSTALL_PREFIX="$install" ` + -DMBGL_WITH_QT=ON ` + -DMBGL_QT_STATIC=ON ` + -DMBGL_QT_LIBRARY_ONLY=ON diff --git a/platform/qt/scripts/configure_Qt5_iOS_static.sh b/platform/qt/scripts/configure_Qt5_iOS_static.sh new file mode 100755 index 000000000..dc9a8eb3b --- /dev/null +++ b/platform/qt/scripts/configure_Qt5_iOS_static.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +if [[ -z ${1+x} ]]; then + echo "Error: Pass the path to maplibre-gl-native as first argument" 1>&2 + exit 1 +fi + +if [[ -z ${2+x} ]]; then + echo "Error: Pass the install prefix as the second argument" 1>&2 + exit 2 +fi + +if [[ -z ${3+x} ]]; then + echo "Error: Pass Qt installation path as the third argument" 1>&2 + exit 3 +fi + +cmake "$1" \ + -G"Ninja Multi-Config" \ + -DCMAKE_SYSTEM_NAME=iOS \ + -DCMAKE_CONFIGURATION_TYPES="Release;Debug" \ + -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \ + -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0 \ + -DMBGL_WITH_QT=ON \ + -DMBGL_QT_STATIC=ON \ + -DMBGL_QT_LIBRARY_ONLY=ON \ + -DCMAKE_INSTALL_PREFIX="$2" \ + -DCMAKE_FIND_ROOT_PATH="$3/ios" \ + -DCMAKE_PREFIX_PATH="$3/ios" diff --git a/platform/qt/scripts/configure_Qt5_macOS.sh b/platform/qt/scripts/configure_Qt5_macOS.sh new file mode 100755 index 000000000..f47284e72 --- /dev/null +++ b/platform/qt/scripts/configure_Qt5_macOS.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +if [[ -z ${1+x} ]]; then + echo "Error: Pass the path to maplibre-gl-native as first argument" 1>&2 + exit 1 +fi + +if [[ -z ${2+x} ]]; then + echo "Error: Pass the install prefix as the second argument" 1>&2 + exit 2 +fi + +cmake "$1" \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 \ + -DMBGL_WITH_QT=ON \ + -DCMAKE_INSTALL_PREFIX="$2" diff --git a/platform/qt/scripts/configure_Qt5_macOS_static.sh b/platform/qt/scripts/configure_Qt5_macOS_static.sh new file mode 100755 index 000000000..50aa2ff11 --- /dev/null +++ b/platform/qt/scripts/configure_Qt5_macOS_static.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if [[ -z ${1+x} ]]; then + echo "Error: Pass the path to maplibre-gl-native as first argument" 1>&2 + exit 1 +fi + +if [[ -z ${2+x} ]]; then + echo "Error: Pass the install prefix as the second argument" 1>&2 + exit 2 +fi + +cmake "$1" \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 \ + -DMBGL_WITH_QT=ON \ + -DMBGL_QT_STATIC=ON \ + -DMBGL_QT_LIBRARY_ONLY=ON \ + -DCMAKE_INSTALL_PREFIX="$2" diff --git a/platform/qt/scripts/configure_Qt6_Windows.ps1 b/platform/qt/scripts/configure_Qt6_Windows.ps1 new file mode 100644 index 000000000..d9653eba5 --- /dev/null +++ b/platform/qt/scripts/configure_Qt6_Windows.ps1 @@ -0,0 +1,8 @@ +$path = $args[0] +$install = $args[1] + +qt-cmake -S "$path" ` + -GNinja ` + -DCMAKE_BUILD_TYPE="Release" ` + -DCMAKE_INSTALL_PREFIX="$install" ` + -DMBGL_WITH_QT=ON diff --git a/platform/qt/scripts/configure_Qt6_macOS.sh b/platform/qt/scripts/configure_Qt6_macOS.sh new file mode 100755 index 000000000..965efc232 --- /dev/null +++ b/platform/qt/scripts/configure_Qt6_macOS.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +if [[ -z ${1+x} ]]; then + echo "Error: Pass the path to maplibre-gl-native as first argument" 1>&2 + exit 1 +fi + +if [[ -z ${2+x} ]]; then + echo "Error: Pass the install prefix as the second argument" 1>&2 + exit 2 +fi + +qt-cmake "$1" \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_OSX_DEPLOYMENT_TARGET=10.14 \ + -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \ + -DMBGL_WITH_QT=ON \ + -DCMAKE_INSTALL_PREFIX="$2" diff --git a/platform/qt/scripts/configure_Qt6_macOS_static.sh b/platform/qt/scripts/configure_Qt6_macOS_static.sh new file mode 100755 index 000000000..656289e16 --- /dev/null +++ b/platform/qt/scripts/configure_Qt6_macOS_static.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +if [[ -z ${1+x} ]]; then + echo "Error: Pass the path to maplibre-gl-native as first argument" 1>&2 + exit 1 +fi + +if [[ -z ${2+x} ]]; then + echo "Error: Pass the install prefix as the second argument" 1>&2 + exit 2 +fi + +qt-cmake "$1" \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_OSX_DEPLOYMENT_TARGET=10.14 \ + -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \ + -DMBGL_WITH_QT=ON \ + -DMBGL_QT_STATIC=ON \ + -DMBGL_QT_LIBRARY_ONLY=ON \ + -DCMAKE_INSTALL_PREFIX="$2" diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index b99087809..0d9413aa1 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -68,6 +68,11 @@ using namespace QMapbox; +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4805) +#endif + // mbgl::GLContextMode static_assert(mbgl::underlying_type(QMapboxGLSettings::UniqueGLContext) == mbgl::underlying_type(mbgl::gfx::ContextMode::Unique), "error"); static_assert(mbgl::underlying_type(QMapboxGLSettings::SharedGLContext) == mbgl::underlying_type(mbgl::gfx::ContextMode::Shared), "error"); @@ -91,6 +96,11 @@ static_assert(mbgl::underlying_type(QMapboxGL::NorthRightwards) == mbgl::underly static_assert(mbgl::underlying_type(QMapboxGL::NorthDownwards) == mbgl::underlying_type(mbgl::NorthOrientation::Downwards), "error"); static_assert(mbgl::underlying_type(QMapboxGL::NorthLeftwards) == mbgl::underlying_type(mbgl::NorthOrientation::Leftwards), "error"); +#ifdef _MSC_VER +#pragma warning(pop) +#endif + + namespace { QThreadStorage> loop; @@ -984,7 +994,7 @@ mbgl::optional asMapboxGLAnnotation(const QMapbox::Annotation */ QMapbox::AnnotationID QMapboxGL::addAnnotation(const QMapbox::Annotation &annotation) { - return d_ptr->mapObj->addAnnotation(*asMapboxGLAnnotation(annotation)); + return static_cast(d_ptr->mapObj->addAnnotation(*asMapboxGLAnnotation(annotation))); } /*! diff --git a/platform/qt/src/qt_geojson.cpp b/platform/qt/src/qt_geojson.cpp index 27f867dec..4198be6e8 100644 --- a/platform/qt/src/qt_geojson.cpp +++ b/platform/qt/src/qt_geojson.cpp @@ -1,7 +1,4 @@ #include "qt_geojson.hpp" -#include -#include -#include #pragma clang diagnostic ignored "-Wenum-compare-switch" diff --git a/platform/qt/src/timer.cpp b/platform/qt/src/timer.cpp index 05876c24c..e7e1195c0 100644 --- a/platform/qt/src/timer.cpp +++ b/platform/qt/src/timer.cpp @@ -18,7 +18,11 @@ void Timer::Impl::start(uint64_t timeout, uint64_t repeat_, std::function= QT_VERSION_CHECK(5, 8, 0) + timer.start(static_cast(timeout)); +#else + timer.start(static_cast(timeout)); +#endif } void Timer::Impl::stop() { @@ -28,7 +32,11 @@ void Timer::Impl::stop() { void Timer::Impl::timerFired() { if (repeat) { timer.setSingleShot(false); - timer.start(repeat); +#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) + timer.start(static_cast(repeat)); +#else + timer.start(static_cast(repeat)); +#endif } callback(); diff --git a/platform/qt/test/main.cpp b/platform/qt/test/main.cpp index 73ca7f403..92570ab09 100644 --- a/platform/qt/test/main.cpp +++ b/platform/qt/test/main.cpp @@ -18,7 +18,11 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); #ifdef WORK_DIRECTORY +#ifdef _MSC_VER + const int result = _chdir(xstr(WORK_DIRECTORY)); +#else const int result = chdir(xstr(WORK_DIRECTORY)); +#endif if (result != 0) { fprintf(stderr, "failed to change directory: %s\n", strerror(errno)); return errno; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a0a704a34..466b3c0c9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -229,4 +229,11 @@ target_link_libraries( $<$,$>:psapi> ) +if(MSVC) + target_compile_definitions( + mbgl-test + PRIVATE MBGL_BUILDING_LIB + ) +endif() + set_property(TARGET mbgl-test PROPERTY FOLDER Core) diff --git a/vendor/csscolorparser.cmake b/vendor/csscolorparser.cmake index 1cb8605ed..c8ce21719 100644 --- a/vendor/csscolorparser.cmake +++ b/vendor/csscolorparser.cmake @@ -2,7 +2,7 @@ if(TARGET mbgl-vendor-csscolorparser) return() endif() -if(MBGL_QT_STATIC) +if(MBGL_WITH_QT AND ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0") add_library(mbgl-vendor-csscolorparser OBJECT) else() add_library(mbgl-vendor-csscolorparser STATIC) @@ -23,6 +23,10 @@ target_include_directories( PUBLIC ${CMAKE_CURRENT_LIST_DIR}/csscolorparser ) +if(MSVC) + target_compile_options(mbgl-vendor-csscolorparser PRIVATE /wd4244) +endif() + set_target_properties( mbgl-vendor-csscolorparser PROPERTIES diff --git a/vendor/icu.cmake b/vendor/icu.cmake index f3f3d76e2..7eb048e97 100644 --- a/vendor/icu.cmake +++ b/vendor/icu.cmake @@ -43,3 +43,8 @@ target_include_directories( ) set_property(TARGET mbgl-vendor-icu PROPERTY FOLDER Core) + +export(TARGETS + mbgl-vendor-icu + APPEND FILE MapboxCoreTargets.cmake +) diff --git a/vendor/nunicode.cmake b/vendor/nunicode.cmake index b21581b44..6bfd716e1 100644 --- a/vendor/nunicode.cmake +++ b/vendor/nunicode.cmake @@ -2,7 +2,7 @@ if(TARGET mbgl-vendor-nunicode) return() endif() -if(MBGL_QT_STATIC) +if(MBGL_WITH_QT AND ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0") add_library(mbgl-vendor-nunicode OBJECT) else() add_library(mbgl-vendor-nunicode STATIC) @@ -24,7 +24,9 @@ target_compile_definitions( PRIVATE NU_BUILD_STATIC ) -if(NOT MSVC) +if(MSVC) + target_compile_options(mbgl-vendor-nunicode PRIVATE /wd4146) +else() target_compile_options(mbgl-vendor-nunicode PRIVATE -Wno-error) endif() @@ -32,3 +34,8 @@ target_include_directories( mbgl-vendor-nunicode SYSTEM PUBLIC ${CMAKE_CURRENT_LIST_DIR}/nunicode/include ) + +export(TARGETS + mbgl-vendor-nunicode + APPEND FILE MapboxCoreTargets.cmake +) diff --git a/vendor/parsedate.cmake b/vendor/parsedate.cmake index 5bd94410c..c57c1f869 100644 --- a/vendor/parsedate.cmake +++ b/vendor/parsedate.cmake @@ -2,7 +2,7 @@ if(TARGET mbgl-vendor-parsedate) return() endif() -if(MBGL_QT_STATIC) +if(MBGL_WITH_QT AND ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0") add_library(mbgl-vendor-parsedate OBJECT) else() add_library(mbgl-vendor-parsedate STATIC) diff --git a/vendor/sqlite.cmake b/vendor/sqlite.cmake index b010e0c78..9c7e61285 100644 --- a/vendor/sqlite.cmake +++ b/vendor/sqlite.cmake @@ -27,3 +27,8 @@ target_include_directories( mbgl-vendor-sqlite SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/sqlite/include ) + +export(TARGETS + mbgl-vendor-sqlite + APPEND FILE MapboxCoreTargets.cmake +)