CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. set(the_description "High-level GUI")
  2. if(ANDROID)
  3. ocv_add_module(highgui opencv_imgproc opencv_imgcodecs OPTIONAL opencv_videoio WRAP python)
  4. else()
  5. ocv_add_module(highgui opencv_imgproc opencv_imgcodecs OPTIONAL opencv_videoio WRAP python java)
  6. endif()
  7. include(${CMAKE_CURRENT_LIST_DIR}/cmake/plugin.cmake)
  8. set(tgts "PRIVATE")
  9. set(highgui_hdrs
  10. ${CMAKE_CURRENT_LIST_DIR}/src/precomp.hpp
  11. )
  12. set(highgui_srcs
  13. ${CMAKE_CURRENT_LIST_DIR}/src/backend.cpp
  14. ${CMAKE_CURRENT_LIST_DIR}/src/window.cpp
  15. ${CMAKE_CURRENT_LIST_DIR}/src/roiSelector.cpp
  16. )
  17. # ----------------------------------------------------------------------------
  18. # CMake file for highgui. See root CMakeLists.txt
  19. # Some parts taken from version of Hartmut Seichter, HIT Lab NZ.
  20. # Jose Luis Blanco, 2008
  21. # ----------------------------------------------------------------------------
  22. if(DEFINED WINRT AND NOT DEFINED ENABLE_WINRT_MODE_NATIVE)
  23. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
  24. endif()
  25. if(APPLE)
  26. ocv_include_directories(${ZLIB_INCLUDE_DIRS})
  27. list(APPEND HIGHGUI_LIBRARIES ${ZLIB_LIBRARIES})
  28. endif()
  29. if(HAVE_WEBP)
  30. add_definitions(-DHAVE_WEBP)
  31. endif()
  32. file(GLOB highgui_ext_hdrs
  33. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/*.hpp"
  34. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp"
  35. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.h")
  36. # Removing WinRT API headers by default
  37. list(REMOVE_ITEM highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/highgui_winrt.hpp")
  38. set(OPENCV_HIGHGUI_BUILTIN_BACKEND "")
  39. if(HAVE_QT)
  40. set(OPENCV_HIGHGUI_BUILTIN_BACKEND "QT${QT_VERSION_MAJOR}")
  41. add_definitions(-DHAVE_QT)
  42. if(QT_VERSION_MAJOR GREATER 4)
  43. # "Automoc" doesn't work properly with opencv_world build, use QT<ver>_WRAP_CPP() directly
  44. #set(CMAKE_AUTOMOC ON)
  45. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  46. if(QT_VERSION_MAJOR EQUAL 6)
  47. add_definitions(-DHAVE_QT6) # QGLWidget deprecated for QT6, use this preprocessor to adjust window_QT.[h,cpp]
  48. QT6_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc)
  49. QT6_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h)
  50. elseif(QT_VERSION_MAJOR EQUAL 5)
  51. QT5_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc)
  52. QT5_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h)
  53. else()
  54. message(FATAL_ERROR "Unsupported QT version: ${QT_VERSION_MAJOR}")
  55. endif()
  56. list(APPEND highgui_srcs
  57. ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.cpp
  58. ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h
  59. ${_MOC_OUTFILES}
  60. ${_RCC_OUTFILES})
  61. set(qt_deps Core Gui Widgets Test Concurrent)
  62. if(HAVE_QT_OPENGL)
  63. add_definitions(-DHAVE_QT_OPENGL)
  64. # QOpenGLWidget requires Qt6 package component OpenGLWidgets
  65. if(QT_VERSION_MAJOR GREATER 5)
  66. list(APPEND qt_deps OpenGLWidgets)
  67. endif()
  68. list(APPEND qt_deps OpenGL)
  69. if(OPENGL_LIBRARIES)
  70. list(APPEND HIGHGUI_LIBRARIES "${OPENGL_LIBRARIES}")
  71. endif()
  72. endif()
  73. foreach(dt_dep ${qt_deps})
  74. add_definitions(${Qt${QT_VERSION_MAJOR}${dt_dep}_DEFINITIONS})
  75. include_directories(${Qt${QT_VERSION_MAJOR}${dt_dep}_INCLUDE_DIRS})
  76. list(APPEND HIGHGUI_LIBRARIES ${Qt${QT_VERSION_MAJOR}${dt_dep}_LIBRARIES})
  77. endforeach()
  78. else()
  79. ocv_assert(QT_VERSION_MAJOR EQUAL 4)
  80. if(HAVE_QT_OPENGL)
  81. set(QT_USE_QTOPENGL TRUE)
  82. if(OPENGL_LIBRARIES)
  83. list(APPEND HIGHGUI_LIBRARIES "${OPENGL_LIBRARIES}")
  84. endif()
  85. endif()
  86. include(${QT_USE_FILE})
  87. QT4_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc)
  88. QT4_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h)
  89. list(APPEND HIGHGUI_LIBRARIES ${QT_LIBRARIES})
  90. list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES})
  91. ocv_check_flag_support(CXX -Wno-missing-declarations _have_flag "")
  92. if(${_have_flag})
  93. set_source_files_properties(${_RCC_OUTFILES} PROPERTIES COMPILE_FLAGS -Wno-missing-declarations)
  94. endif()
  95. endif()
  96. elseif(WINRT)
  97. set(OPENCV_HIGHGUI_BUILTIN_BACKEND "WINRT")
  98. if(NOT WINRT_8_0)
  99. # Dependencies used by the implementation referenced
  100. # below are not available on WinRT 8.0.
  101. # Enabling it for WiRT 8.1+ only.
  102. # WinRT 8.1+ detected. Adding WinRT API header.
  103. message(STATUS " ${name}: WinRT detected. Adding WinRT API header")
  104. list(APPEND highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/highgui_winrt.hpp")
  105. list(APPEND highgui_srcs
  106. ${CMAKE_CURRENT_LIST_DIR}/src/window_winrt.cpp
  107. ${CMAKE_CURRENT_LIST_DIR}/src/window_winrt_bridge.cpp)
  108. list(APPEND highgui_hdrs
  109. ${CMAKE_CURRENT_LIST_DIR}/src/window_winrt_bridge.hpp)
  110. endif()
  111. # libraries below are neither available nor required
  112. # on ARM devices and/or Windows Phone
  113. if(WINRT_PHONE OR (OpenCV_ARCH STREQUAL "ARM"))
  114. list(REMOVE_ITEM HIGHGUI_LIBRARIES "comctl32" "gdi32" "ole32" "setupapi")
  115. if(WINRT_PHONE)
  116. message(STATUS " ${name}: Windows Phone detected")
  117. elseif(OpenCV_ARCH STREQUAL "ARM")
  118. message(STATUS " ${name}: ARM detected")
  119. if(WINRT_STORE)
  120. list(REMOVE_ITEM HIGHGUI_LIBRARIES "ws2_32")
  121. message(STATUS " ${name}: Removing 'ws2_32.lib'")
  122. endif()
  123. endif()
  124. message(STATUS " ${name}: Removing 'comctl32.lib, gdi32.lib, ole32.lib, setupapi.lib'")
  125. message(STATUS " ${name}: Leaving '${HIGHGUI_LIBRARIES}'")
  126. endif()
  127. elseif(HAVE_COCOA)
  128. set(OPENCV_HIGHGUI_BUILTIN_BACKEND "COCOA")
  129. add_definitions(-DHAVE_COCOA)
  130. list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_cocoa.mm)
  131. list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa")
  132. endif()
  133. if(TARGET ocv.3rdparty.win32ui)
  134. if("win32ui" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all")
  135. ocv_create_builtin_highgui_plugin(opencv_highgui_win32 ocv.3rdparty.win32ui "window_w32.cpp")
  136. elseif(NOT OPENCV_HIGHGUI_BUILTIN_BACKEND)
  137. set(OPENCV_HIGHGUI_BUILTIN_BACKEND "WIN32UI")
  138. list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_w32.cpp)
  139. list(APPEND tgts ocv.3rdparty.win32ui)
  140. if(HAVE_OPENGL AND OPENGL_LIBRARIES)
  141. list(APPEND tgts "${OPENGL_LIBRARIES}")
  142. endif()
  143. endif()
  144. endif()
  145. if(TARGET ocv.3rdparty.gtk3 OR TARGET ocv.3rdparty.gtk2)
  146. if(TARGET ocv.3rdparty.gtk3 AND NOT WITH_GTK_2_X)
  147. set(__gtk_dependency "ocv.3rdparty.gtk3")
  148. else()
  149. set(__gtk_dependency "ocv.3rdparty.gtk2")
  150. endif()
  151. if(
  152. NOT HIGHGUI_PLUGIN_LIST STREQUAL "all"
  153. AND NOT "gtk" IN_LIST HIGHGUI_PLUGIN_LIST
  154. AND NOT "gtk2" IN_LIST HIGHGUI_PLUGIN_LIST
  155. AND NOT "gtk3" IN_LIST HIGHGUI_PLUGIN_LIST
  156. AND NOT OPENCV_HIGHGUI_BUILTIN_BACKEND
  157. )
  158. if(__gtk_dependency STREQUAL "ocv.3rdparty.gtk3")
  159. set(OPENCV_HIGHGUI_BUILTIN_BACKEND "GTK3")
  160. elseif(__gtk_dependency STREQUAL "ocv.3rdparty.gtk2")
  161. set(OPENCV_HIGHGUI_BUILTIN_BACKEND "GTK2")
  162. else()
  163. set(OPENCV_HIGHGUI_BUILTIN_BACKEND "GTK")
  164. endif()
  165. list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_gtk.cpp)
  166. list(APPEND tgts ${__gtk_dependency})
  167. if(TARGET ocv.3rdparty.gthread)
  168. list(APPEND tgts ocv.3rdparty.gthread)
  169. endif()
  170. if(TARGET ocv.3rdparty.gtkglext
  171. AND __gtk_dependency STREQUAL "ocv.3rdparty.gtk2"
  172. AND NOT OPENCV_GTK_DISABLE_GTKGLEXT
  173. )
  174. list(APPEND tgts ocv.3rdparty.gtkglext)
  175. if(TARGET ocv.3rdparty.gtk_opengl
  176. AND __gtk_dependency STREQUAL "ocv.3rdparty.gtk2"
  177. AND NOT OPENCV_GTK_DISABLE_OPENGL
  178. )
  179. list(APPEND tgts ocv.3rdparty.gtk_opengl)
  180. endif()
  181. endif()
  182. elseif("gtk" IN_LIST HIGHGUI_PLUGIN_LIST)
  183. ocv_create_builtin_highgui_plugin(opencv_highgui_gtk ${__gtk_dependency} "window_gtk.cpp")
  184. if(TARGET ocv.3rdparty.gthread)
  185. ocv_target_link_libraries(opencv_highgui_gtk ocv.3rdparty.gthread)
  186. endif()
  187. if(TARGET ocv.3rdparty.gtkglext)
  188. ocv_target_link_libraries(opencv_highgui_gtk ocv.3rdparty.gtkglext)
  189. endif()
  190. else()
  191. if(TARGET ocv.3rdparty.gtk3 AND ("gtk3" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all"))
  192. ocv_create_builtin_highgui_plugin(opencv_highgui_gtk3 ocv.3rdparty.gtk3 "window_gtk.cpp")
  193. if(TARGET ocv.3rdparty.gthread)
  194. ocv_target_link_libraries(opencv_highgui_gtk3 ocv.3rdparty.gthread)
  195. endif()
  196. if(TARGET ocv.3rdparty.gtkglext)
  197. ocv_target_link_libraries(opencv_highgui_gtk3 ocv.3rdparty.gtkglext)
  198. endif()
  199. endif()
  200. if(TARGET ocv.3rdparty.gtk2 AND ("gtk2" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all"))
  201. ocv_create_builtin_highgui_plugin(opencv_highgui_gtk2 ocv.3rdparty.gtk2 "window_gtk.cpp")
  202. if(TARGET ocv.3rdparty.gthread)
  203. ocv_target_link_libraries(opencv_highgui_gtk2 ocv.3rdparty.gthread)
  204. endif()
  205. if(TARGET ocv.3rdparty.gtkglext)
  206. ocv_target_link_libraries(opencv_highgui_gtk2 ocv.3rdparty.gtkglext)
  207. endif()
  208. endif()
  209. endif()
  210. endif()
  211. if(NOT OPENCV_HIGHGUI_BUILTIN_BACKEND)
  212. set(OPENCV_HIGHGUI_BUILTIN_BACKEND "NONE")
  213. endif()
  214. message(STATUS "highgui: using builtin backend: ${OPENCV_HIGHGUI_BUILTIN_BACKEND}")
  215. set(OPENCV_HIGHGUI_BUILTIN_BACKEND "${OPENCV_HIGHGUI_BUILTIN_BACKEND}" PARENT_SCOPE) # informational
  216. if(TRUE)
  217. # these variables are set by 'ocv_append_build_options(HIGHGUI ...)'
  218. foreach(P ${HIGHGUI_INCLUDE_DIRS})
  219. ocv_include_directories(${P})
  220. endforeach()
  221. foreach(P ${HIGHGUI_LIBRARY_DIRS})
  222. link_directories(${P})
  223. endforeach()
  224. endif()
  225. if(tgts STREQUAL "PRIVATE")
  226. set(tgts "")
  227. endif()
  228. # install used dependencies only
  229. if(NOT BUILD_SHARED_LIBS
  230. AND NOT (CMAKE_VERSION VERSION_LESS "3.13.0") # upgrade CMake: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/2152
  231. )
  232. foreach(tgt in ${tgts})
  233. if(tgt MATCHES "^ocv\.3rdparty\.")
  234. install(TARGETS ${tgt} EXPORT OpenCVModules)
  235. endif()
  236. endforeach()
  237. endif()
  238. source_group("Src" FILES ${highgui_srcs} ${highgui_hdrs})
  239. source_group("Include" FILES ${highgui_ext_hdrs})
  240. ocv_set_module_sources(HEADERS ${highgui_ext_hdrs} SOURCES ${highgui_srcs} ${highgui_hdrs})
  241. ocv_module_include_directories()
  242. ocv_create_module(${HIGHGUI_LIBRARIES})
  243. macro(ocv_highgui_configure_target)
  244. if(APPLE)
  245. add_apple_compiler_options(${the_module})
  246. endif()
  247. if(MSVC AND NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT)
  248. set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
  249. endif()
  250. ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
  251. endmacro()
  252. if(NOT BUILD_opencv_world)
  253. ocv_highgui_configure_target()
  254. endif()
  255. ocv_add_accuracy_tests(${tgts})
  256. #ocv_add_perf_tests(${tgts})
  257. if(HIGHGUI_ENABLE_PLUGINS)
  258. ocv_target_compile_definitions(${the_module} PRIVATE ENABLE_PLUGINS)
  259. if(TARGET opencv_test_highgui)
  260. ocv_target_compile_definitions(opencv_test_highgui PRIVATE ENABLE_PLUGINS)
  261. endif()
  262. endif()
  263. ocv_target_link_libraries(${the_module} LINK_PRIVATE ${tgts})
  264. # generate module configuration
  265. set(CONFIG_STR "// Auto-generated file
  266. #define OPENCV_HIGHGUI_BUILTIN_BACKEND_STR \"${OPENCV_HIGHGUI_BUILTIN_BACKEND}\"
  267. ")
  268. if(OPENCV_HIGHGUI_BUILTIN_BACKEND STREQUAL "NONE")
  269. set(CONFIG_STR "${CONFIG_STR}
  270. #define OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND 1
  271. ")
  272. endif()
  273. ocv_update_file("${CMAKE_CURRENT_BINARY_DIR}/opencv_highgui_config.hpp" "${CONFIG_STR}")