CMakeLists.txt 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. project(QtDialog)
  4. if(POLICY CMP0020)
  5. cmake_policy(SET CMP0020 NEW) # Drop when CMake >= 2.8.11 required
  6. endif()
  7. CMake_OPTIONAL_COMPONENT(cmake-gui)
  8. find_package(Qt5Widgets QUIET)
  9. if (Qt5Widgets_FOUND)
  10. include_directories(${Qt5Widgets_INCLUDE_DIRS})
  11. add_definitions(${Qt5Widgets_DEFINITONS})
  12. macro(qt4_wrap_ui)
  13. qt5_wrap_ui(${ARGN})
  14. endmacro()
  15. macro(qt4_wrap_cpp)
  16. qt5_wrap_cpp(${ARGN})
  17. endmacro()
  18. macro(qt4_add_resources)
  19. qt5_add_resources(${ARGN})
  20. endmacro()
  21. set(CMake_QT_LIBRARIES ${Qt5Widgets_LIBRARIES})
  22. set(QT_QTMAIN_LIBRARY ${Qt5Core_QTMAIN_LIBRARIES})
  23. # Remove this when the minimum version of Qt is 4.6.
  24. add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
  25. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
  26. if(CMake_QT_STATIC_QXcbIntegrationPlugin_LIBRARIES)
  27. list(APPEND CMake_QT_LIBRARIES ${CMake_QT_STATIC_QXcbIntegrationPlugin_LIBRARIES})
  28. set_property(SOURCE CMakeSetup.cxx
  29. PROPERTY COMPILE_DEFINITIONS USE_QXcbIntegrationPlugin)
  30. endif()
  31. # We need to install platform plugin and add qt.conf for Qt5 on Mac and Windows.
  32. # FIXME: This should be part of Qt5 CMake scripts, but unfortunatelly
  33. # Qt5 support is missing there.
  34. if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
  35. macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var)
  36. get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
  37. if(EXISTS "${_qt_plugin_path}")
  38. get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME)
  39. get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH)
  40. get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME)
  41. if(APPLE)
  42. set(_qt_plugin_dir "PlugIns")
  43. elseif(WIN32)
  44. set(_qt_plugin_dir "plugins")
  45. endif()
  46. set(_qt_plugin_dest "${_qt_plugin_dir}/${_qt_plugin_type}")
  47. install(FILES "${_qt_plugin_path}"
  48. DESTINATION "${_qt_plugin_dest}"
  49. ${COMPONENT})
  50. set(${_qt_plugins_var}
  51. "${${_qt_plugins_var}};\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${_qt_plugin_dest}/${_qt_plugin_file}")
  52. else()
  53. message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found")
  54. endif()
  55. endmacro()
  56. if(APPLE)
  57. install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS)
  58. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
  59. "[Paths]\nPlugins = ${_qt_plugin_dir}\n")
  60. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
  61. DESTINATION "${CMAKE_INSTALL_PREFIX}/Resources"
  62. ${COMPONENT})
  63. elseif(WIN32)
  64. install_qt5_plugin("Qt5::QWindowsIntegrationPlugin" QT_PLUGINS)
  65. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
  66. "[Paths]\nPlugins = ../${_qt_plugin_dir}\n")
  67. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
  68. DESTINATION bin
  69. ${COMPONENT})
  70. endif()
  71. endif()
  72. if(TARGET Qt5::Core)
  73. get_property(_Qt5_Core_LOCATION TARGET Qt5::Core PROPERTY LOCATION)
  74. get_filename_component(Qt_BIN_DIR "${_Qt5_Core_LOCATION}" PATH)
  75. if(APPLE)
  76. get_filename_component(Qt_BIN_DIR "${Qt_BIN_DIR}" PATH)
  77. endif()
  78. endif()
  79. else()
  80. set(QT_MIN_VERSION "4.4.0")
  81. find_package(Qt4 REQUIRED)
  82. if(NOT QT4_FOUND)
  83. message(SEND_ERROR "Failed to find Qt 4.4 or greater.")
  84. return()
  85. endif()
  86. include(${QT_USE_FILE})
  87. set(CMake_QT_LIBRARIES ${QT_LIBRARIES})
  88. endif()
  89. set(SRCS
  90. AddCacheEntry.cxx
  91. AddCacheEntry.h
  92. CMakeSetup.cxx
  93. CMakeSetupDialog.cxx
  94. CMakeSetupDialog.h
  95. FirstConfigure.cxx
  96. FirstConfigure.h
  97. QCMake.cxx
  98. QCMake.h
  99. QCMakeCacheView.cxx
  100. QCMakeCacheView.h
  101. QCMakeWidgets.cxx
  102. QCMakeWidgets.h
  103. RegexExplorer.cxx
  104. RegexExplorer.h
  105. WarningMessagesDialog.cxx
  106. WarningMessagesDialog.h
  107. )
  108. QT4_WRAP_UI(UI_SRCS
  109. CMakeSetupDialog.ui
  110. Compilers.ui
  111. CrossCompiler.ui
  112. AddCacheEntry.ui
  113. RegexExplorer.ui
  114. WarningMessagesDialog.ui
  115. )
  116. QT4_WRAP_CPP(MOC_SRCS
  117. AddCacheEntry.h
  118. Compilers.h
  119. CMakeSetupDialog.h
  120. FirstConfigure.h
  121. QCMake.h
  122. QCMakeCacheView.h
  123. QCMakeWidgets.h
  124. RegexExplorer.h
  125. WarningMessagesDialog.h
  126. )
  127. QT4_ADD_RESOURCES(RC_SRCS CMakeSetup.qrc)
  128. set(SRCS ${SRCS} ${UI_SRCS} ${MOC_SRCS} ${RC_SRCS})
  129. if(WIN32)
  130. set(SRCS ${SRCS} CMakeSetup.rc)
  131. endif()
  132. if(APPLE)
  133. set(SRCS ${SRCS} CMakeSetup.icns)
  134. set(MACOSX_BUNDLE_ICON_FILE CMakeSetup.icns)
  135. set_source_files_properties(CMakeSetup.icns PROPERTIES
  136. MACOSX_PACKAGE_LOCATION Resources)
  137. endif()
  138. if(USE_LGPL)
  139. install(FILES ${CMake_SOURCE_DIR}/Licenses/LGPLv${USE_LGPL}.txt
  140. DESTINATION ${CMAKE_DATA_DIR}/Licenses
  141. ${COMPONENT})
  142. set_property(SOURCE CMakeSetupDialog.cxx
  143. PROPERTY COMPILE_DEFINITIONS USE_LGPL="${USE_LGPL}")
  144. endif()
  145. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  146. add_executable(cmake-gui WIN32 MACOSX_BUNDLE ${SRCS} ${MANIFEST_FILE})
  147. target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${CMake_QT_LIBRARIES})
  148. # cmake-gui has not been updated for `include-what-you-use`.
  149. # Block the tool until this is done.
  150. set_target_properties(cmake-gui PROPERTIES
  151. CXX_INCLUDE_WHAT_YOU_USE ""
  152. )
  153. # Files generated by MOC, RCC, and UIC may produce clang-tidy warnings.
  154. # We generate a dummy .clang-tidy file in the binary directory that disables
  155. # all clang-tidy checks except one that will never match. This one check is
  156. # necessary; clang-tidy reports an error when no checks are enabled.
  157. # Since the Qt code generators will generate source files in the binary tree,
  158. # clang-tidy will load the configuration from this dummy file when the sources
  159. # are built.
  160. file(WRITE "${QtDialog_BINARY_DIR}/.clang-tidy" "
  161. ---
  162. Checks: '-*,llvm-twine-local'
  163. ...
  164. ")
  165. if(APPLE)
  166. file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
  167. LIMIT_COUNT 1 REGEX "^Copyright 2000-20[0-9][0-9] Kitware")
  168. set_target_properties(cmake-gui PROPERTIES
  169. OUTPUT_NAME CMake
  170. MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
  171. MACOSX_BUNDLE_SHORT_VERSION_STRING "${CMAKE_BUNDLE_VERSION}"
  172. # TBD: MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_BUNDLE_VERSION}"
  173. MACOSX_BUNDLE_COPYRIGHT "${copyright_line}"
  174. MACOSX_BUNDLE_GUI_IDENTIFIER "org.cmake.cmake"
  175. )
  176. # Create a symlink in the build tree to provide a "cmake-gui" next
  177. # to the "cmake" executable that refers to the application bundle.
  178. add_custom_command(TARGET cmake-gui POST_BUILD
  179. COMMAND ln -sf CMake.app/Contents/MacOS/CMake
  180. $<TARGET_FILE_DIR:cmake>/cmake-gui
  181. )
  182. endif()
  183. set(CMAKE_INSTALL_DESTINATION_ARGS
  184. BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}" ${COMPONENT})
  185. install(TARGETS cmake-gui
  186. RUNTIME DESTINATION bin ${COMPONENT}
  187. ${CMAKE_INSTALL_DESTINATION_ARGS})
  188. if(UNIX AND NOT APPLE)
  189. foreach (size IN ITEMS 32 128)
  190. install(
  191. FILES "${CMAKE_CURRENT_SOURCE_DIR}/CMakeSetup${size}.png"
  192. DESTINATION "${CMAKE_XDGDATA_DIR}/icons/hicolor/${size}x${size}/apps"
  193. ${COMPONENT}
  194. RENAME "CMakeSetup.png")
  195. endforeach ()
  196. # install a desktop file so CMake appears in the application start menu
  197. # with an icon
  198. install(FILES cmake-gui.desktop
  199. DESTINATION "${CMAKE_XDGDATA_DIR}/applications"
  200. ${COMPONENT})
  201. install(FILES cmakecache.xml
  202. DESTINATION "${CMAKE_XDGDATA_DIR}/mime/packages"
  203. ${COMPONENT})
  204. endif()
  205. if(APPLE)
  206. install(CODE "
  207. execute_process(COMMAND ln -s \"../MacOS/CMake\" cmake-gui
  208. WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)
  209. " ${COMPONENT})
  210. endif()
  211. if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
  212. # install rules for including 3rd party libs such as Qt
  213. # if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation
  214. set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/cmake-gui${CMAKE_EXECUTABLE_SUFFIX}")
  215. if(APPLE)
  216. set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/MacOS/CMake")
  217. endif()
  218. install(CODE "
  219. include(\"${CMake_SOURCE_DIR}/Modules/BundleUtilities.cmake\")
  220. set(BU_CHMOD_BUNDLE_ITEMS ON)
  221. fixup_bundle(\"${fixup_exe}\" \"${QT_PLUGINS}\" \"${Qt_BIN_DIR};${QT_LIBRARY_DIR};${QT_BINARY_DIR}\")
  222. " ${COMPONENT})
  223. endif()
  224. set(CMAKE_PACKAGE_QTGUI TRUE)
  225. configure_file("${QtDialog_SOURCE_DIR}/QtDialogCPack.cmake.in"
  226. "${QtDialog_BINARY_DIR}/QtDialogCPack.cmake" @ONLY)