CMakeLists.txt 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. CMakeSetupDialog.cxx
  76. CMakeSetupDialog.h
  77. Compilers.h
  78. EnvironmentDialog.cxx
  79. EnvironmentDialog.h
  80. FirstConfigure.cxx
  81. FirstConfigure.h
  82. QCMake.cxx
  83. QCMake.h
  84. QCMakeCacheView.cxx
  85. QCMakeCacheView.h
  86. QCMakePreset.cxx
  87. QCMakePreset.h
  88. QCMakePresetComboBox.cxx
  89. QCMakePresetComboBox.h
  90. QCMakePresetItemModel.cxx
  91. QCMakePresetItemModel.h
  92. QCMakeWidgets.cxx
  93. QCMakeWidgets.h
  94. RegexExplorer.cxx
  95. RegexExplorer.h
  96. WarningMessagesDialog.cxx
  97. WarningMessagesDialog.h
  98. )
  99. qt5_wrap_ui(UI_SRCS
  100. CMakeSetupDialog.ui
  101. Compilers.ui
  102. CrossCompiler.ui
  103. AddCacheEntry.ui
  104. EnvironmentDialog.ui
  105. RegexExplorer.ui
  106. WarningMessagesDialog.ui
  107. )
  108. qt5_wrap_cpp(MOC_SRCS
  109. AddCacheEntry.h
  110. Compilers.h
  111. CMakeSetupDialog.h
  112. EnvironmentDialog.h
  113. FirstConfigure.h
  114. QCMake.h
  115. QCMakeCacheView.h
  116. QCMakePresetComboBox.h
  117. QCMakePresetItemModel.h
  118. QCMakeWidgets.h
  119. RegexExplorer.h
  120. WarningMessagesDialog.h
  121. )
  122. qt5_add_resources(RC_SRCS CMakeSetup.qrc)
  123. if (FALSE) # CMake's bootstrap binary does not support automoc
  124. set(CMAKE_AUTOMOC 1)
  125. set(CMAKE_AUTORCC 1)
  126. set(CMAKE_AUTOUIC 1)
  127. else ()
  128. list(APPEND SRCS
  129. ${UI_SRCS}
  130. ${MOC_SRCS}
  131. ${RC_SRCS})
  132. endif ()
  133. if(USE_LGPL)
  134. install(FILES ${CMake_SOURCE_DIR}/Licenses/LGPLv${USE_LGPL}.txt
  135. DESTINATION ${CMAKE_DATA_DIR}/Licenses
  136. ${COMPONENT})
  137. set_property(SOURCE CMakeSetupDialog.cxx
  138. PROPERTY COMPILE_DEFINITIONS USE_LGPL="${USE_LGPL}")
  139. endif()
  140. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  141. add_library(CMakeGUILib STATIC ${SRCS})
  142. # CMake_QT_EXTRA_LIBRARIES have to come before the main libraries on the link line
  143. target_link_libraries(CMakeGUILib PUBLIC CMakeLib ${CMake_QT_EXTRA_LIBRARIES} Qt5::Core Qt5::Widgets)
  144. add_library(CMakeGUIMainLib STATIC CMakeSetup.cxx)
  145. target_link_libraries(CMakeGUIMainLib PUBLIC CMakeGUILib)
  146. add_executable(cmake-gui WIN32 MACOSX_BUNDLE CMakeGUIExec.cxx ${MANIFEST_FILE})
  147. target_link_libraries(cmake-gui CMakeGUIMainLib Qt5::Core)
  148. if(WIN32)
  149. target_sources(CMakeGUIMainLib INTERFACE $<TARGET_OBJECTS:CMakeVersion> CMakeSetup.rc)
  150. endif()
  151. if(APPLE)
  152. target_sources(CMakeGUIMainLib INTERFACE CMakeSetup.icns)
  153. set(MACOSX_BUNDLE_ICON_FILE CMakeSetup.icns)
  154. set_source_files_properties(CMakeSetup.icns PROPERTIES
  155. MACOSX_PACKAGE_LOCATION Resources)
  156. endif()
  157. if(CMake_JOB_POOL_LINK_BIN)
  158. set_property(TARGET cmake-gui PROPERTY JOB_POOL_LINK "link-bin")
  159. endif()
  160. # cmake-gui has not been updated for `include-what-you-use`.
  161. # Block the tool until this is done.
  162. set_target_properties(CMakeGUILib CMakeGUIMainLib cmake-gui PROPERTIES
  163. CXX_INCLUDE_WHAT_YOU_USE ""
  164. )
  165. # Files generated by MOC, RCC, and UIC may produce clang-tidy warnings.
  166. # We generate a dummy .clang-tidy file in the binary directory that disables
  167. # all clang-tidy checks except one that will never match. This one check is
  168. # necessary; clang-tidy reports an error when no checks are enabled.
  169. # Since the Qt code generators will generate source files in the binary tree,
  170. # clang-tidy will load the configuration from this dummy file when the sources
  171. # are built.
  172. file(WRITE "${QtDialog_BINARY_DIR}/.clang-tidy" "
  173. ---
  174. Checks: '-*,llvm-twine-local'
  175. ...
  176. ")
  177. if(APPLE)
  178. file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
  179. LIMIT_COUNT 1 REGEX "^Copyright 2000-20[0-9][0-9] Kitware")
  180. set_target_properties(cmake-gui PROPERTIES
  181. OUTPUT_NAME CMake
  182. MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
  183. MACOSX_BUNDLE_SHORT_VERSION_STRING "${CMAKE_BUNDLE_VERSION}"
  184. # TBD: MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_BUNDLE_VERSION}"
  185. MACOSX_BUNDLE_COPYRIGHT "${copyright_line}"
  186. MACOSX_BUNDLE_GUI_IDENTIFIER "org.cmake.cmake"
  187. )
  188. # Create a symlink in the build tree to provide a "cmake-gui" next
  189. # to the "cmake" executable that refers to the application bundle.
  190. add_custom_command(TARGET cmake-gui POST_BUILD
  191. COMMAND ln -sf CMake.app/Contents/MacOS/CMake
  192. $<TARGET_FILE_DIR:cmake>/cmake-gui
  193. )
  194. endif()
  195. set(CMAKE_INSTALL_DESTINATION_ARGS
  196. BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}" ${COMPONENT})
  197. install(TARGETS cmake-gui
  198. RUNTIME DESTINATION bin ${COMPONENT}
  199. ${CMAKE_INSTALL_DESTINATION_ARGS})
  200. if(UNIX AND NOT APPLE)
  201. foreach (size IN ITEMS 32 128)
  202. install(
  203. FILES "${CMAKE_CURRENT_SOURCE_DIR}/CMakeSetup${size}.png"
  204. DESTINATION "${CMAKE_XDGDATA_DIR}/icons/hicolor/${size}x${size}/apps"
  205. ${COMPONENT}
  206. RENAME "CMakeSetup.png")
  207. endforeach ()
  208. # install a desktop file so CMake appears in the application start menu
  209. # with an icon
  210. install(FILES cmake-gui.desktop
  211. DESTINATION "${CMAKE_XDGDATA_DIR}/applications"
  212. ${COMPONENT})
  213. install(FILES cmakecache.xml
  214. DESTINATION "${CMAKE_XDGDATA_DIR}/mime/packages"
  215. ${COMPONENT})
  216. endif()
  217. if(APPLE)
  218. install(CODE "
  219. execute_process(COMMAND ln -s \"../MacOS/CMake\" cmake-gui
  220. WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)
  221. " ${COMPONENT})
  222. endif()
  223. if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
  224. # install rules for including 3rd party libs such as Qt
  225. # if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation
  226. set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/cmake-gui${CMAKE_EXECUTABLE_SUFFIX}")
  227. if(APPLE)
  228. set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/MacOS/CMake")
  229. endif()
  230. install(CODE "
  231. include(\"${CMake_SOURCE_DIR}/Modules/BundleUtilities.cmake\")
  232. set(BU_CHMOD_BUNDLE_ITEMS ON)
  233. fixup_bundle(\"${fixup_exe}\" \"${QT_PLUGINS}\" \"${Qt_BIN_DIR};${QT_LIBRARY_DIR};${QT_BINARY_DIR}\")
  234. " ${COMPONENT})
  235. endif()
  236. set(CMAKE_PACKAGE_QTGUI TRUE)
  237. configure_file("${QtDialog_SOURCE_DIR}/QtDialogCPack.cmake.in"
  238. "${QtDialog_BINARY_DIR}/QtDialogCPack.cmake" @ONLY)