CMakeLists.txt 8.6 KB

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