CMakeLists.txt 8.1 KB

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