From 5dbd98aeb6563a155acac432f82896a121b6f75d Mon Sep 17 00:00:00 2001 From: Tadej Novak Date: Sat, 14 Oct 2023 21:56:26 +0200 Subject: [PATCH] Update CMake packaging and test with examples (#42) --- .github/actions/qt6-build/entrypoint.sh | 25 ++++ .github/workflows/Linux-Test.yml | 32 ++++- .github/workflows/Linux.yml | 2 +- .github/workflows/macOS.yml | 52 +++++++- CMakeLists.txt | 8 +- README.md | 27 +++- examples/minimal/CMakeLists.txt | 27 ---- examples/quick/CMakeLists.txt | 45 +++++++ examples/{minimal => quick}/main.cpp | 4 +- examples/{minimal => quick}/main.qml | 24 ++-- examples/{minimal => quick}/minimal.pro | 0 examples/{minimal => quick}/qml.qrc | 0 examples/widgets/CMakeLists.txt | 41 ++++++ examples/widgets/main.cpp | 18 +++ examples/widgets/mainwindow.cpp | 30 +++++ examples/widgets/mainwindow.hpp | 20 +++ examples/widgets/window.cpp | 61 +++++++++ examples/widgets/window.hpp | 34 +++++ src/CMakeLists.txt | 28 +++++ src/config.cmake.in | 33 +++++ src/core/CMakeLists.txt | 159 +++++++++++------------- src/core/config.cmake.in | 15 --- src/location/CMakeLists.txt | 116 ++++++++--------- src/location/config.cmake.in | 4 - src/location/macros.cmake | 24 ++++ src/location/plugins/CMakeLists.txt | 70 +++++++---- src/widgets/CMakeLists.txt | 124 ++++++++---------- src/widgets/config.cmake.in | 8 -- test/core/CMakeLists.txt | 19 +-- test/qml/CMakeLists.txt | 7 +- test/widgets/CMakeLists.txt | 10 +- 31 files changed, 735 insertions(+), 332 deletions(-) delete mode 100644 examples/minimal/CMakeLists.txt create mode 100644 examples/quick/CMakeLists.txt rename examples/{minimal => quick}/main.cpp (76%) rename examples/{minimal => quick}/main.qml (76%) rename examples/{minimal => quick}/minimal.pro (100%) rename examples/{minimal => quick}/qml.qrc (100%) create mode 100644 examples/widgets/CMakeLists.txt create mode 100644 examples/widgets/main.cpp create mode 100644 examples/widgets/mainwindow.cpp create mode 100644 examples/widgets/mainwindow.hpp create mode 100644 examples/widgets/window.cpp create mode 100644 examples/widgets/window.hpp create mode 100644 src/config.cmake.in delete mode 100644 src/core/config.cmake.in delete mode 100644 src/location/config.cmake.in create mode 100644 src/location/macros.cmake delete mode 100644 src/widgets/config.cmake.in diff --git a/.github/actions/qt6-build/entrypoint.sh b/.github/actions/qt6-build/entrypoint.sh index 95fde75..c9cd64f 100755 --- a/.github/actions/qt6-build/entrypoint.sh +++ b/.github/actions/qt6-build/entrypoint.sh @@ -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 .. diff --git a/.github/workflows/Linux-Test.yml b/.github/workflows/Linux-Test.yml index 4416db9..47994cb 100644 --- a/.github/workflows/Linux-Test.yml +++ b/.github/workflows/Linux-Test.yml @@ -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) @@ -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 diff --git a/.github/workflows/Linux.yml b/.github/workflows/Linux.yml index 3108156..1ad2617 100644 --- a/.github/workflows/Linux.yml +++ b/.github/workflows/Linux.yml @@ -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 }} diff --git a/.github/workflows/macOS.yml b/.github/workflows/macOS.yml index 841d8a0..4c617a3 100644 --- a/.github/workflows/macOS.yml +++ b/.github/workflows/macOS.yml @@ -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' diff --git a/CMakeLists.txt b/CMakeLists.txt index 496e0ab..432db74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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() diff --git a/README.md b/README.md index 0562b7d..b0c610c 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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/ -GNinja \ + -DCMAKE_C_COMPILER_LAUNCHER="ccache" \ + -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \ + -DCMAKE_PREFIX_PATH="" +ninja +``` + +For macOS a deployment target `deploy` is provided for convenience. + ## Copyright Copyright (C) 2023 MapLibre contributors diff --git a/examples/minimal/CMakeLists.txt b/examples/minimal/CMakeLists.txt deleted file mode 100644 index 393dc50..0000000 --- a/examples/minimal/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -project(minimal VERSION 1.0.0 LANGUAGES CXX) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -find_package(Qt6 REQUIRED COMPONENTS Quick Gui) -qt_standard_project_setup() - -qt_add_executable(minimal - main.cpp -) - -qt_add_qml_module(minimal - URI minimal - VERSION 1.0 - QML_FILES - main.qml -) - -set_target_properties(minimal PROPERTIES - WIN32_EXECUTABLE ON - MACOSX_BUNDLE ON -) - -target_link_libraries(minimal PRIVATE Qt6::Gui Qt6::Quick) diff --git a/examples/quick/CMakeLists.txt b/examples/quick/CMakeLists.txt new file mode 100644 index 0000000..9bb7f76 --- /dev/null +++ b/examples/quick/CMakeLists.txt @@ -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() diff --git a/examples/minimal/main.cpp b/examples/quick/main.cpp similarity index 76% rename from examples/minimal/main.cpp rename to examples/quick/main.cpp index fe08f5a..5c85da5 100644 --- a/examples/minimal/main.cpp +++ b/examples/quick/main.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2022 MapLibre contributors +// Copyright (C) 2023 MapLibre contributors // SPDX-License-Identifier: MIT @@ -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(); } diff --git a/examples/minimal/main.qml b/examples/quick/main.qml similarity index 76% rename from examples/minimal/main.qml rename to examples/quick/main.qml index b94b7ee..4990944 100644 --- a/examples/minimal/main.qml +++ b/examples/quick/main.qml @@ -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 @@ -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" } } @@ -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 } } } diff --git a/examples/minimal/minimal.pro b/examples/quick/minimal.pro similarity index 100% rename from examples/minimal/minimal.pro rename to examples/quick/minimal.pro diff --git a/examples/minimal/qml.qrc b/examples/quick/qml.qrc similarity index 100% rename from examples/minimal/qml.qrc rename to examples/quick/qml.qrc diff --git a/examples/widgets/CMakeLists.txt b/examples/widgets/CMakeLists.txt new file mode 100644 index 0000000..cf95d8a --- /dev/null +++ b/examples/widgets/CMakeLists.txt @@ -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() diff --git a/examples/widgets/main.cpp b/examples/widgets/main.cpp new file mode 100644 index 0000000..897342b --- /dev/null +++ b/examples/widgets/main.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2023 MapLibre contributors + +// SPDX-License-Identifier: MIT + +#include "mainwindow.hpp" + +#include + +int main(int argc, char **argv) { + QApplication app(argc, argv); + + MainWindow window; + + window.resize(800, 600); + window.show(); + + return app.exec(); +} diff --git a/examples/widgets/mainwindow.cpp b/examples/widgets/mainwindow.cpp new file mode 100644 index 0000000..d5a874a --- /dev/null +++ b/examples/widgets/mainwindow.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2023 MapLibre contributors + +// SPDX-License-Identifier: MIT + +#include "mainwindow.hpp" + +#include "window.hpp" + +#include +#include +#include + +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.")); +} diff --git a/examples/widgets/mainwindow.hpp b/examples/widgets/mainwindow.hpp new file mode 100644 index 0000000..a52c79d --- /dev/null +++ b/examples/widgets/mainwindow.hpp @@ -0,0 +1,20 @@ +// Copyright (C) 2023 MapLibre contributors + +// SPDX-License-Identifier: MIT + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +class MainWindow : public QMainWindow { + Q_OBJECT + +public: + explicit MainWindow(); + +private slots: + void onAddNew(); +}; + +#endif diff --git a/examples/widgets/window.cpp b/examples/widgets/window.cpp new file mode 100644 index 0000000..f7e0ad1 --- /dev/null +++ b/examples/widgets/window.cpp @@ -0,0 +1,61 @@ +// Copyright (C) 2023 MapLibre contributors + +// SPDX-License-Identifier: MIT + +#include "window.hpp" + +#include "mainwindow.hpp" + +#include + +#include +#include +#include +#include + +Window::Window(MainWindow *mainWindow) + : QWidget(mainWindow), + m_mainWindow(mainWindow) { + QMapLibre::Settings settings; + m_glWidget = new QMapLibre::GLWidget(settings); + + auto *layout = new QVBoxLayout; + layout->addWidget(m_glWidget); + m_buttonDock = new QPushButton(tr("Undock"), this); + connect(m_buttonDock, &QPushButton::clicked, this, &Window::dockUndock); + layout->addWidget(m_buttonDock); + + setLayout(layout); + + setWindowTitle(tr("Hello QMapLibre")); +} + +void Window::keyPressEvent(QKeyEvent *e) { + if (e->key() == Qt::Key_Escape) + close(); + else + QWidget::keyPressEvent(e); +} + +void Window::dockUndock() { + if (parent()) { + setParent(nullptr); + setAttribute(Qt::WA_DeleteOnClose); + move(QGuiApplication::primaryScreen()->size().width() / 2 - width() / 2, + QGuiApplication::primaryScreen()->size().height() / 2 - height() / 2); + m_buttonDock->setText(tr("Dock")); + show(); + } else { + if (!m_mainWindow->centralWidget()) { + if (m_mainWindow->isVisible()) { + setAttribute(Qt::WA_DeleteOnClose, false); + m_buttonDock->setText(tr("Undock")); + m_mainWindow->setCentralWidget(this); + } else { + QMessageBox::information(nullptr, tr("Cannot dock"), tr("Main window already closed")); + } + } else { + QMessageBox::information(nullptr, tr("Cannot dock"), tr("Main window already occupied")); + } + } +} diff --git a/examples/widgets/window.hpp b/examples/widgets/window.hpp new file mode 100644 index 0000000..d280ff4 --- /dev/null +++ b/examples/widgets/window.hpp @@ -0,0 +1,34 @@ +// Copyright (C) 2023 MapLibre contributors + +// SPDX-License-Identifier: MIT + +#ifndef WINDOW_H +#define WINDOW_H + +#include +#include + +namespace QMapLibre { +class GLWidget; +} +class MainWindow; + +class Window : public QWidget { + Q_OBJECT + +public: + explicit Window(MainWindow *mainWindow); + +protected: + void keyPressEvent(QKeyEvent *event) override; + +private slots: + void dockUndock(); + +private: + QMapLibre::GLWidget *m_glWidget; + QPushButton *m_buttonDock; + MainWindow *m_mainWindow; +}; + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 63bccb1..f76de0b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,9 +1,37 @@ +# Packaging and export +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) +set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${MLN_QT_NAME}/) + +# Components add_subdirectory(core) +set(MLN_QT_SUPPORTED_COMPONENTS "Core") if (MLN_QT_WITH_LOCATION) add_subdirectory(location) + list(APPEND MLN_QT_SUPPORTED_COMPONENTS "Location") message(STATUS "Building location module") endif() if (MLN_QT_WITH_WIDGETS) add_subdirectory(widgets) + list(APPEND MLN_QT_SUPPORTED_COMPONENTS "Widgets") message(STATUS "Building widgets module") endif() + +# Setup package and install +configure_package_config_file( + "config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_NAME}Config.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}/${MLN_QT_NAME}ConfigVersion.cmake + VERSION ${MLN_QT_VERSION} + COMPATIBILITY AnyNewerVersion) + +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_NAME}ConfigVersion.cmake + DESTINATION ${CMAKECONFIG_INSTALL_DIR} +) diff --git a/src/config.cmake.in b/src/config.cmake.in new file mode 100644 index 0000000..f355986 --- /dev/null +++ b/src/config.cmake.in @@ -0,0 +1,33 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +set(_@MLN_QT_NAME@_supported_components @MLN_QT_SUPPORTED_COMPONENTS@) + +foreach(_comp ${@MLN_QT_NAME@_FIND_COMPONENTS}) + if (NOT _comp IN_LIST _@MLN_QT_NAME@_supported_components) + set(@MLN_QT_NAME@_FOUND False) + set(@MLN_QT_NAME@_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}") + endif() + + if (_comp STREQUAL Core) + find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS Gui Network) + if(NOT @MLN_QT_WITH_INTERNAL_SQLITE@) + find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS Sql) + endif() + elseif(_comp STREQUAL Location) + find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS Location) + + include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_NAME@${_comp}Macros.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_NAME@${_comp}PluginGeoServicesTargets.cmake") + elseif(_comp STREQUAL Widgets) + find_dependency(@MLN_QT_NAME@ COMPONENTS Core) + if (@QT_VERSION_MAJOR@ EQUAL 6) + find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS OpenGLWidgets Widgets) + else() + find_dependency(Qt@QT_VERSION_MAJOR@ COMPONENTS OpenGL Widgets) + endif() + endif() + + include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_NAME@${_comp}Targets.cmake") +endforeach() diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index a1d8c62..a92b2c3 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -11,7 +11,7 @@ add_subdirectory( ) # Public headers -string(TOLOWER ${MLN_QT_CORE_LIB} MLN_QT_CORE_LIB_LOWERCASE) +string(TOLOWER ${MLN_QT_NAME} MLN_QT_NAME_LOWERCASE) set(Core_Headers export.hpp map.hpp @@ -20,80 +20,83 @@ set(Core_Headers utils.hpp ) # Header generation -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_CORE_LIB}/${MLN_QT_CORE_LIB}" "#include \"${MLN_QT_CORE_LIB_LOWERCASE}.hpp\"") -list(APPEND Core_Headers_Generated "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_CORE_LIB}/${MLN_QT_CORE_LIB}") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_NAME}/${MLN_QT_NAME}" "#include \"${MLN_QT_NAME_LOWERCASE}.hpp\"") +list(APPEND Core_Headers_Generated "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_NAME}/${MLN_QT_NAME}") foreach(Header ${Core_Headers}) string(SUBSTRING ${Header} 0 1 HeaderFirstLetter) string(TOUPPER ${HeaderFirstLetter} HeaderFirstLetter) string(REGEX REPLACE "^.(.*)" "${HeaderFirstLetter}\\1" HeaderOut "${Header}") string(REGEX REPLACE "\.hpp" "" HeaderOut "${HeaderOut}") - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_CORE_LIB}/${HeaderOut}" "#include \"${Header}\"") - list(APPEND Core_Headers_Generated "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_CORE_LIB}/${HeaderOut}") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_NAME}/${HeaderOut}" "#include \"${Header}\"") + list(APPEND Core_Headers_Generated "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_NAME}/${HeaderOut}") endforeach() -set(Core_Headers ${MLN_QT_CORE_LIB_LOWERCASE}.hpp ${Core_Headers} ${Core_Headers_Generated}) +set(Core_Headers ${MLN_QT_NAME_LOWERCASE}.hpp ${Core_Headers} ${Core_Headers_Generated}) # Make a Qt library if(COMMAND qt_add_library) - qt_add_library(${MLN_QT_CORE_LIB}) + qt_add_library(Core) else() - add_library(${MLN_QT_CORE_LIB} SHARED) + add_library(Core SHARED) endif() +add_library(${MLN_QT_NAME}::Core ALIAS Core) # Main sources target_sources( - ${MLN_QT_CORE_LIB} + Core PRIVATE - ${Core_Headers} - conversion_p.hpp - geojson.cpp - geojson_p.hpp - map_observer.cpp - map_observer_p.hpp - map_p.hpp - map_renderer.cpp - map_renderer_p.hpp - map.cpp - renderer_backend.cpp - renderer_backend_p.hpp - renderer_observer_p.hpp - scheduler.cpp - scheduler_p.hpp - settings.cpp - types.cpp - utils.cpp + ${Core_Headers} + conversion_p.hpp + geojson.cpp + geojson_p.hpp + map_observer.cpp + map_observer_p.hpp + map_p.hpp + map_renderer.cpp + map_renderer_p.hpp + map.cpp + renderer_backend.cpp + renderer_backend_p.hpp + renderer_observer_p.hpp + scheduler.cpp + scheduler_p.hpp + settings.cpp + types.cpp + utils.cpp ) # Linux/Mac: Set framework, version and headers set_target_properties( - ${MLN_QT_CORE_LIB} PROPERTIES - AUTOMOC ON - EXPORT_NAME ${MLN_QT_CORE_LIB} - OUTPUT_NAME ${MLN_QT_CORE_LIB} - VERSION ${MLN_QT_VERSION} - SOVERSION ${MLN_QT_VERSION_COMPATIBILITY} - PUBLIC_HEADER "${Core_Headers}" + Core + PROPERTIES + AUTOMOC ON + OUTPUT_NAME ${MLN_QT_NAME} + VERSION ${MLN_QT_VERSION} + SOVERSION ${MLN_QT_VERSION_COMPATIBILITY} + PUBLIC_HEADER "${Core_Headers}" ) # Qt MOC if (Qt6_FOUND AND COMMAND qt_enable_autogen_tool) - qt_enable_autogen_tool(${MLN_QT_CORE_LIB} "moc" ON) + qt_enable_autogen_tool(Core "moc" ON) endif() # Common compile definitions target_compile_definitions( - ${MLN_QT_CORE_LIB} + Core PRIVATE - QT_BUILD_MAPLIBRE_LIB + QT_BUILD_MAPLIBRE_LIB ) # static? # target_compile_definitions( -# ${MLN_QT_CORE_LIB} +# Core # PUBLIC QT_MAPLIBRE_STATIC # ) # Common include directories target_include_directories( - ${MLN_QT_CORE_LIB} + Core + PUBLIC + $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/include @@ -102,7 +105,7 @@ target_include_directories( # Common link libraries target_link_libraries( - ${MLN_QT_CORE_LIB} + Core PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui @@ -112,65 +115,51 @@ target_link_libraries( $ $ ) +if (NOT MLN_QT_WITH_INTERNAL_SQLITE) + target_link_libraries( + Core + PUBLIC + Qt${QT_VERSION_MAJOR}::Sql + ) +endif() # Apple specifics if (APPLE) set_target_properties( - ${MLN_QT_CORE_LIB} PROPERTIES - FRAMEWORK ON - FRAMEWORK_VERSION A - MACOSX_FRAMEWORK_IDENTIFIER org.maplibre.${MLN_QT_CORE_LIB} - MACOSX_FRAMEWORK_BUNDLE_VERSION ${MLN_QT_VERSION} - MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MLN_QT_VERSION} + Core + PROPERTIES + FRAMEWORK ON + FRAMEWORK_VERSION A + MACOSX_FRAMEWORK_IDENTIFIER org.maplibre.${MLN_QT_NAME} + MACOSX_FRAMEWORK_BUNDLE_VERSION ${MLN_QT_VERSION} + MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MLN_QT_VERSION} ) target_include_directories( - ${MLN_QT_CORE_LIB} + Core INTERFACE - $ + $ ) endif() -# Configuration and installation -include(GNUInstallDirs) -include(CMakePackageConfigHelpers) -set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${MLN_QT_CORE_LIB}/) - -configure_package_config_file( - "config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_CORE_LIB}Config.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}/${MLN_QT_CORE_LIB}ConfigVersion.cmake - VERSION ${MLN_QT_VERSION} - COMPATIBILITY AnyNewerVersion) - -install(EXPORT ${MLN_QT_CORE_LIB}Targets - DESTINATION ${CMAKECONFIG_INSTALL_DIR} - COMPONENT development) - -export(EXPORT ${MLN_QT_CORE_LIB}Targets) - -install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_CORE_LIB}Config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_CORE_LIB}ConfigVersion.cmake" - DESTINATION ${CMAKECONFIG_INSTALL_DIR} - COMPONENT development) +# Export and installation +install( + EXPORT ${MLN_QT_NAME}CoreTargets + NAMESPACE ${MLN_QT_NAMESPACE} + DESTINATION ${CMAKECONFIG_INSTALL_DIR}) install( DIRECTORY ${CMAKE_SOURCE_DIR}/vendor/maplibre-native/include/mbgl DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" - COMPONENT development ) -install(TARGETS ${MLN_QT_CORE_LIB} - EXPORT ${MLN_QT_CORE_LIB}Targets - # 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}/${MLN_QT_CORE_LIB}" +install( + TARGETS Core + EXPORT ${MLN_QT_NAME}CoreTargets + # 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}/${MLN_QT_NAME}" ) diff --git a/src/core/config.cmake.in b/src/core/config.cmake.in deleted file mode 100644 index 842ff46..0000000 --- a/src/core/config.cmake.in +++ /dev/null @@ -1,15 +0,0 @@ -@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(NOT @MLN_QT_WITH_INTERNAL_SQLITE@) - find_dependency(Qt@QT_VERSION_MAJOR@ - COMPONENTS Sql @REQUIRED_QT_VERSION@) -endif() - -include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_CORE_LIB@Targets.cmake") -@PACKAGE_INCLUDE_QCHTARGETS@ diff --git a/src/location/CMakeLists.txt b/src/location/CMakeLists.txt index d7f9c15..edfcd2c 100644 --- a/src/location/CMakeLists.txt +++ b/src/location/CMakeLists.txt @@ -1,44 +1,45 @@ # Make a Qt library if(COMMAND qt_add_library) - qt_add_library(${MLN_QT_LOCATION_LIB}) + qt_add_library(Location) else() - add_library(${MLN_QT_LOCATION_LIB} SHARED) + add_library(Location SHARED) endif() +add_library(${MLN_QT_NAME}::Location ALIAS Location) target_sources( - ${MLN_QT_LOCATION_LIB} + Location PRIVATE - qgeomap.cpp qgeomap.hpp qgeomap_p.hpp - qt_mapping_engine.cpp qt_mapping_engine.hpp - stylechange.cpp stylechange_p.h - texture_node.cpp texture_node.hpp + qgeomap.cpp qgeomap.hpp qgeomap_p.hpp + qt_mapping_engine.cpp qt_mapping_engine.hpp + stylechange.cpp stylechange_p.h + texture_node.cpp texture_node.hpp ) # Linux/Mac: Set framework, version and headers set_target_properties( - ${MLN_QT_LOCATION_LIB} PROPERTIES - AUTOMOC ON - EXPORT_NAME ${MLN_QT_LOCATION_LIB} - OUTPUT_NAME ${MLN_QT_LOCATION_LIB} - VERSION ${MLN_QT_VERSION} - SOVERSION ${MLN_QT_VERSION_COMPATIBILITY} + Location + PROPERTIES + AUTOMOC ON + OUTPUT_NAME ${MLN_QT_NAME}Location + VERSION ${MLN_QT_VERSION} + SOVERSION ${MLN_QT_VERSION_COMPATIBILITY} ) # Qt MOC if (Qt6_FOUND AND COMMAND qt_enable_autogen_tool) - qt_enable_autogen_tool(${MLN_QT_LOCATION_LIB} "moc" ON) + qt_enable_autogen_tool(Location "moc" ON) endif() # Common compile definitions target_compile_definitions( - ${MLN_QT_LOCATION_LIB} + Location PRIVATE - QT_BUILD_MAPLIBRE_LIB + QT_BUILD_MAPLIBRE_LIB ) # Common include directories target_include_directories( - ${MLN_QT_LOCATION_LIB} + Location PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/include @@ -48,69 +49,56 @@ target_include_directories( # Common link libraries target_link_libraries( - ${MLN_QT_LOCATION_LIB} - PUBLIC - ${MLN_QT_CORE_LIB} + Location PRIVATE - $<$:Qt::OpenGL> - Qt::Network - Qt::LocationPrivate + Core + $<$:Qt::OpenGL> + Qt::Network + Qt::LocationPrivate ) # Apple specifics if (APPLE) set_target_properties( - ${MLN_QT_LOCATION_LIB} PROPERTIES - FRAMEWORK ON - FRAMEWORK_VERSION A - MACOSX_FRAMEWORK_IDENTIFIER org.maplibre.${MLN_QT_LOCATION_LIB} - MACOSX_FRAMEWORK_BUNDLE_VERSION ${MLN_QT_VERSION} - MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MLN_QT_VERSION} + Location + PROPERTIES + FRAMEWORK ON + FRAMEWORK_VERSION A + MACOSX_FRAMEWORK_IDENTIFIER org.maplibre.${MLN_QT_NAME}Location + MACOSX_FRAMEWORK_BUNDLE_VERSION ${MLN_QT_VERSION} + MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MLN_QT_VERSION} ) target_include_directories( - ${MLN_QT_LOCATION_LIB} + Location INTERFACE - $ + $ ) endif() -# Configuration and installation -include(GNUInstallDirs) -include(CMakePackageConfigHelpers) -set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${MLN_QT_LOCATION_LIB}/) - -configure_package_config_file( - "config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_LOCATION_LIB}Config.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}/${MLN_QT_LOCATION_LIB}ConfigVersion.cmake - VERSION ${MLN_QT_VERSION} - COMPATIBILITY AnyNewerVersion) - -install(EXPORT ${MLN_QT_LOCATION_LIB}Targets +# Export and installation +install( + EXPORT ${MLN_QT_NAME}LocationTargets + NAMESPACE ${MLN_QT_NAMESPACE} DESTINATION ${CMAKECONFIG_INSTALL_DIR} - COMPONENT development) +) -export(EXPORT ${MLN_QT_LOCATION_LIB}Targets) +install( + TARGETS Location + EXPORT ${MLN_QT_NAME}LocationTargets + # 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}/${MLN_QT_NAME}Location" +) -install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_LOCATION_LIB}Config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_LOCATION_LIB}ConfigVersion.cmake" +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/macros.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_NAME}LocationMacros.cmake" COPYONLY) +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_NAME}LocationMacros.cmake DESTINATION ${CMAKECONFIG_INSTALL_DIR} - COMPONENT development) - -install(TARGETS ${MLN_QT_LOCATION_LIB} - EXPORT ${MLN_QT_LOCATION_LIB}Targets - # 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}/${MLN_QT_LOCATION_LIB}" ) # plugins diff --git a/src/location/config.cmake.in b/src/location/config.cmake.in deleted file mode 100644 index 0c81e1e..0000000 --- a/src/location/config.cmake.in +++ /dev/null @@ -1,4 +0,0 @@ -@PACKAGE_INIT@ - -include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_LOCATION_LIB@Targets.cmake") -@PACKAGE_INCLUDE_QCHTARGETS@ diff --git a/src/location/macros.cmake b/src/location/macros.cmake new file mode 100644 index 0000000..2731055 --- /dev/null +++ b/src/location/macros.cmake @@ -0,0 +1,24 @@ +function(qmaplibre_location_copy_plugin target) + if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + return() + endif() + + string(TOUPPER "${CMAKE_BUILD_TYPE}" _BuildConfiguration) + get_target_property(_ImportedConfigurations QMapLibre::PluginGeoServices IMPORTED_CONFIGURATIONS) + if(NOT _BuildConfiguration) + list(GET _ImportedConfigurations 0 _Configuration) + elseif(_BuildConfiguration IN_LIST _ImportedConfigurations) + set(_Configuration ${_BuildConfiguration}) + else() + list(GET _ImportedConfigurations 0 _Configuration) + endif() + + get_target_property(_ImportedLocation QMapLibre::PluginGeoServices IMPORTED_LOCATION_${_Configuration}) + + get_property(_targetName TARGET ${target} PROPERTY OUTPUT_NAME) + if (NOT _targetName) + set(_targetName ${target}) + endif() + + file(COPY "${_ImportedLocation}" DESTINATION "${_targetName}.app/Contents/PlugIns/geoservices") +endfunction() diff --git a/src/location/plugins/CMakeLists.txt b/src/location/plugins/CMakeLists.txt index c24a267..2512200 100644 --- a/src/location/plugins/CMakeLists.txt +++ b/src/location/plugins/CMakeLists.txt @@ -12,8 +12,13 @@ else() endif() # QtLocation plugin extra target properties -set_property(TARGET ${MLN_QT_GEOSERVICES_PLUGIN} PROPERTY AUTOMOC ON) -set_property(TARGET ${MLN_QT_GEOSERVICES_PLUGIN} PROPERTY LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/geoservices") +set_target_properties( + ${MLN_QT_GEOSERVICES_PLUGIN} + PROPERTIES + AUTOMOC ON + EXPORT_NAME PluginGeoServices + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/geoservices" +) # QtLocation plugin include directories target_include_directories( @@ -23,15 +28,23 @@ target_include_directories( ${CMAKE_BINARY_DIR}/src/core/include ) -# Qt Location plugin linked libraries -target_link_libraries(${MLN_QT_GEOSERVICES_PLUGIN} +# QtLocation plugin linked libraries +target_link_libraries( + ${MLN_QT_GEOSERVICES_PLUGIN} PRIVATE - ${MLN_QT_LOCATION_LIB} - Qt::Location - Qt::LocationPrivate) + Location + Qt::Location + Qt::LocationPrivate) # QtLocation plugin installation -install(TARGETS ${MLN_QT_GEOSERVICES_PLUGIN} +install( + EXPORT ${MLN_QT_NAME}LocationPluginGeoServicesTargets + NAMESPACE ${MLN_QT_NAMESPACE} + DESTINATION ${CMAKECONFIG_INSTALL_DIR} +) +install( + TARGETS ${MLN_QT_GEOSERVICES_PLUGIN} + EXPORT ${MLN_QT_NAME}LocationPluginGeoServicesTargets LIBRARY DESTINATION "plugins/geoservices" ) @@ -52,10 +65,15 @@ else() add_library(${MLN_QT_QML_PLUGIN} SHARED qml_types.hpp legacy/qml_module.cpp legacy/qml_registration.cpp) target_compile_definitions(${MLN_QT_QML_PLUGIN} PRIVATE QT_PLUGIN) target_include_directories(${MLN_QT_QML_PLUGIN} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - set_property(TARGET ${MLN_QT_QML_PLUGIN} PROPERTY AUTOMOC ON) - set_property(TARGET ${MLN_QT_QML_PLUGIN} PROPERTY LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre") + set_target_properties( + ${MLN_QT_QML_PLUGIN} + PROPERTIES + AUTOMOC ON + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre" + ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/legacy/qmldir.in" "${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre/qmldir" @ONLY) endif() +set_property(TARGET ${MLN_QT_QML_PLUGIN} PROPERTY EXPORT_NAME PluginQml) # QtLocation QML extension plugin include directories target_include_directories( @@ -66,24 +84,34 @@ target_include_directories( ) # QtLocation QML extension plugin linked libraries -target_link_libraries(${MLN_QT_QML_PLUGIN} +target_link_libraries( + ${MLN_QT_QML_PLUGIN} PRIVATE - ${MLN_QT_LOCATION_LIB} - Qt::LocationPrivate + Location + Qt::LocationPrivate ) # QtLocation QML extension plugin installation -install(TARGETS ${MLN_QT_QML_PLUGIN} - LIBRARY DESTINATION "qml/QtLocation/MapLibre" +install( + EXPORT ${MLN_QT_NAME}LocationPluginQmlTargets + NAMESPACE ${MLN_QT_NAMESPACE} + DESTINATION ${CMAKECONFIG_INSTALL_DIR} +) +install( + TARGETS ${MLN_QT_QML_PLUGIN} + EXPORT ${MLN_QT_NAME}LocationPluginQmlTargets + LIBRARY DESTINATION "qml/QtLocation/MapLibre" ) -install(FILES +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre/qmldir" DESTINATION "qml/QtLocation/MapLibre" - COMPONENT development) +) if (COMMAND qt_add_qml_module) - install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre/${MLN_QT_QML_PLUGIN}.qmltypes" - DESTINATION "qml/QtLocation/MapLibre" - COMPONENT development) + install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/QtLocation/MapLibre/${MLN_QT_QML_PLUGIN}.qmltypes" + DESTINATION "qml/QtLocation/MapLibre" +) endif() diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index 460762f..b52f50c 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -1,56 +1,59 @@ # Public headers -string(TOLOWER ${MLN_QT_WIDGETS_LIB} MLN_QT_WIDGETS_LIB_LOWERCASE) +string(TOLOWER ${MLN_QT_NAME}Widgets MLN_QT_WIDGETS_LOWERCASE) set(Widgets_Headers gl_widget.hpp ) # Header generation -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_WIDGETS_LIB}/${MLN_QT_WIDGETS_LIB}" "#include \"${MLN_QT_WIDGETS_LIB_LOWERCASE}.hpp\"") -list(APPEND Widgets_Headers_Generated "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_WIDGETS_LIB}/${MLN_QT_WIDGETS_LIB}") -file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_WIDGETS_LIB}/GLWidget" "#include \"gl_widget.hpp\"") -list(APPEND Widgets_Headers_Generated "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_WIDGETS_LIB}/GLWidget") -set(Widgets_Headers ${MLN_QT_WIDGETS_LIB_LOWERCASE}.hpp ${Widgets_Headers} ${Widgets_Headers_Generated}) +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_NAME}Widgets/${MLN_QT_NAME}Widgets" "#include \"${MLN_QT_WIDGETS_LOWERCASE}.hpp\"") +list(APPEND Widgets_Headers_Generated "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_NAME}Widgets/${MLN_QT_NAME}Widgets") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_NAME}Widgets/GLWidget" "#include \"gl_widget.hpp\"") +list(APPEND Widgets_Headers_Generated "${CMAKE_CURRENT_BINARY_DIR}/include/${MLN_QT_NAME}Widgets/GLWidget") +set(Widgets_Headers ${MLN_QT_WIDGETS_LOWERCASE}.hpp ${Widgets_Headers} ${Widgets_Headers_Generated}) # Make a Qt library if(COMMAND qt_add_library) - qt_add_library(${MLN_QT_WIDGETS_LIB}) + qt_add_library(Widgets) else() - add_library(${MLN_QT_WIDGETS_LIB} SHARED) + add_library(Widgets SHARED) endif() +add_library(${MLN_QT_NAME}::Widgets ALIAS Core) target_sources( - ${MLN_QT_WIDGETS_LIB} + Widgets PRIVATE - ${Widgets_Headers} - gl_widget.cpp - gl_widget_p.hpp + ${Widgets_Headers} + gl_widget.cpp + gl_widget_p.hpp ) # Linux/Mac: Set framework, version and headers set_target_properties( - ${MLN_QT_WIDGETS_LIB} PROPERTIES - AUTOMOC ON - EXPORT_NAME ${MLN_QT_WIDGETS_LIB} - OUTPUT_NAME ${MLN_QT_WIDGETS_LIB} - VERSION ${MLN_QT_VERSION} - SOVERSION ${MLN_QT_VERSION_COMPATIBILITY} - PUBLIC_HEADER "${Widgets_Headers}" + Widgets + PROPERTIES + AUTOMOC ON + OUTPUT_NAME ${MLN_QT_NAME}Widgets + VERSION ${MLN_QT_VERSION} + SOVERSION ${MLN_QT_VERSION_COMPATIBILITY} + PUBLIC_HEADER "${Widgets_Headers}" ) # Qt MOC if (Qt6_FOUND AND COMMAND qt_enable_autogen_tool) - qt_enable_autogen_tool(${MLN_QT_WIDGETS_LIB} "moc" ON) + qt_enable_autogen_tool(Widgets "moc" ON) endif() # Common compile definitions target_compile_definitions( - ${MLN_QT_WIDGETS_LIB} + Widgets PRIVATE - QT_BUILD_MAPLIBRE_LIB + QT_BUILD_MAPLIBRE_LIB ) # Common include directories target_include_directories( - ${MLN_QT_WIDGETS_LIB} + Widgets + PUBLIC + $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/include @@ -60,19 +63,19 @@ target_include_directories( # Common link libraries target_link_libraries( - ${MLN_QT_WIDGETS_LIB} + Widgets PUBLIC - ${MLN_QT_CORE_LIB} + Core ) if (Qt6_FOUND) target_link_libraries( - ${MLN_QT_WIDGETS_LIB} + Widgets PUBLIC Qt${QT_VERSION_MAJOR}::OpenGLWidgets ) else() target_link_libraries( - ${MLN_QT_WIDGETS_LIB} + Widgets PUBLIC Qt${QT_VERSION_MAJOR}::OpenGL ) @@ -81,55 +84,36 @@ endif() # Apple specifics if (APPLE) set_target_properties( - ${MLN_QT_WIDGETS_LIB} PROPERTIES - FRAMEWORK ON - FRAMEWORK_VERSION A - MACOSX_FRAMEWORK_IDENTIFIER org.maplibre.${MLN_QT_WIDGETS_LIB} - MACOSX_FRAMEWORK_BUNDLE_VERSION ${MLN_QT_VERSION} - MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MLN_QT_VERSION} + Widgets + PROPERTIES + FRAMEWORK ON + FRAMEWORK_VERSION A + MACOSX_FRAMEWORK_IDENTIFIER org.maplibre.${MLN_QT_NAME}Widgets + MACOSX_FRAMEWORK_BUNDLE_VERSION ${MLN_QT_VERSION} + MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${MLN_QT_VERSION} ) target_include_directories( - ${MLN_QT_WIDGETS_LIB} + Widgets INTERFACE - $ + $ ) endif() -# Configuration and installation -include(GNUInstallDirs) -include(CMakePackageConfigHelpers) -set(CMAKECONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${MLN_QT_WIDGETS_LIB}/) - -configure_package_config_file( - "config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_WIDGETS_LIB}Config.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}/${MLN_QT_WIDGETS_LIB}ConfigVersion.cmake - VERSION ${MLN_QT_VERSION} - COMPATIBILITY AnyNewerVersion) - -install(EXPORT ${MLN_QT_WIDGETS_LIB}Targets +# Export and installation +install( + EXPORT ${MLN_QT_NAME}WidgetsTargets + NAMESPACE ${MLN_QT_NAMESPACE} DESTINATION ${CMAKECONFIG_INSTALL_DIR} - COMPONENT development) - -export(EXPORT ${MLN_QT_WIDGETS_LIB}Targets) - -install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_WIDGETS_LIB}Config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/${MLN_QT_WIDGETS_LIB}ConfigVersion.cmake" - DESTINATION ${CMAKECONFIG_INSTALL_DIR} - COMPONENT development) +) -install(TARGETS ${MLN_QT_WIDGETS_LIB} - EXPORT ${MLN_QT_WIDGETS_LIB}Targets - # 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}/${MLN_QT_WIDGETS_LIB}" +install( + TARGETS Widgets + EXPORT ${MLN_QT_NAME}WidgetsTargets + # 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}/${MLN_QT_NAME}Widgets" ) diff --git a/src/widgets/config.cmake.in b/src/widgets/config.cmake.in deleted file mode 100644 index 053b28a..0000000 --- a/src/widgets/config.cmake.in +++ /dev/null @@ -1,8 +0,0 @@ -@PACKAGE_INIT@ - -include(CMakeFindDependencyMacro) -find_dependency(Qt@QT_VERSION_MAJOR@ - COMPONENTS OpenGLWidgets @REQUIRED_QT_VERSION@) - -include("${CMAKE_CURRENT_LIST_DIR}/@MLN_QT_WIDGETS_LIB@Targets.cmake") -@PACKAGE_INCLUDE_QCHTARGETS@ diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index 196afb3..3e0e6fe 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -13,7 +13,8 @@ else() add_executable(test_mln_core ${test_sources}) endif() -target_include_directories(test_mln_core +target_include_directories( + test_mln_core PRIVATE ${CMAKE_SOURCE_DIR}/src/core ${CMAKE_BINARY_DIR}/src/core/include @@ -21,14 +22,18 @@ target_include_directories(test_mln_core ) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Test REQUIRED) -target_link_libraries(test_mln_core +target_link_libraries( + test_mln_core PRIVATE - $<$:Qt::OpenGLWidgets> - Qt::Test - ${MLN_QT_CORE_LIB} + $<$:Qt::OpenGLWidgets> + Qt::Test + Core ) set_target_properties(test_mln_core PROPERTIES AUTOMOC ON) add_test(NAME test_mln_core COMMAND $) -set_tests_properties(test_mln_core PROPERTIES - ENVIRONMENT "MLN_FIXTURES_PATH=${CMAKE_SOURCE_DIR}/vendor/maplibre-native/test/fixtures") +set_tests_properties( + test_mln_core + PROPERTIES + ENVIRONMENT "MLN_FIXTURES_PATH=${CMAKE_SOURCE_DIR}/vendor/maplibre-native/test/fixtures" +) diff --git a/test/qml/CMakeLists.txt b/test/qml/CMakeLists.txt index 990dab8..71d7c5f 100644 --- a/test/qml/CMakeLists.txt +++ b/test/qml/CMakeLists.txt @@ -8,5 +8,8 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS QuickTest REQUIRED) target_link_libraries(test_mln_qml PRIVATE Qt::QuickTest) add_test(NAME test_mln_qml COMMAND $ -input ${CMAKE_CURRENT_SOURCE_DIR}/qt${QT_VERSION_MAJOR}) -set_tests_properties(test_mln_qml PROPERTIES - ENVIRONMENT "DYLD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/core:${CMAKE_BINARY_DIR}/src/location;QSG_RHI_BACKEND=opengl;QML_IMPORT_PATH=${CMAKE_BINARY_DIR}/src/location/plugins;QML2_IMPORT_PATH=${CMAKE_BINARY_DIR}/src/location/plugins;QT_PLUGIN_PATH=${CMAKE_BINARY_DIR}/src/location/plugins") +set_tests_properties( + test_mln_qml + PROPERTIES + ENVIRONMENT "DYLD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/core:${CMAKE_BINARY_DIR}/src/location;QSG_RHI_BACKEND=opengl;QML_IMPORT_PATH=${CMAKE_BINARY_DIR}/src/location/plugins;QML2_IMPORT_PATH=${CMAKE_BINARY_DIR}/src/location/plugins;QT_PLUGIN_PATH=${CMAKE_BINARY_DIR}/src/location/plugins" +) diff --git a/test/widgets/CMakeLists.txt b/test/widgets/CMakeLists.txt index 7b326d9..59063d6 100644 --- a/test/widgets/CMakeLists.txt +++ b/test/widgets/CMakeLists.txt @@ -9,7 +9,8 @@ else() add_executable(test_mln_widgets ${test_sources}) endif() -target_include_directories(test_mln_widgets +target_include_directories( + test_mln_widgets PRIVATE ${CMAKE_SOURCE_DIR}/src/core ${CMAKE_BINARY_DIR}/src/core/include @@ -19,10 +20,11 @@ target_include_directories(test_mln_widgets ) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Test REQUIRED) -target_link_libraries(test_mln_widgets +target_link_libraries( + test_mln_widgets PRIVATE - Qt::Test - ${MLN_QT_WIDGETS_LIB} + Qt::Test + Widgets ) set_target_properties(test_mln_widgets PROPERTIES AUTOMOC ON)