From dd2aee2f70aebddbdd086c004b55842762cb568d Mon Sep 17 00:00:00 2001 From: AmonRaNet Date: Tue, 8 Feb 2022 12:03:10 +0100 Subject: [PATCH] Parametrized QT version --- demo/CMakeLists.txt | 52 +++++++++++++++----------------------- lib/CMakeLists.txt | 61 +++++++++++++++++++-------------------------- 2 files changed, 46 insertions(+), 67 deletions(-) diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt index 35c467a..4052192 100644 --- a/demo/CMakeLists.txt +++ b/demo/CMakeLists.txt @@ -5,22 +5,21 @@ set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) -find_package(Qt6 COMPONENTS - Core - Gui - Network - Widgets - ) +# Set the QT version +find_package(Qt6 COMPONENTS Core QUIET) if (NOT Qt6_FOUND) - message("Qt6 components not found. Attempting to find Qt5 components...") - find_package(Qt5 REQUIRED COMPONENTS - Core - Gui - Widgets - Network - ) + set(QT_VERSION 5 CACHE STRING "Qt version for QGeoView") +else() + set(QT_VERSION 6 CACHE STRING "Qt version for QGeoView") endif() +find_package(Qt${QT_VERSION} REQUIRED COMPONENTS + Core + Gui + Widgets + Network +) + add_executable(qgeoview-demo main.cpp mainwindow.h @@ -58,22 +57,11 @@ add_executable(qgeoview-demo samples/mytile.h ) -if (Qt6_FOUND) - target_link_libraries(qgeoview-demo - PRIVATE - Qt6::Core - Qt6::Network - Qt6::Gui - Qt6::Widgets - QGeoView - ) -else() - target_link_libraries(qgeoview-demo - PRIVATE - Qt5::Core - Qt5::Network - Qt5::Gui - Qt5::Widgets - QGeoView - ) -endif() +target_link_libraries(qgeoview-demo + PRIVATE + Qt${QT_VERSION}::Core + Qt${QT_VERSION}::Network + Qt${QT_VERSION}::Gui + Qt${QT_VERSION}::Widgets + QGeoView +) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 78f25b3..8d289e1 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,24 +1,24 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_AUTOMOC ON) -find_package(Qt6 COMPONENTS - Core - Gui - Widgets - Network - ) +# Set the QT version +find_package(Qt6 COMPONENTS Core QUIET) if (NOT Qt6_FOUND) - message("Qt6 components not found. Attempting to find Qt5 components...") - find_package(Qt5 REQUIRED COMPONENTS - Core - Gui - Widgets - Network - ) + set(QT_VERSION 5 CACHE STRING "Qt version for QGeoView") +else() + set(QT_VERSION 6 CACHE STRING "Qt version for QGeoView") endif() +find_package(Qt${QT_VERSION} REQUIRED COMPONENTS + Core + Gui + Widgets + Network +) + add_library(qgeoview SHARED include/QGeoView/QGVGlobal.h + include/QGeoView/QGVUtils.h include/QGeoView/QGVProjection.h include/QGeoView/QGVProjectionEPSG3857.h include/QGeoView/QGVCamera.h @@ -40,6 +40,7 @@ add_library(qgeoview SHARED include/QGeoView/QGVWidgetScale.h include/QGeoView/QGVWidgetZoom.h include/QGeoView/QGVWidgetText.h + src/QGVUtils.cpp src/QGVGlobal.cpp src/QGVProjection.cpp src/QGVProjectionEPSG3857.cpp @@ -76,34 +77,24 @@ target_compile_definitions(qgeoview QGV_EXPORT ) -if (Qt6_FOUND) - target_link_libraries(qgeoview - PRIVATE - Qt6::Core - Qt6::Gui - Qt6::Widgets - Qt6::Network - ) -else() - target_link_libraries(qgeoview - PRIVATE - Qt5::Core - Qt5::Gui - Qt5::Widgets - Qt5::Network - ) -endif() +target_link_libraries(qgeoview + PRIVATE + Qt${QT_VERSION}::Core + Qt${QT_VERSION}::Gui + Qt${QT_VERSION}::Widgets + Qt${QT_VERSION}::Network +) add_library(QGeoView ALIAS qgeoview) install(TARGETS qgeoview LIBRARY - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib/static + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static ) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ - DESTINATION include - FILES_MATCHING PATTERN "*.h*" + DESTINATION include + FILES_MATCHING PATTERN "*.h*" )