CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkMacroSetupQt.cmake
Go to the documentation of this file.
1 ###########################################################################
2 #
3 # Library: CTK
4 #
5 # Copyright (c) Kitware Inc.
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0.txt
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 ###########################################################################
20 
21 #! \ingroup CMakeUtilities
22 macro(ctkMacroSetupQt)
23  set(CTK_QT_VERSION "4" CACHE STRING "Expected Qt version")
24  mark_as_advanced(CTK_QT_VERSION)
25 
26  set_property(CACHE CTK_QT_VERSION PROPERTY STRINGS 4 5)
27 
28  if(NOT (CTK_QT_VERSION VERSION_EQUAL "4" OR CTK_QT_VERSION VERSION_EQUAL "5"))
29  message(FATAL_ERROR "Expected value for CTK_QT_VERSION is either '4' or '5'")
30  endif()
31 
32 
33  if(CTK_QT_VERSION VERSION_GREATER "4")
34  cmake_minimum_required(VERSION 2.8.12)
35  find_package(Qt5 COMPONENTS Core)
36  set(CTK_QT5_COMPONENTS Core Xml XmlPatterns Concurrent Sql Test)
37  if(CTK_ENABLE_Widgets OR CTK_LIB_Widgets OR CTK_LIB_CommandLineModules/Frontend/QtGui OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
38  list(APPEND CTK_QT5_COMPONENTS Widgets OpenGL UiTools)
39  endif()
40  if(CTK_LIB_CommandLineModules/Frontend/QtWebKit OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
41  if(TARGET Qt5::WebKitWidgets)
42  list(APPEND CTK_QT5_COMPONENTS WebKitWidgets)
43  else()
44  list(APPEND CTK_QT5_COMPONENTS WebEngineWidgets)
45  endif()
46  endif()
47  if(CTK_LIB_XNAT/Core OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
48  list(APPEND CTK_QT5_COMPONENTS Script)
49  endif()
50  find_package(Qt5 COMPONENTS ${CTK_QT5_COMPONENTS} REQUIRED)
51 
52  mark_as_superbuild(Qt5_DIR) # Qt 5
53 
54  # XXX Backward compatible way
55  if(DEFINED CMAKE_PREFIX_PATH)
56  mark_as_superbuild(CMAKE_PREFIX_PATH) # Qt 5
57  endif()
58 
59  else()
60  set(minimum_required_qt_version "4.6")
61 
62  find_package(Qt4)
63 
64  if(QT4_FOUND)
65 
66  if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_LESS "${minimum_required_qt_version}")
67  message(FATAL_ERROR "error: CTK requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}.")
68  endif()
69 
70  set(QT_USE_QTNETWORK ON)
71  set(QT_USE_QTSQL ON)
72  set(QT_USE_QTOPENGL ON)
73  set(QT_USE_QTXML ON)
74  set(QT_USE_QTXMLPATTERNS ON)
75  set(QT_USE_QTTEST ${BUILD_TESTING})
76  include(${QT_USE_FILE})
77 
78  # Set variable QT_INSTALLED_LIBRARY_DIR that will contains
79  # Qt shared library
80  set(QT_INSTALLED_LIBRARY_DIR ${QT_LIBRARY_DIR})
81  if(WIN32)
82  get_filename_component(QT_INSTALLED_LIBRARY_DIR ${QT_QMAKE_EXECUTABLE} PATH)
83  endif()
84 
85  mark_as_superbuild(QT_QMAKE_EXECUTABLE) # Qt 4
86  else()
87  message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
88  endif()
89  endif()
90 
91  mark_as_superbuild(CTK_QT_VERSION)
92 endmacro()