ctkMacroSetupQt.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #! \ingroup CMakeUtilities
  21. macro(ctkMacroSetupQt)
  22. set(CTK_QT_VERSION "4" CACHE STRING "Expected Qt version")
  23. mark_as_advanced(CTK_QT_VERSION)
  24. set_property(CACHE CTK_QT_VERSION PROPERTY STRINGS 4 5)
  25. if(NOT (CTK_QT_VERSION VERSION_EQUAL "4" OR CTK_QT_VERSION VERSION_EQUAL "5"))
  26. message(FATAL_ERROR "Expected value for CTK_QT_VERSION is either '4' or '5'")
  27. endif()
  28. if(CTK_QT_VERSION VERSION_GREATER "4")
  29. cmake_minimum_required(VERSION 2.8.12)
  30. set(QT5_INSTALL_PREFIX "" CACHE PATH "The install location of Qt5")
  31. set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QT5_INSTALL_PREFIX})
  32. set(CTK_QT5_COMPONENTS Core Xml XmlPatterns Concurrent Sql Test)
  33. if(CTK_LIB_Widgets OR CTK_LIB_CommandLineModules/Frontend/QtGui OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
  34. list(APPEND CTK_QT5_COMPONENTS Widgets OpenGL UiTools)
  35. endif()
  36. if(CTK_LIB_CommandLineModules/Frontend/QtWebKit OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
  37. list(APPEND CTK_QT5_COMPONENTS WebKitWidgets)
  38. endif()
  39. if(CTK_LIB_XNAT/Core OR CTK_BUILD_ALL OR CTK_BUILD_ALL_LIBRARIES)
  40. list(APPEND CTK_QT5_COMPONENTS Script)
  41. endif()
  42. find_package(Qt5 COMPONENTS ${CTK_QT5_COMPONENTS} REQUIRED)
  43. else()
  44. set(minimum_required_qt_version "4.6")
  45. find_package(Qt4)
  46. if(QT4_FOUND)
  47. if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_LESS "${minimum_required_qt_version}")
  48. message(FATAL_ERROR "error: CTK requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}.")
  49. endif()
  50. set(QT_USE_QTNETWORK ON)
  51. set(QT_USE_QTSQL ON)
  52. set(QT_USE_QTOPENGL ON)
  53. set(QT_USE_QTXML ON)
  54. set(QT_USE_QTXMLPATTERNS ON)
  55. set(QT_USE_QTTEST ${BUILD_TESTING})
  56. include(${QT_USE_FILE})
  57. # Set variable QT_INSTALLED_LIBRARY_DIR that will contains
  58. # Qt shared library
  59. set(QT_INSTALLED_LIBRARY_DIR ${QT_LIBRARY_DIR})
  60. if(WIN32)
  61. get_filename_component(QT_INSTALLED_LIBRARY_DIR ${QT_QMAKE_EXECUTABLE} PATH)
  62. endif()
  63. else()
  64. message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
  65. endif()
  66. else()
  67. message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
  68. endif()
  69. mark_as_superbuild(CTK_QT_VERSION)
  70. mark_as_superbuild(QT_QMAKE_EXECUTABLE) # Qt 4
  71. mark_as_superbuild(QT5_INSTALL_PREFIX) # Qt 5
  72. endmacro()