Skip to content

Commit

Permalink
Update CMake packaging and test with examples (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej authored Oct 14, 2023
1 parent 6486434 commit 5dbd98a
Show file tree
Hide file tree
Showing 31 changed files with 735 additions and 332 deletions.
25 changes: 25 additions & 0 deletions .github/actions/qt6-build/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,28 @@ qt-cmake ../source/ \
ninja
# ninja test
ninja install
cd ..

export PREFIX_PATH="$(pwd)/install"

# QtQuick example
mkdir build-example-quick && cd build-example-quick
qt-cmake ../source/examples/quick/ \
-G Ninja \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_PREFIX_PATH="$PREFIX_PATH"
ninja
cd ..

# QtWidgets example
mkdir build-example-widgets && cd build-example-widgets
qt-cmake ../source/examples/widgets/ \
-G Ninja \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_PREFIX_PATH="$PREFIX_PATH"
ninja
cd ..
32 changes: 29 additions & 3 deletions .github/workflows/Linux-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
- name: Set up ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: Linux_QMapLibre_${{ matrix.qt_version }}
key: Linux_QMapLibre_${{ matrix.qt_version }}_${{ matrix.compiler }}
append-timestamp: false

- name: Build QMapLibre (Qt 6)
Expand All @@ -118,14 +118,40 @@ jobs:
run: ctest --output-on-failure
working-directory: build

- name: Build QtQuick Example (Qt 6)
if: matrix.qt_series == 6
run: |
export PREFIX_PATH="$(pwd)/install"
mkdir build-example-quick && cd build-example-quick
qt-cmake ../source/examples/quick/ \
-G Ninja \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_PREFIX_PATH="$PREFIX_PATH"
ninja
- name: Build QtWidgets Example (Qt 6)
if: matrix.qt_series == 6
run: |
export PREFIX_PATH="$(pwd)/install"
mkdir build-example-widgets && cd build-example-widgets
qt-cmake ../source/examples/widgets/ \
-G Ninja \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_PREFIX_PATH="$PREFIX_PATH"
ninja
- name: Create artifacts
run: |
pushd install
tar cjvf ../QMapLibre_Linux.tar.bz2 *
popd
- name: Upload artifacts
- name: Upload installation
uses: actions/upload-artifact@v3
with:
name: QMapLibre_Linux_${{ matrix.qt_version }}
name: QMapLibre_Linux_${{ matrix.qt_version }}_${{ matrix.compiler }}
path: QMapLibre_Linux.tar.bz2
2 changes: 1 addition & 1 deletion .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
tar cjvf ../QMapLibre_Linux.tar.bz2 *
popd
- name: Upload artifacts
- name: Upload installationUpload artifacts
uses: actions/upload-artifact@v3
with:
name: QMapLibre_Linux_${{ matrix.qt_version }}
Expand Down
52 changes: 50 additions & 2 deletions .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,66 @@ jobs:
ninja test
ninja install
- name: Create artifacts
- name: Build QtQuick Example (Qt 6)
if: matrix.qt_series == 6
run: |
export PREFIX_PATH="$(pwd)/install"
mkdir build-example-quick && cd build-example-quick
qt-cmake ../source/examples/quick/ \
-G Ninja \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="11.0" \
-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
-DCMAKE_PREFIX_PATH="$PREFIX_PATH"
ninja
ninja deploy
- name: Build QtWidgets Example (Qt 6)
if: matrix.qt_series == 6
run: |
export PREFIX_PATH="$(pwd)/install"
mkdir build-example-widgets && cd build-example-widgets
qt-cmake ../source/examples/widgets/ \
-G Ninja \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="11.0" \
-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" \
-DCMAKE_PREFIX_PATH="$PREFIX_PATH"
ninja
ninja deploy
- name: Compress installation
run: |
pushd install
tar cjvf ../QMapLibre_macOS.tar.bz2 *
popd
- name: Upload artifacts
- name: Compress examples
if: matrix.qt_series == 6
run: |
mkdir examples && pushd examples
cp -a ../build-example-quick/QMapLibreExampleQuick.app .
cp -a ../build-example-widgets/QMapLibreExampleWidgets.app .
tar cjvf ../QMapLibre_macOS_examples.tar.bz2 *
popd
- name: Upload installation
uses: actions/upload-artifact@v3
with:
name: QMapLibre_macOS_${{ matrix.qt_version }}
path: QMapLibre_macOS.tar.bz2

- name: Upload examples
if: matrix.qt_series == 6
uses: actions/upload-artifact@v3
with:
name: QMapLibre_macOS_${{ matrix.qt_version }}_examples
path: QMapLibre_macOS_examples.tar.bz2

release:
name: Release QMapLibre
if: github.ref_type == 'tag'
Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

# Common QMapLibre definitions
set(MLN_QT_CORE_LIB QMapLibre)
set(MLN_QT_LOCATION_LIB QMapLibreLocation)
set(MLN_QT_WIDGETS_LIB QMapLibreWidgets)
set(MLN_QT_NAME QMapLibre)
set(MLN_QT_NAMESPACE ${MLN_QT_NAME}::)
set(MLN_QT_GEOSERVICES_PLUGIN qtgeoservices_maplibre)
set(MLN_QT_QML_PLUGIN declarative_locationplugin_maplibre)

Expand All @@ -36,6 +35,9 @@ set(MLN_QT_WITH_WIDGETS ON CACHE BOOL "Build QMapLibreWidgets")
# Find Qt
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui Network REQUIRED) # main dependencies
if (NOT MLN_QT_WITH_INTERNAL_SQLITE)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Sql REQUIRED)
endif()
if (MLN_QT_WITH_LOCATION)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Location REQUIRED) # location
endif()
Expand Down
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ Qt 5.15 is fully supported only on desktop platforms.

