Skip to content

Commit

Permalink
Update CMake packaging and test with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej committed Oct 14, 2023
1 parent 4a5c563 commit 297c928
Show file tree
Hide file tree
Showing 30 changed files with 704 additions and 328 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 ..
28 changes: 27 additions & 1 deletion .github/workflows/Linux-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,39 @@ 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 }}
Expand Down
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
48 changes: 46 additions & 2 deletions .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,62 @@ 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_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_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: 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.
41 changes: 41 additions & 0 deletions examples/widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.19)

project(QMapLibreExampleWidgets VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(APPLE) # suppress some warnings in Qt6
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(Qt6 REQUIRED COMPONENTS Widgets REQUIRED)
qt_standard_project_setup()

find_package(QMapLibre COMPONENTS Widgets REQUIRED)

qt_add_executable(QMapLibreExampleWidgets
main.cpp
mainwindow.cpp
mainwindow.hpp
window.cpp
window.hpp
)

set_target_properties(QMapLibreExampleWidgets PROPERTIES
WIN32_EXECUTABLE ON
MACOSX_BUNDLE ON
)

target_link_libraries(QMapLibreExampleWidgets
PRIVATE
QMapLibre::Widgets
)

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_custom_target(deploy
COMMAND macdeployqt QMapLibreExampleWidgets.app
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_dependencies(deploy QMapLibreExampleWidgets)
endif()
18 changes: 18 additions & 0 deletions examples/widgets/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2023 MapLibre contributors

// SPDX-License-Identifier: MIT

#include "mainwindow.hpp"

#include <QApplication>

int main(int argc, char **argv) {
QApplication app(argc, argv);

MainWindow window;

window.resize(800, 600);
window.show();

return app.exec();
}
30 changes: 30 additions & 0 deletions examples/widgets/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2023 MapLibre contributors

// SPDX-License-Identifier: MIT

#include "mainwindow.hpp"

#include "window.hpp"

#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>

MainWindow::MainWindow() {
auto *menuBar = new QMenuBar(this);
QMenu *menuWindow = menuBar->addMenu(tr("&Window"));
auto *actionAddNew = new QAction(menuWindow);
actionAddNew->setText(tr("Add new"));
menuWindow->addAction(actionAddNew);
connect(actionAddNew, &QAction::triggered, this, &MainWindow::onAddNew);
setMenuBar(menuBar);

onAddNew();
}

void MainWindow::onAddNew() {
if (!centralWidget())
setCentralWidget(new Window(this));
else
QMessageBox::information(nullptr, tr("Cannot add new window"), tr("Already occupied. Undock first."));
}
Loading

0 comments on commit 297c928

Please sign in to comment.