Skip to content

Commit

Permalink
Added the Qt backend with static link support
Browse files Browse the repository at this point in the history
When static linking, Qt resources must the initialized manually

The file static_opencv_qt_resources.cpp initializes the resources
for the highgui icons. This patch uses the QtCMakeExtra Hunter
project to add it as an interface source file.
  • Loading branch information
pretyman committed Mar 23, 2016
1 parent e0d5b08 commit e91796b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/OpenCVFindLibsGUI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ endif()
ocv_clear_vars(HAVE_QT HAVE_QT5)
if(WITH_QT)
if(NOT WITH_QT EQUAL 4)
hunter_add_package(Qt)
find_package(Qt5Core)
find_package(Qt5Gui)
find_package(Qt5Widgets)
Expand Down
33 changes: 33 additions & 0 deletions cmake/templates/OpenCVConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,36 @@ endif()
if("@JPEG_FOUND@")
find_dependency(JPEG CONFIG)
endif()

# AWP: Qt5 dependencies -- start
if("@Qt5Core_FOUND@")
find_dependency(Qt5Core)
endif()

if("@Qt5Gui_FOUND@")
find_dependency(Qt5Gui)
endif()

if("@Qt5Widgets_FOUND@")
find_dependency(Qt5Widgets)
if(NOT "@BUILD_SHARED_LIBS@")
# function from Hunter's QtCMakeExtra project
_qt_cmake_extra_helpers_add_source(
opencv_highgui "static_opencv_qt_resources.cpp"
)
endif()
endif()

if("@Qt5Test_FOUND@")
find_dependency(Qt5Test)
endif()

if("@Qt5Concurrent_FOUND@")
find_dependency(Qt5Concurrent)
endif()

if("@Qt5OpenGL_FOUND@")
find_dependency(Qt5OpenGL)
endif()
# AWP: Qt5 dependencies -- end

11 changes: 11 additions & 0 deletions modules/highgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ if(HAVE_QT5)
${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h
${_RCC_OUTFILES})

# Hunter patch to load qt resources when static linking
# Hunter has only Qt5, so its guarded by if(HAVE_QT5)
if(NOT BUILD_SHARED_LIBS)
install(
FILES
${CMAKE_CURRENT_LIST_DIR}/static_opencv_qt_resources.cpp
DESTINATION
"src/qt/plugins"
)
endif()

foreach(dt5_dep Core Gui Widgets Test Concurrent)
add_definitions(${Qt5${dt5_dep}_DEFINITIONS})
include_directories(${Qt5${dt5_dep}_INCLUDE_DIRS})
Expand Down
22 changes: 22 additions & 0 deletions modules/highgui/static_opencv_qt_resources.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Part of the Hunter patch for static linking OpenCV with Qt
* Initializes the resources for the highgui window icons
*/

#include <QtCore>

inline void static_opencv_qt_resources() {
Q_INIT_RESOURCE(window_QT);
}

namespace {

struct static_opencv_qt_resources_initializer{
static_opencv_qt_resources_initializer() {
static_opencv_qt_resources();
}
};

static_opencv_qt_resources_initializer global_instance;
}

0 comments on commit e91796b

Please sign in to comment.