diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-09-25 21:35:04 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-09-28 13:48:36 -0400 |
commit | 64c75b442c4d387e4867757abf49462c561e5955 (patch) | |
tree | 63f572961f6309a851d2e85ebe191e6a3cb7e5ab /platform/qt | |
parent | d73e33eb62858b91212314d97bfe9cf49e857141 (diff) | |
download | qtlocation-mapboxgl-64c75b442c4d387e4867757abf49462c561e5955.tar.gz |
[build] split out DefaultFileSource and dependents to a separate target
We don't want to link it into the node bindings, so keep it in a separate target
Diffstat (limited to 'platform/qt')
-rw-r--r-- | platform/qt/config.cmake | 28 | ||||
-rw-r--r-- | platform/qt/qt.cmake | 75 | ||||
-rw-r--r-- | platform/qt/qt4.cmake | 25 | ||||
-rw-r--r-- | platform/qt/qt5.cmake | 28 | ||||
-rw-r--r-- | platform/qt/src/headless_backend_qt.cpp (renamed from platform/qt/test/headless_backend_qt.cpp) | 0 | ||||
-rw-r--r-- | platform/qt/test/qmapboxgl.cpp | 99 | ||||
-rw-r--r-- | platform/qt/test/qmapboxgl.test.cpp | 77 | ||||
-rw-r--r-- | platform/qt/test/qmapboxgl.test.hpp | 36 |
8 files changed, 192 insertions, 176 deletions
diff --git a/platform/qt/config.cmake b/platform/qt/config.cmake index 732fb1de28..a7fdbf3542 100644 --- a/platform/qt/config.cmake +++ b/platform/qt/config.cmake @@ -15,7 +15,7 @@ endif() macro(mbgl_platform_core) target_sources(mbgl-core - ${MBGL_QT_FILES} + ${MBGL_QT_CORE_FILES} ) target_include_directories(mbgl-core @@ -24,7 +24,7 @@ macro(mbgl_platform_core) ) target_link_libraries(mbgl-core - ${MBGL_QT_LIBRARIES} + ${MBGL_QT_CORE_LIBRARIES} ) if(NOT WITH_QT_DECODERS) @@ -50,17 +50,23 @@ macro(mbgl_platform_core) endmacro() + +macro(mbgl_filesource) + target_sources(mbgl-filesource + ${MBGL_QT_FILESOURCE_FILES} + ) + + target_link_libraries(mbgl-filesource + ${MBGL_QT_FILESOURCE_LIBRARIES} + ) +endmacro() + + macro(mbgl_platform_test) target_sources(mbgl-test - PRIVATE platform/default/mbgl/gl/headless_frontend.cpp - PRIVATE platform/default/mbgl/gl/headless_frontend.hpp - PRIVATE platform/default/mbgl/gl/headless_backend.cpp - PRIVATE platform/default/mbgl/gl/headless_backend.hpp - PRIVATE platform/default/mbgl/gl/headless_display.cpp - PRIVATE platform/default/mbgl/gl/headless_display.hpp - PRIVATE platform/qt/test/headless_backend_qt.cpp PRIVATE platform/qt/test/main.cpp - PRIVATE platform/qt/test/qmapboxgl.cpp + PRIVATE platform/qt/test/qmapboxgl.test.cpp + PRIVATE platform/qt/test/qmapboxgl.test.cpp ) set_source_files_properties( @@ -72,7 +78,7 @@ macro(mbgl_platform_test) target_link_libraries(mbgl-test PRIVATE qmapboxgl - ${MBGL_QT_TEST_LIBRARIES} + PRIVATE mbgl-filesource ) endmacro() diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index 489ae5ed08..2346d7d820 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -10,22 +10,16 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -D__QT__") set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(MBGL_QT_FILES - # File source - PRIVATE platform/default/asset_file_source.cpp - PRIVATE platform/default/default_file_source.cpp - PRIVATE platform/default/local_file_source.cpp - PRIVATE platform/default/online_file_source.cpp - - # Offline - PRIVATE platform/default/mbgl/storage/offline.cpp - PRIVATE platform/default/mbgl/storage/offline_database.cpp - PRIVATE platform/default/mbgl/storage/offline_database.hpp - PRIVATE platform/default/mbgl/storage/offline_download.cpp - PRIVATE platform/default/mbgl/storage/offline_download.hpp - PRIVATE platform/default/sqlite3.hpp +set(MBGL_QT_CORE_FILES + # Headless view + PRIVATE platform/default/mbgl/gl/headless_frontend.cpp + PRIVATE platform/default/mbgl/gl/headless_frontend.hpp + PRIVATE platform/default/mbgl/gl/headless_backend.cpp + PRIVATE platform/default/mbgl/gl/headless_backend.hpp + PRIVATE platform/default/mbgl/gl/headless_display.cpp + PRIVATE platform/default/mbgl/gl/headless_display.hpp + PRIVATE platform/qt/src/headless_backend_qt.cpp # Misc PRIVATE platform/default/logging_stderr.cpp @@ -42,22 +36,24 @@ set(MBGL_QT_FILES # Platform integration PRIVATE platform/qt/src/async_task.cpp PRIVATE platform/qt/src/async_task_impl.hpp - PRIVATE platform/qt/src/http_file_source.cpp - PRIVATE platform/qt/src/http_file_source.hpp - PRIVATE platform/qt/src/http_request.cpp - PRIVATE platform/qt/src/http_request.hpp PRIVATE platform/qt/src/qt_image.cpp PRIVATE platform/qt/src/run_loop.cpp PRIVATE platform/qt/src/run_loop_impl.hpp - PRIVATE platform/qt/src/sqlite3.cpp PRIVATE platform/qt/src/string_stdlib.cpp PRIVATE platform/qt/src/timer.cpp PRIVATE platform/qt/src/timer_impl.hpp PRIVATE platform/qt/src/utf.cpp ) -include_directories( - PRIVATE platform/qt/include +set(MBGL_QT_FILESOURCE_FILES + # File source + PRIVATE platform/qt/src/http_file_source.cpp + PRIVATE platform/qt/src/http_file_source.hpp + PRIVATE platform/qt/src/http_request.cpp + PRIVATE platform/qt/src/http_request.hpp + + # Database + PRIVATE platform/qt/src/sqlite3.cpp ) # Shared library @@ -72,6 +68,17 @@ add_library(qmapboxgl SHARED platform/default/mbgl/util/default_styles.hpp ) +target_include_directories(qmapboxgl + PUBLIC platform/qt/include +) + +target_link_libraries(qmapboxgl + PRIVATE mbgl-core + PRIVATE mbgl-filesource + ${MBGL_QT_CORE_LIBRARIES} + ${MBGL_QT_FILESOURCE_LIBRARIES} +) + # C++ app add_executable(mbgl-qt platform/qt/app/main.cpp @@ -80,6 +87,20 @@ add_executable(mbgl-qt platform/qt/resources/common.qrc ) +target_compile_options(qmapboxgl + PRIVATE -std=c++03 +) + +target_link_libraries(mbgl-qt + PRIVATE qmapboxgl +) + +if(WITH_QT_4) + include(platform/qt/qt4.cmake) +else() + include(platform/qt/qt5.cmake) +endif() + xcode_create_scheme(TARGET mbgl-qt) if(WITH_QT_4) @@ -90,22 +111,22 @@ endif() # OS specific configurations if (MASON_PLATFORM STREQUAL "osx" OR MASON_PLATFORM STREQUAL "ios") - list(APPEND MBGL_QT_FILES + list(APPEND MBGL_QT_CORE_FILES PRIVATE platform/darwin/src/nsthread.mm ) - list(APPEND MBGL_QT_LIBRARIES + list(APPEND MBGL_QT_CORE_LIBRARIES PRIVATE "-framework Foundation" PRIVATE "-framework OpenGL" ) elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") - list(APPEND MBGL_QT_FILES + list(APPEND MBGL_QT_CORE_FILES PRIVATE platform/default/thread.cpp ) - list(APPEND MBGL_QT_LIBRARIES + list(APPEND MBGL_QT_CORE_LIBRARIES PRIVATE -lGL ) elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - list(APPEND MBGL_QT_FILES + list(APPEND MBGL_QT_CORE_FILES PRIVATE platform/qt/src/thread.cpp ) endif() diff --git a/platform/qt/qt4.cmake b/platform/qt/qt4.cmake index 66aed87c38..272009c541 100644 --- a/platform/qt/qt4.cmake +++ b/platform/qt/qt4.cmake @@ -1,31 +1,20 @@ find_package(Qt4 REQUIRED) -set(MBGL_QT_LIBRARIES - PRIVATE Qt4::QtCore - PRIVATE Qt4::QtGui - PRIVATE Qt4::QtNetwork - PRIVATE Qt4::QtOpenGL - PRIVATE Qt4::QtSql +set(MBGL_QT_CORE_LIBRARIES + PUBLIC Qt4::QtCore + PUBLIC Qt4::QtGui + PUBLIC Qt4::QtOpenGL ) -set(MBGL_QT_TEST_LIBRARIES - PRIVATE Qt4::QtCore - PRIVATE Qt4::QtOpenGL +set(MBGL_QT_FILESOURCE_LIBRARIES + PUBLIC Qt4::QtNetwork + PUBLIC Qt4::QtSql ) target_compile_options(qmapboxgl PRIVATE -Wno-inconsistent-missing-override ) -target_link_libraries(qmapboxgl - PRIVATE mbgl-core - PRIVATE Qt4::QtCore - PRIVATE Qt4::QtGui - PRIVATE Qt4::QtOpenGL -) - target_link_libraries(mbgl-qt - PRIVATE qmapboxgl - PRIVATE Qt4::QtGui PRIVATE Qt4::QtOpenGL ) diff --git a/platform/qt/qt5.cmake b/platform/qt/qt5.cmake index ed51051311..c4af774ba3 100644 --- a/platform/qt/qt5.cmake +++ b/platform/qt/qt5.cmake @@ -1,35 +1,21 @@ find_package(Qt5Core REQUIRED) find_package(Qt5Gui REQUIRED) -find_package(Qt5Location REQUIRED) find_package(Qt5Network REQUIRED) find_package(Qt5OpenGL REQUIRED) find_package(Qt5Widgets REQUIRED) find_package(Qt5Sql REQUIRED) -set(MBGL_QT_LIBRARIES - PRIVATE Qt5::Core - PRIVATE Qt5::Gui - PRIVATE Qt5::Network - PRIVATE Qt5::Sql +set(MBGL_QT_CORE_LIBRARIES + PUBLIC Qt5::Core + PUBLIC Qt5::Gui + PUBLIC Qt5::OpenGL ) -set(MBGL_QT_TEST_LIBRARIES - PRIVATE Qt5::Core - PRIVATE Qt5::Gui - PRIVATE Qt5::Widgets - PRIVATE Qt5::OpenGL -) - -target_link_libraries(qmapboxgl - PRIVATE mbgl-core - PRIVATE Qt5::Core - PRIVATE Qt5::Gui - PRIVATE Qt5::Location - PRIVATE Qt5::Sql +set(MBGL_QT_FILESOURCE_LIBRARIES + PUBLIC Qt5::Network + PUBLIC Qt5::Sql ) target_link_libraries(mbgl-qt - PRIVATE qmapboxgl - PRIVATE Qt5::OpenGL PRIVATE Qt5::Widgets ) diff --git a/platform/qt/test/headless_backend_qt.cpp b/platform/qt/src/headless_backend_qt.cpp index 5f95b2f96a..5f95b2f96a 100644 --- a/platform/qt/test/headless_backend_qt.cpp +++ b/platform/qt/src/headless_backend_qt.cpp diff --git a/platform/qt/test/qmapboxgl.cpp b/platform/qt/test/qmapboxgl.cpp deleted file mode 100644 index 747f8796fa..0000000000 --- a/platform/qt/test/qmapboxgl.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include <mbgl/test/util.hpp> -#include <mbgl/util/io.hpp> - -#include <QApplication> -#include <QMapbox> -#include <QMapboxGL> - -// We're using QGLFramebufferObject, which is only available in Qt 5 and up. -#if QT_VERSION >= 0x050000 - -#include <QGLWidget> -#include <QGLFramebufferObject> - -class QMapboxGLTest : public QObject, public ::testing::Test { - Q_OBJECT - -public: - QMapboxGLTest() : size(512, 512), fbo((assert(widget.context()->isValid()), widget.makeCurrent(), size)), map(nullptr, settings, size) { - connect(&map, SIGNAL(mapChanged(QMapboxGL::MapChange)), - this, SLOT(onMapChanged(QMapboxGL::MapChange))); - connect(&map, SIGNAL(needsRendering()), - this, SLOT(onNeedsRendering())); - map.resize(fbo.size(), fbo.size()); - map.setFramebufferObject(fbo.handle()); - map.setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 14); - } - - void runUntil(QMapboxGL::MapChange status) { - changeCallback = [&](QMapboxGL::MapChange change) { - if (change == status) { - qApp->exit(); - changeCallback = nullptr; - } - }; - - qApp->exec(); - } - -private: - QGLWidget widget; - const QSize size; - QGLFramebufferObject fbo; - -protected: - QMapboxGLSettings settings; - QMapboxGL map; - - std::function<void(QMapboxGL::MapChange)> changeCallback; - -private slots: - void onMapChanged(QMapboxGL::MapChange change) { - if (changeCallback) { - changeCallback(change); - } - }; - - void onNeedsRendering() { - widget.makeCurrent(); - fbo.bind(); - glViewport(0, 0, fbo.width(), fbo.height()); - map.render(); - }; -}; - -TEST_F(QMapboxGLTest, TEST_DISABLED_ON_CI(styleJson)) { - QString json = QString::fromStdString( - mbgl::util::read_file("test/fixtures/resources/style_vector.json")); - - map.setStyleJson(json); - ASSERT_EQ(map.styleJson(), json); - runUntil(QMapboxGL::MapChangeDidFinishLoadingMap); - - map.setStyleJson("invalid json"); - runUntil(QMapboxGL::MapChangeDidFailLoadingMap); - - map.setStyleJson("\"\""); - runUntil(QMapboxGL::MapChangeDidFailLoadingMap); - - map.setStyleJson(QString()); - runUntil(QMapboxGL::MapChangeDidFailLoadingMap); -} - -TEST_F(QMapboxGLTest, TEST_DISABLED_ON_CI(styleUrl)) { - QString url(QMapbox::defaultStyles()[0].first); - - map.setStyleUrl(url); - ASSERT_EQ(map.styleUrl(), url); - runUntil(QMapboxGL::MapChangeDidFinishLoadingMap); - - map.setStyleUrl("invalid://url"); - runUntil(QMapboxGL::MapChangeDidFailLoadingMap); - - map.setStyleUrl(QString()); - runUntil(QMapboxGL::MapChangeDidFailLoadingMap); -} - -#include "qmapboxgl.moc" - -#endif diff --git a/platform/qt/test/qmapboxgl.test.cpp b/platform/qt/test/qmapboxgl.test.cpp new file mode 100644 index 0000000000..c6ae3ed403 --- /dev/null +++ b/platform/qt/test/qmapboxgl.test.cpp @@ -0,0 +1,77 @@ +#include "qmapboxgl.test.hpp" + +#include <mbgl/util/io.hpp> + +#include <QMapbox> + +// We're using QGLFramebufferObject, which is only available in Qt 5 and up. +#if QT_VERSION >= 0x050000 + +QMapboxGLTest::QMapboxGLTest() : size(512, 512), fbo((assert(widget.context()->isValid()), widget.makeCurrent(), size)), map(nullptr, settings, size) { + connect(&map, SIGNAL(mapChanged(QMapboxGL::MapChange)), + this, SLOT(onMapChanged(QMapboxGL::MapChange))); + connect(&map, SIGNAL(needsRendering()), + this, SLOT(onNeedsRendering())); + map.resize(fbo.size(), fbo.size()); + map.setFramebufferObject(fbo.handle()); + map.setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 14); +} + +void QMapboxGLTest::runUntil(QMapboxGL::MapChange status) { + changeCallback = [&](QMapboxGL::MapChange change) { + if (change == status) { + qApp->exit(); + changeCallback = nullptr; + } + }; + + qApp->exec(); +} + +void QMapboxGLTest::onMapChanged(QMapboxGL::MapChange change) { + if (changeCallback) { + changeCallback(change); + } +} + +void QMapboxGLTest::onNeedsRendering() { + widget.makeCurrent(); + fbo.bind(); + glViewport(0, 0, fbo.width(), fbo.height()); + map.render(); +} + + +TEST_F(QMapboxGLTest, TEST_DISABLED_ON_CI(styleJson)) { + QString json = QString::fromStdString( + mbgl::util::read_file("test/fixtures/resources/style_vector.json")); + + map.setStyleJson(json); + ASSERT_EQ(map.styleJson(), json); + runUntil(QMapboxGL::MapChangeDidFinishLoadingMap); + + map.setStyleJson("invalid json"); + runUntil(QMapboxGL::MapChangeDidFailLoadingMap); + + map.setStyleJson("\"\""); + runUntil(QMapboxGL::MapChangeDidFailLoadingMap); + + map.setStyleJson(QString()); + runUntil(QMapboxGL::MapChangeDidFailLoadingMap); +} + +TEST_F(QMapboxGLTest, TEST_DISABLED_ON_CI(styleUrl)) { + QString url(QMapbox::defaultStyles()[0].first); + + map.setStyleUrl(url); + ASSERT_EQ(map.styleUrl(), url); + runUntil(QMapboxGL::MapChangeDidFinishLoadingMap); + + map.setStyleUrl("invalid://url"); + runUntil(QMapboxGL::MapChangeDidFailLoadingMap); + + map.setStyleUrl(QString()); + runUntil(QMapboxGL::MapChangeDidFailLoadingMap); +} + +#endif diff --git a/platform/qt/test/qmapboxgl.test.hpp b/platform/qt/test/qmapboxgl.test.hpp new file mode 100644 index 0000000000..04d63610ca --- /dev/null +++ b/platform/qt/test/qmapboxgl.test.hpp @@ -0,0 +1,36 @@ +#include <mbgl/test/util.hpp> + +#include <QApplication> +#include <QMapboxGL> + +// We're using QGLFramebufferObject, which is only available in Qt 5 and up. +#if QT_VERSION >= 0x050000 + +#include <QGLWidget> +#include <QGLFramebufferObject> + +class QMapboxGLTest : public QObject, public ::testing::Test { + Q_OBJECT + +public: + QMapboxGLTest(); + + void runUntil(QMapboxGL::MapChange); + +private: + QGLWidget widget; + const QSize size; + QGLFramebufferObject fbo; + +protected: + QMapboxGLSettings settings; + QMapboxGL map; + + std::function<void(QMapboxGL::MapChange)> changeCallback; + +private slots: + void onMapChanged(QMapboxGL::MapChange); + void onNeedsRendering(); +}; + +#endif |