## How to build?

Both plugin and MapLibre build in one step. Ninja is recommended.
Both plugin and MapLibre build in one step. `ninja` and `ccache` are recommended.
For Qt 6 using the `qt-cmake` wrapper is recommended.

```shell
cmake ../maplibre-native-qt -GNinja
mkdir build && cd build
cmake ../maplibre-native-qt -GNinja \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_INSTALL_PREFIX="../install"
ninja
ninja install
```
Expand All @@ -34,6 +38,25 @@ Add the following arguments to the CMake call:
Add the following arguments to the CMake call:
`-G"Ninja Multi-Config" -DCMAKE_CONFIGURATION_TYPES="Release;Debug"`

## How to use?

Once installed `QMapLibre` can be used in any Qt and CMake project.
Two example projects based on Qt 6 are available in the
[examples](examples) directory.

To build an example, run the following commands:

```shell
mkdir build-example && cd build-example
qt-cmake ../maplibre-native-qt/examples/<example> -GNinja \
-DCMAKE_C_COMPILER_LAUNCHER="ccache" \
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
-DCMAKE_PREFIX_PATH="<absolute-path-to-install>"
ninja
```

For macOS a deployment target `deploy` is provided for convenience.

## Copyright

Copyright (C) 2023 MapLibre contributors
Expand Down
27 changes: 0 additions & 27 deletions examples/minimal/CMakeLists.txt

This file was deleted.

45 changes: 45 additions & 0 deletions examples/quick/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.19)

project(QMapLibreExampleQuick VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(Qt6 REQUIRED COMPONENTS Quick REQUIRED)
qt_standard_project_setup()

find_package(QMapLibre COMPONENTS Location REQUIRED)

qt_add_executable(QMapLibreExampleQuick
main.cpp
)

qt_add_qml_module(QMapLibreExampleQuick
URI Example
VERSION 1.0
RESOURCE_PREFIX "/"
QML_FILES
main.qml
)

set_target_properties(QMapLibreExampleQuick PROPERTIES
WIN32_EXECUTABLE ON
MACOSX_BUNDLE ON
)

target_link_libraries(QMapLibreExampleQuick
PRIVATE
Qt::Quick
QMapLibre::Location
)

qmaplibre_location_copy_plugin(QMapLibreExampleQuick)

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_custom_target(deploy
COMMAND macdeployqt QMapLibreExampleQuick.app -qmldir=${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_dependencies(deploy QMapLibreExampleQuick)
endif()
4 changes: 2 additions & 2 deletions examples/minimal/main.cpp → examples/quick/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2022 MapLibre contributors
// Copyright (C) 2023 MapLibre contributors

// SPDX-License-Identifier: MIT

Expand All @@ -16,7 +16,7 @@ int main(int argc, char *argv[]) {
QGuiApplication app(argc, argv);

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/minimal/main.qml")));
engine.load(QUrl(QStringLiteral("qrc:/Example/main.qml")));

return app.exec();
}
24 changes: 12 additions & 12 deletions examples/minimal/main.qml → examples/quick/main.qml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (C) 2022 MapLibre contributors
// Copyright (C) 2023 MapLibre contributors

// SPDX-License-Identifier: MIT

import QtQuick 2.15
import QtQuick.Window 2.15
import QtLocation 5.15
import QtPositioning 5.15
import QtQuick 6.5
import QtQuick.Window 6.5
import QtLocation 6.5
import QtPositioning 6.5

Window {
id: window
Expand Down Expand Up @@ -37,10 +37,10 @@ Window {

Plugin {
id: mapPlugin
name: "maplibregl"
name: "maplibre"
// specify plugin parameters if necessary
PluginParameter {
name: "maplibregl.mapping.additional_style_urls"
name: "maplibre.map.style_urls"
value: "https://demotiles.maplibre.org/style.json"
}
}
Expand All @@ -50,14 +50,14 @@ Window {
anchors.fill: parent
anchors.topMargin: fullWindow ? 0 : Math.round(parent.height / 3)

Map {
id: map
MapView {
id: mapView
anchors.fill: parent
anchors.topMargin: fullWindow ? 0 : Math.round(parent.height / 6)
anchors.leftMargin: fullWindow ? 0 : Math.round(parent.width / 6)
plugin: mapPlugin
center: window.coordinate
zoomLevel: 5
map.plugin: mapPlugin
map.center: window.coordinate
map.zoomLevel: 5
}
}
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5dbd98a

Please sign in to comment.