CMakeLists.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #=============================================================================
  2. # CMake - Cross Platform Makefile Generator
  3. # Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. #
  5. # Distributed under the OSI-approved BSD License (the "License");
  6. # see accompanying file Copyright.txt for details.
  7. #
  8. # This software is distributed WITHOUT ANY WARRANTY; without even the
  9. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. # See the License for more information.
  11. #=============================================================================
  12. project(QtDialog)
  13. if(POLICY CMP0020)
  14. cmake_policy(SET CMP0020 NEW) # Drop when CMake >= 2.8.11 required
  15. endif()
  16. find_package(Qt5Widgets QUIET)
  17. if (Qt5Widgets_FOUND)
  18. include_directories(${Qt5Widgets_INCLUDE_DIRS})
  19. add_definitions(${Qt5Widgets_DEFINITONS})
  20. macro(qt4_wrap_ui)
  21. qt5_wrap_ui(${ARGN})
  22. endmacro()
  23. macro(qt4_wrap_cpp)
  24. qt5_wrap_cpp(${ARGN})
  25. endmacro()
  26. macro(qt4_add_resources)
  27. qt5_add_resources(${ARGN})
  28. endmacro()
  29. set(CMake_QT_LIBRARIES ${Qt5Widgets_LIBRARIES})
  30. set(QT_QTMAIN_LIBRARY ${Qt5Core_QTMAIN_LIBRARIES})
  31. # Remove this when the minimum version of Qt is 4.6.
  32. add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
  33. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
  34. # We need to install Cocoa platform plugin and add qt.conf for Qt5 on Mac.
  35. # FIXME: This should be part of Qt5 CMake scripts, but unfortunatelly
  36. # Qt5 Mac support is missing there.
  37. if(APPLE)
  38. macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var)
  39. get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
  40. if(EXISTS "${_qt_plugin_path}")
  41. get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME)
  42. get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH)
  43. get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME)
  44. set(_qt_plugin_dest "${CMAKE_INSTALL_PREFIX}/PlugIns/${_qt_plugin_type}")
  45. install(FILES "${_qt_plugin_path}"
  46. DESTINATION "${_qt_plugin_dest}")
  47. set(${_qt_plugins_var}
  48. "${${_qt_plugins_var}};${_qt_plugin_dest}/${_qt_plugin_file}")
  49. else()
  50. message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found")
  51. endif()
  52. endmacro()
  53. install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS)
  54. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
  55. "[Paths]\nPlugins = PlugIns\n")
  56. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
  57. DESTINATION "${CMAKE_INSTALL_PREFIX}/Resources")
  58. endif()
  59. if(WIN32 AND TARGET Qt5::Core)
  60. get_property(_Qt5_Core_LOCATION TARGET Qt5::Core PROPERTY LOCATION)
  61. get_filename_component(Qt_BIN_DIR "${_Qt5_Core_LOCATION}" PATH)
  62. endif()
  63. else()
  64. set(QT_MIN_VERSION "4.4.0")
  65. find_package(Qt4 REQUIRED)
  66. if(NOT QT4_FOUND)
  67. message(SEND_ERROR "Failed to find Qt 4.4 or greater.")
  68. return()
  69. endif()
  70. include(${QT_USE_FILE})
  71. set(CMake_QT_LIBRARIES ${QT_LIBRARIES})
  72. if(WIN32 AND EXISTS "${QT_QMAKE_EXECUTABLE}")
  73. get_filename_component(_Qt_BIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH)
  74. if(EXISTS "${_Qt_BIN_DIR}/QtCore4.dll")
  75. set(Qt_BIN_DIR ${_Qt_BIN_DIR})
  76. endif()
  77. endif()
  78. endif()
  79. set(SRCS
  80. AddCacheEntry.cxx
  81. AddCacheEntry.h
  82. CMakeSetup.cxx
  83. CMakeSetupDialog.cxx
  84. CMakeSetupDialog.h
  85. FirstConfigure.cxx
  86. FirstConfigure.h
  87. QCMake.cxx
  88. QCMake.h
  89. QCMakeCacheView.cxx
  90. QCMakeCacheView.h
  91. QCMakeWidgets.cxx
  92. QCMakeWidgets.h
  93. QMacInstallDialog.cxx
  94. QMacInstallDialog.h
  95. )
  96. QT4_WRAP_UI(UI_SRCS
  97. CMakeSetupDialog.ui
  98. Compilers.ui
  99. CrossCompiler.ui
  100. AddCacheEntry.ui
  101. MacInstallDialog.ui
  102. )
  103. QT4_WRAP_CPP(MOC_SRCS
  104. AddCacheEntry.h
  105. Compilers.h
  106. CMakeSetupDialog.h
  107. FirstConfigure.h
  108. QCMake.h
  109. QCMakeCacheView.h
  110. QCMakeWidgets.h
  111. QMacInstallDialog.h
  112. )
  113. QT4_ADD_RESOURCES(RC_SRCS CMakeSetup.qrc)
  114. set(SRCS ${SRCS} ${UI_SRCS} ${MOC_SRCS} ${RC_SRCS})
  115. if(WIN32)
  116. set(SRCS ${SRCS} CMakeSetup.rc)
  117. endif()
  118. if(APPLE)
  119. set(SRCS ${SRCS} CMakeSetup.icns)
  120. set(MACOSX_BUNDLE_ICON_FILE CMakeSetup.icns)
  121. set_source_files_properties(CMakeSetup.icns PROPERTIES
  122. MACOSX_PACKAGE_LOCATION Resources)
  123. endif()
  124. if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
  125. install(FILES ${CMake_SOURCE_DIR}/Licenses/LGPLv2.1.txt
  126. DESTINATION ${CMAKE_DATA_DIR}/Licenses)
  127. set_property(SOURCE CMakeSetupDialog.cxx
  128. PROPERTY COMPILE_DEFINITIONS CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
  129. endif()
  130. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  131. add_executable(cmake-gui WIN32 MACOSX_BUNDLE ${SRCS})
  132. target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${CMake_QT_LIBRARIES})
  133. if(Qt_BIN_DIR)
  134. set_property(TARGET cmake-gui PROPERTY Qt_BIN_DIR ${Qt_BIN_DIR})
  135. endif()
  136. if(APPLE)
  137. file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
  138. LIMIT_COUNT 1 REGEX "^Copyright 2000-20[0-9][0-9] Kitware")
  139. set_target_properties(cmake-gui PROPERTIES
  140. OUTPUT_NAME CMake
  141. MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
  142. MACOSX_BUNDLE_SHORT_VERSION_STRING "${CMAKE_BUNDLE_VERSION}"
  143. # TBD: MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_BUNDLE_VERSION}"
  144. MACOSX_BUNDLE_COPYRIGHT "${copyright_line}"
  145. )
  146. # Create a symlink in the build tree to provide a "cmake-gui" next
  147. # to the "cmake" executable that refers to the application bundle.
  148. add_custom_command(TARGET cmake-gui POST_BUILD
  149. COMMAND ln -sf CMake.app/Contents/MacOS/CMake
  150. $<TARGET_FILE_DIR:cmake>/cmake-gui
  151. )
  152. endif()
  153. set(CMAKE_INSTALL_DESTINATION_ARGS
  154. BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}")
  155. install(TARGETS cmake-gui RUNTIME DESTINATION bin ${CMAKE_INSTALL_DESTINATION_ARGS})
  156. if(UNIX)
  157. # install a desktop file so CMake appears in the application start menu
  158. # with an icon
  159. install(FILES CMake.desktop DESTINATION share/applications )
  160. install(FILES CMakeSetup32.png DESTINATION share/pixmaps )
  161. install(FILES cmakecache.xml DESTINATION share/mime/packages )
  162. endif()
  163. if(APPLE)
  164. install(CODE "execute_process(COMMAND ln -s \"../MacOS/CMake\" cmake-gui
  165. WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)")
  166. endif()
  167. if(APPLE OR WIN32)
  168. # install rules for including 3rd party libs such as Qt
  169. # if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation
  170. set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/cmake-gui${CMAKE_EXECUTABLE_SUFFIX}")
  171. if(APPLE)
  172. set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/MacOS/CMake")
  173. endif()
  174. install(CODE "
  175. include(\"${CMake_SOURCE_DIR}/Modules/BundleUtilities.cmake\")
  176. set(BU_CHMOD_BUNDLE_ITEMS ON)
  177. fixup_bundle(\"${fixup_exe}\" \"${QT_PLUGINS}\" \"${QT_LIBRARY_DIR};${QT_BINARY_DIR}\")
  178. ")
  179. endif()
  180. set(CMAKE_PACKAGE_QTGUI TRUE)
  181. configure_file("${QtDialog_SOURCE_DIR}/QtDialogCPack.cmake.in"
  182. "${QtDialog_BINARY_DIR}/QtDialogCPack.cmake" @ONLY)