summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-07-18 14:44:41 +0300
committerKonstantin Käfer <mail@kkaefer.com>2016-08-05 11:42:22 +0200
commit821e58fdc1a21598e26dda542476ea530ac3c275 (patch)
tree9b969864e8f6eb598f133abd2bbb2fe1674f49e8
parent4e5fc0d7a4cbb85e9e43f5cac958ef132512c413 (diff)
downloadqtlocation-mapboxgl-821e58fdc1a21598e26dda542476ea530ac3c275.tar.gz
[build] Build Qt with CMake
-rw-r--r--Makefile44
-rw-r--r--cmake/mbgl.cmake8
-rw-r--r--platform/qt/config.cmake62
-rw-r--r--platform/qt/qt.cmake93
-rw-r--r--platform/qt/qt4.cmake21
-rw-r--r--platform/qt/qt5.cmake48
-rw-r--r--platform/qt/src/http_file_source.cpp4
7 files changed, 277 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index b447cfc4de..7322e60508 100644
--- a/Makefile
+++ b/Makefile
@@ -9,10 +9,12 @@ endif
ifeq ($(shell uname -s), Darwin)
HOST_PLATFORM = macos
HOST_PLATFORM_VERSION = $(shell uname -m)
+ NINJA ?= platform/macos/ninja
export JOBS ?= $(shell sysctl -n hw.ncpu)
else ifeq ($(shell uname -s), Linux)
HOST_PLATFORM = linux
HOST_PLATFORM_VERSION = $(shell uname -m)
+ NINJA ?= platform/linux/ninja
export JOBS ?= $(shell grep --count processor /proc/cpuinfo)
else
$(error Cannot determine host platform)
@@ -250,7 +252,6 @@ ifeq ($(HOST_PLATFORM), linux)
export PATH := $(shell pwd)/platform/linux:$(PATH)
export LINUX_OUTPUT_PATH = build/linux-$(shell uname -m)/$(BUILDTYPE)
LINUX_BUILD = $(LINUX_OUTPUT_PATH)/build.ninja
-NINJA = platform/linux/ninja
$(LINUX_BUILD): $(BUILD_DEPS)
mkdir -p $(LINUX_OUTPUT_PATH)
@@ -323,6 +324,47 @@ check: compdb clang-tools
endif
+#### Qt targets #####################################################
+
+export QT_OUTPUT_PATH = build/qt-$(BUILD_PLATFORM)-$(BUILD_PLATFORM_VERSION)/$(BUILDTYPE)
+QT_BUILD = $(QT_OUTPUT_PATH)/build.ninja
+
+$(QT_BUILD): $(BUILD_DEPS)
+ mkdir -p $(QT_OUTPUT_PATH)
+ (cd $(QT_OUTPUT_PATH) && cmake -G Ninja ../../.. \
+ -DCMAKE_BUILD_TYPE=$(BUILDTYPE) \
+ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
+ -DBUILD_PLATFORM=$(BUILD_PLATFORM) \
+ -DMBGL_PLATFORM=qt \
+ -DWITH_QT_DECODERS=${WITH_QT_DECODERS} \
+ -DWITH_QT_4=${WITH_QT_4})
+
+.PHONY: qt-app
+qt-app: $(QT_BUILD)
+ $(NINJA) -j$(JOBS) -C $(QT_OUTPUT_PATH) mbgl-qt
+
+.PHONY: run-qt-app
+run-qt-app: qt-app
+ $(QT_OUTPUT_PATH)/mbgl-qt
+
+.PHONY: qt-qml-app
+qt-qml-app: $(QT_BUILD)
+ $(NINJA) -j$(JOBS) -C $(QT_OUTPUT_PATH) mbgl-qt-qml
+
+.PHONY: run-qt-qml-app
+run-qt-qml-app: qt-qml-app
+ $(QT_OUTPUT_PATH)/mbgl-qt-qml
+
+.PHONY: qt-test
+qt-test: $(QT_BUILD)
+ $(NINJA) -j$(JOBS) -C $(QT_OUTPUT_PATH) mbgl-test
+
+run-qt-test-%: qt-test
+ $(QT_OUTPUT_PATH)/mbgl-test --gtest_catch_exceptions=0 --gtest_filter=$*
+
+.PHONY: run-qt-test
+run-qt-test: run-qt-test-*
+
#### Node targets ##############################################################
.PHONY: test-node
diff --git a/cmake/mbgl.cmake b/cmake/mbgl.cmake
index a796a9b372..317057a406 100644
--- a/cmake/mbgl.cmake
+++ b/cmake/mbgl.cmake
@@ -7,13 +7,17 @@ if (NOT DEFINED MBGL_PLATFORM)
endif()
if (NOT DEFINED ENV{MASON_PLATFORM})
- if(MBGL_PLATFORM STREQUAL "macos")
- set(ENV{MASON_PLATFORM} "osx")
+ if(MBGL_PLATFORM STREQUAL "qt")
+ set(ENV{MASON_PLATFORM} ${BUILD_PLATFORM})
else()
set(ENV{MASON_PLATFORM} ${MBGL_PLATFORM})
endif()
endif()
+if ("$ENV{MASON_PLATFORM}" STREQUAL "macos")
+ set(ENV{MASON_PLATFORM} "osx")
+endif()
+
set(MBGL_GENERATED ${CMAKE_BINARY_DIR}/generated/${CMAKE_CFG_INTDIR})
# Generate source groups so the files are properly sorted in IDEs like Xcode.
diff --git a/platform/qt/config.cmake b/platform/qt/config.cmake
new file mode 100644
index 0000000000..41abe30174
--- /dev/null
+++ b/platform/qt/config.cmake
@@ -0,0 +1,62 @@
+include(platform/qt/qt.cmake)
+
+mason_use(nunicode 1.6)
+mason_use(sqlite 3.9.1)
+
+if(NOT WITH_QT_DECODERS)
+ mason_use(libjpeg-turbo 1.4.2)
+ mason_use(libpng 1.6.20)
+ mason_use(webp 0.5.0)
+endif()
+
+macro(mbgl_platform_core)
+ target_sources(mbgl-core
+ ${MBGL_QT_FILES}
+ )
+
+ target_include_directories(mbgl-core
+ PRIVATE platform/default
+ PRIVATE platform/qt/include
+ )
+
+ target_add_mason_package(mbgl-core PRIVATE nunicode)
+ target_add_mason_package(mbgl-core PRIVATE sqlite)
+
+ target_link_libraries(mbgl-core
+ ${MBGL_QT_LIBRARIES}
+ )
+
+ if(NOT WITH_QT_DECODERS)
+ target_sources(mbgl-core
+ PRIVATE platform/default/jpeg_reader.cpp
+ PRIVATE platform/default/png_reader.cpp
+ PRIVATE platform/default/webp_reader.cpp
+ )
+
+ target_add_mason_package(mbgl-core PRIVATE libjpeg-turbo)
+ target_add_mason_package(mbgl-core PRIVATE libpng)
+ target_add_mason_package(mbgl-core PRIVATE webp)
+ else()
+ add_definitions(-DQT_IMAGE_DECODERS)
+ endif()
+endmacro()
+
+# TODO: Implement a Qt headless view, using offscreen
+# graphics system. Right now tests are Linux only.
+macro(mbgl_platform_test)
+ target_sources(mbgl-test
+ PRIVATE platform/default/headless_display.cpp
+ PRIVATE platform/default/headless_view.cpp
+ PRIVATE platform/default/headless_view_glx.cpp
+ PRIVATE test/src/main.cpp
+ )
+
+ set_source_files_properties(
+ test/src/main.cpp
+ PROPERTIES COMPILE_FLAGS -DWORK_DIRECTORY="${CMAKE_SOURCE_DIR}"
+ )
+
+ target_link_libraries(mbgl-test
+ PRIVATE -lX11
+ )
+endmacro()
diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake
new file mode 100644
index 0000000000..c2cebd7964
--- /dev/null
+++ b/platform/qt/qt.cmake
@@ -0,0 +1,93 @@
+# This file is to be reused by target platforms that don't
+# support `mason` (i.e. Yocto). Do not add any `mason` macro.
+
+option(WITH_QT_DECODERS "Use builtin Qt image decoders" OFF)
+option(WITH_QT_4 "Use Qt4 instead of Qt5" OFF)
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
+
+project(Qt4And5)
+
+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/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.cpp
+ PRIVATE platform/default/sqlite3.hpp
+
+ # Misc
+ PRIVATE platform/default/log_stderr.cpp
+ PRIVATE platform/default/string_stdlib.cpp
+
+ # 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/image.cpp
+ PRIVATE platform/qt/src/qmapbox.cpp
+ PRIVATE platform/qt/src/qmapboxgl.cpp
+ PRIVATE platform/qt/src/qmapboxgl_p.hpp
+ PRIVATE platform/qt/src/run_loop.cpp
+ PRIVATE platform/qt/src/run_loop_impl.hpp
+ PRIVATE platform/qt/src/timer.cpp
+ PRIVATE platform/qt/src/timer_impl.hpp
+
+ # Qt resources
+ PRIVATE platform/qt/qmapbox.qrc
+
+ # Public headers
+ PRIVATE platform/qt/include/qmapbox.hpp
+ PRIVATE platform/qt/include/qmapboxgl.hpp
+)
+
+include_directories(
+ PRIVATE platform/qt/include
+)
+
+# C++ app
+add_executable(mbgl-qt
+ platform/qt/app/main.cpp
+ platform/qt/app/mapwindow.cpp
+ platform/qt/app/mapwindow.hpp
+ platform/qt/app/source.qrc
+)
+
+if(WITH_QT_4)
+ include(platform/qt/qt4.cmake)
+else()
+ include(platform/qt/qt5.cmake)
+endif()
+
+# OS specific configurations
+if (BUILD_PLATFORM STREQUAL "macos")
+ list(APPEND MBGL_QT_FILES
+ PRIVATE platform/darwin/src/nsthread.mm
+ )
+ list(APPEND MBGL_QT_LIBRARIES
+ PRIVATE "-framework Foundation"
+ PRIVATE "-framework OpenGL"
+ )
+else()
+ list(APPEND MBGL_QT_FILES
+ PRIVATE platform/default/thread.cpp
+ )
+ list(APPEND MBGL_QT_LIBRARIES
+ PRIVATE -lGL
+ )
+endif()
diff --git a/platform/qt/qt4.cmake b/platform/qt/qt4.cmake
new file mode 100644
index 0000000000..25e6158bc2
--- /dev/null
+++ b/platform/qt/qt4.cmake
@@ -0,0 +1,21 @@
+find_package(Qt4 REQUIRED)
+
+set(MBGL_QT_LIBRARIES
+ PRIVATE Qt4::QtCore
+ PRIVATE Qt4::QtGui
+ PRIVATE Qt4::QtNetwork
+ PRIVATE Qt4::QtOpenGL
+)
+
+add_library(qmapboxgl SHARED)
+
+target_link_libraries(qmapboxgl
+ PUBLIC mbgl-core
+ PRIVATE Qt4::QtCore
+)
+
+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
new file mode 100644
index 0000000000..25f07a25fd
--- /dev/null
+++ b/platform/qt/qt5.cmake
@@ -0,0 +1,48 @@
+find_package(Qt5Core REQUIRED)
+find_package(Qt5Gui REQUIRED)
+find_package(Qt5Location REQUIRED)
+find_package(Qt5Network REQUIRED)
+find_package(Qt5OpenGL REQUIRED)
+find_package(Qt5Quick REQUIRED)
+find_package(Qt5Widgets REQUIRED)
+
+set(MBGL_QT_LIBRARIES
+ PRIVATE Qt5::Core
+ PRIVATE Qt5::Gui
+ PRIVATE Qt5::Network
+ PRIVATE Qt5::OpenGL
+)
+
+add_library(qmapboxgl SHARED
+ platform/qt/include/qquickmapboxgl.hpp
+ platform/qt/src/qquickmapboxgl.cpp
+ platform/qt/src/qquickmapboxglrenderer.cpp
+ platform/qt/src/qquickmapboxglrenderer.hpp
+)
+
+target_link_libraries(qmapboxgl
+ PRIVATE mbgl-core
+ PRIVATE Qt5::Core
+ PRIVATE Qt5::Gui
+ PRIVATE Qt5::Location
+ PRIVATE Qt5::OpenGL
+ PRIVATE Qt5::Quick
+)
+
+target_link_libraries(mbgl-qt
+ PRIVATE qmapboxgl
+ PRIVATE Qt5::OpenGL
+ PRIVATE Qt5::Widgets
+)
+
+# QtQuick app
+add_executable(mbgl-qt-qml
+ platform/qt/qmlapp/main.cpp
+ platform/qt/qmlapp/qml.qrc
+)
+
+target_link_libraries(mbgl-qt-qml
+ PRIVATE qmapboxgl
+ PRIVATE Qt5::Location
+ PRIVATE Qt5::Quick
+)
diff --git a/platform/qt/src/http_file_source.cpp b/platform/qt/src/http_file_source.cpp
index 87948609df..89a5171692 100644
--- a/platform/qt/src/http_file_source.cpp
+++ b/platform/qt/src/http_file_source.cpp
@@ -12,7 +12,11 @@
// Needs to be on the global namespace
// for linking purposes.
void initResources() {
+#if defined(__APPLE__)
+ Q_INIT_RESOURCE(platform_qt_qmapbox);
+#else
Q_INIT_RESOURCE(qmapbox);
+#endif
}
namespace mbgl {