ctkMacroSetupQt.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.9)
  30. set(QT5_INSTALL_PREFIX "" CACHE PATH "The install location of Qt5")
  31. if(NOT QT5_INSTALL_PREFIX OR NOT EXISTS ${QT5_INSTALL_PREFIX}/bin/qmake)
  32. message(FATAL_ERROR "You must specify the install location of Qt5")
  33. endif()
  34. set(CMAKE_PREFIX_PATH ${QT5_INSTALL_PREFIX})
  35. else()
  36. set(minimum_required_qt_version "4.6")
  37. find_package(Qt4)
  38. if(QT4_FOUND)
  39. if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_LESS "${minimum_required_qt_version}")
  40. message(FATAL_ERROR "error: CTK requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}.")
  41. endif()
  42. set(QT_USE_QTNETWORK ON)
  43. set(QT_USE_QTSQL ON)
  44. set(QT_USE_QTOPENGL ON)
  45. set(QT_USE_QTXML ON)
  46. set(QT_USE_QTXMLPATTERNS ON)
  47. set(QT_USE_QTTEST ${BUILD_TESTING})
  48. include(${QT_USE_FILE})
  49. # Set variable QT_INSTALLED_LIBRARY_DIR that will contains
  50. # Qt shared library
  51. set(QT_INSTALLED_LIBRARY_DIR ${QT_LIBRARY_DIR})
  52. if(WIN32)
  53. get_filename_component(QT_INSTALLED_LIBRARY_DIR ${QT_QMAKE_EXECUTABLE} PATH)
  54. endif()
  55. else()
  56. message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
  57. endif()
  58. mark_as_superbuild(QT_QMAKE_EXECUTABLE)
  59. else()
  60. message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
  61. endif()
  62. endmacro()