Merge pull request #16122 from alalek:cmake_update_cpu_compiler_detection
[platform/upstream/opencv.git] / cmake / OpenCVFindLibsGUI.cmake
1 # ----------------------------------------------------------------------------
2 #  Detect 3rd-party GUI libraries
3 # ----------------------------------------------------------------------------
4
5 #--- Win32 UI ---
6 ocv_clear_vars(HAVE_WIN32UI)
7 if(WITH_WIN32UI)
8   try_compile(HAVE_WIN32UI
9     "${OpenCV_BINARY_DIR}"
10     "${OpenCV_SOURCE_DIR}/cmake/checks/win32uitest.cpp"
11     CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=user32;gdi32")
12 endif()
13
14 # --- QT4 ---
15 ocv_clear_vars(HAVE_QT HAVE_QT5)
16 if(WITH_QT)
17   if(NOT WITH_QT EQUAL 4)
18     find_package(Qt5 COMPONENTS Core Gui Widgets Test Concurrent REQUIRED NO_MODULE)
19     if(Qt5_FOUND)
20       set(HAVE_QT5 ON)
21       set(HAVE_QT  ON)
22       find_package(Qt5 COMPONENTS OpenGL QUIET)
23       if(Qt5OpenGL_FOUND)
24         set(QT_QTOPENGL_FOUND ON)
25       endif()
26     endif()
27   endif()
28
29   if(NOT HAVE_QT)
30     find_package(Qt4 REQUIRED QtCore QtGui QtTest)
31     if(QT4_FOUND)
32       set(HAVE_QT TRUE)
33     endif()
34   endif()
35 endif()
36
37 # --- GTK ---
38 ocv_clear_vars(HAVE_GTK HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT)
39 if(WITH_GTK AND NOT HAVE_QT)
40   if(NOT WITH_GTK_2_X)
41     ocv_check_modules(GTK3 gtk+-3.0)
42     if(HAVE_GTK3)
43       ocv_append_build_options(HIGHGUI GTK3)
44       set(HAVE_GTK TRUE)
45     endif()
46   endif()
47   if(NOT HAVE_GTK)
48     ocv_check_modules(GTK2 gtk+-2.0)
49     if(HAVE_GTK2)
50       if (GTK2_VERSION VERSION_LESS MIN_VER_GTK)
51         message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${GTK2_VERSION} found)")
52       else()
53         ocv_append_build_options(HIGHGUI GTK2)
54         set(HAVE_GTK TRUE)
55       endif()
56     endif()
57   endif()
58   ocv_check_modules(GTHREAD gthread-2.0)
59   if(HAVE_GTK AND NOT HAVE_GTHREAD)
60     message(FATAL_ERROR "gthread not found. This library is required when building with GTK support")
61   else()
62     ocv_append_build_options(HIGHGUI GTHREAD)
63   endif()
64   if(WITH_OPENGL AND NOT HAVE_GTK3)
65     ocv_check_modules(GTKGLEXT gtkglext-1.0)
66     if(HAVE_GTKGLEXT)
67       ocv_append_build_options(HIGHGUI GTKGLEXT)
68     endif()
69   endif()
70 endif()
71
72 # --- OpenGl ---
73 ocv_clear_vars(HAVE_OPENGL HAVE_QT_OPENGL)
74 if(WITH_OPENGL)
75   if(WITH_WIN32UI OR (HAVE_QT AND QT_QTOPENGL_FOUND) OR HAVE_GTKGLEXT)
76     find_package (OpenGL QUIET)
77     if(OPENGL_FOUND)
78       set(HAVE_OPENGL TRUE)
79       list(APPEND OPENCV_LINKER_LIBS ${OPENGL_LIBRARIES})
80       if(QT_QTOPENGL_FOUND)
81         set(HAVE_QT_OPENGL TRUE)
82       else()
83         ocv_include_directories(${OPENGL_INCLUDE_DIR})
84       endif()
85     endif()
86   endif()
87 endif(WITH_OPENGL)
88
89 # --- Carbon & Cocoa ---
90 if(APPLE)
91   if(WITH_CARBON)
92     set(HAVE_CARBON YES)
93   elseif(NOT IOS AND CV_CLANG)
94     set(HAVE_COCOA YES)
95   endif()
96 endif()