CMakeLists.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. CMake_OPTIONAL_COMPONENT(cmake-gui)
  17. find_package(Qt5Widgets QUIET)
  18. if (Qt5Widgets_FOUND)
  19. include_directories(${Qt5Widgets_INCLUDE_DIRS})
  20. add_definitions(${Qt5Widgets_DEFINITONS})
  21. macro(qt4_wrap_ui)
  22. qt5_wrap_ui(${ARGN})
  23. endmacro()
  24. macro(qt4_wrap_cpp)
  25. qt5_wrap_cpp(${ARGN})
  26. endmacro()
  27. macro(qt4_add_resources)
  28. qt5_add_resources(${ARGN})
  29. endmacro()
  30. set(CMake_QT_LIBRARIES ${Qt5Widgets_LIBRARIES})
  31. set(QT_QTMAIN_LIBRARY ${Qt5Core_QTMAIN_LIBRARIES})
  32. # Remove this when the minimum version of Qt is 4.6.
  33. add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
  34. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
  35. # We need to install platform plugin and add qt.conf for Qt5 on Mac and Windows.
  36. # FIXME: This should be part of Qt5 CMake scripts, but unfortunatelly
  37. # Qt5 support is missing there.
  38. if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
  39. macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var)
  40. get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
  41. if(EXISTS "${_qt_plugin_path}")
  42. get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME)
  43. get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH)
  44. get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME)
  45. if(APPLE)
  46. set(_qt_plugin_dir "PlugIns")
  47. elseif(WIN32)
  48. set(_qt_plugin_dir "plugins")
  49. endif()
  50. set(_qt_plugin_dest "${_qt_plugin_dir}/${_qt_plugin_type}")
  51. install(FILES "${_qt_plugin_path}"
  52. DESTINATION "${_qt_plugin_dest}"
  53. ${COMPONENT})
  54. set(${_qt_plugins_var}
  55. "${${_qt_plugins_var}};\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${_qt_plugin_dest}/${_qt_plugin_file}")
  56. else()
  57. message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found")
  58. endif()
  59. endmacro()
  60. if(APPLE)
  61. install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS)
  62. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
  63. "[Paths]\nPlugins = ${_qt_plugin_dir}\n")
  64. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
  65. DESTINATION "${CMAKE_INSTALL_PREFIX}/Resources"
  66. ${COMPONENT})
  67. elseif(WIN32)
  68. install_qt5_plugin("Qt5::QWindowsIntegrationPlugin" QT_PLUGINS)
  69. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
  70. "[Paths]\nPlugins = ../${_qt_plugin_dir}\n")
  71. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
  72. DESTINATION bin
  73. ${COMPONENT})
  74. endif()
  75. endif()
  76. if(TARGET Qt5::Core)
  77. get_property(_Qt5_Core_LOCATION TARGET Qt5::Core PROPERTY LOCATION)
  78. get_filename_component(Qt_BIN_DIR "${_Qt5_Core_LOCATION}" PATH)
  79. if(APPLE)
  80. get_filename_component(Qt_BIN_DIR "${Qt_BIN_DIR}" PATH)
  81. endif()
  82. endif()
  83. else()
  84. set(QT_MIN_VERSION "4.4.0")
  85. find_package(Qt4 REQUIRED)
  86. if(NOT QT4_FOUND)
  87. message(SEND_ERROR "Failed to find Qt 4.4 or greater.")
  88. return()
  89. endif()
  90. include(${QT_USE_FILE})
  91. set(CMake_QT_LIBRARIES ${QT_LIBRARIES})
  92. endif()
  93. set(SRCS
  94. AddCacheEntry.cxx
  95. AddCacheEntry.h
  96. CMakeSetup.cxx
  97. CMakeSetupDialog.cxx
  98. CMakeSetupDialog.h
  99. FirstConfigure.cxx
  100. FirstConfigure.h
  101. QCMake.cxx
  102. QCMake.h
  103. QCMakeCacheView.cxx
  104. QCMakeCacheView.h
  105. QCMakeWidgets.cxx
  106. QCMakeWidgets.h
  107. RegexExplorer.cxx
  108. RegexExplorer.h
  109. )
  110. QT4_WRAP_UI(UI_SRCS
  111. CMakeSetupDialog.ui
  112. Compilers.ui
  113. CrossCompiler.ui
  114. AddCacheEntry.ui
  115. RegexExplorer.ui
  116. )
  117. QT4_WRAP_CPP(MOC_SRCS
  118. AddCacheEntry.h
  119. Compilers.h
  120. CMakeSetupDialog.h
  121. FirstConfigure.h
  122. QCMake.h
  123. QCMakeCacheView.h
  124. QCMakeWidgets.h
  125. RegexExplorer.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(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
  139. install(FILES ${CMake_SOURCE_DIR}/Licenses/LGPLv2.1.txt
  140. DESTINATION ${CMAKE_DATA_DIR}/Licenses
  141. ${COMPONENT})
  142. set_property(SOURCE CMakeSetupDialog.cxx
  143. PROPERTY COMPILE_DEFINITIONS CMake_GUI_DISTRIBUTE_WITH_Qt_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. if(APPLE)
  149. file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
  150. LIMIT_COUNT 1 REGEX "^Copyright 2000-20[0-9][0-9] Kitware")
  151. set_target_properties(cmake-gui PROPERTIES
  152. OUTPUT_NAME CMake
  153. MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
  154. MACOSX_BUNDLE_SHORT_VERSION_STRING "${CMAKE_BUNDLE_VERSION}"
  155. # TBD: MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_BUNDLE_VERSION}"
  156. MACOSX_BUNDLE_COPYRIGHT "${copyright_line}"
  157. )
  158. # Create a symlink in the build tree to provide a "cmake-gui" next
  159. # to the "cmake" executable that refers to the application bundle.
  160. add_custom_command(TARGET cmake-gui POST_BUILD
  161. COMMAND ln -sf CMake.app/Contents/MacOS/CMake
  162. $<TARGET_FILE_DIR:cmake>/cmake-gui
  163. )
  164. endif()
  165. set(CMAKE_INSTALL_DESTINATION_ARGS
  166. BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}" ${COMPONENT})
  167. install(TARGETS cmake-gui
  168. RUNTIME DESTINATION bin ${COMPONENT}
  169. ${CMAKE_INSTALL_DESTINATION_ARGS})
  170. if(UNIX AND NOT APPLE)
  171. foreach (size IN ITEMS 32 128)
  172. install(
  173. FILES "${CMAKE_CURRENT_SOURCE_DIR}/CMakeSetup${size}.png"
  174. DESTINATION "share/icons/hicolor/${size}x${size}/apps"
  175. ${COMPONENT}
  176. RENAME "CMakeSetup.png")
  177. endforeach ()
  178. # install a desktop file so CMake appears in the application start menu
  179. # with an icon
  180. install(FILES CMake.desktop
  181. DESTINATION share/applications
  182. ${COMPONENT})
  183. install(FILES cmakecache.xml
  184. DESTINATION share/mime/packages
  185. ${COMPONENT})
  186. endif()
  187. if(APPLE)
  188. install(CODE "
  189. execute_process(COMMAND ln -s \"../MacOS/CMake\" cmake-gui
  190. WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)
  191. " ${COMPONENT})
  192. endif()
  193. if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
  194. # install rules for including 3rd party libs such as Qt
  195. # if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation
  196. set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/cmake-gui${CMAKE_EXECUTABLE_SUFFIX}")
  197. if(APPLE)
  198. set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/MacOS/CMake")
  199. endif()
  200. install(CODE "
  201. include(\"${CMake_SOURCE_DIR}/Modules/BundleUtilities.cmake\")
  202. set(BU_CHMOD_BUNDLE_ITEMS ON)
  203. fixup_bundle(\"${fixup_exe}\" \"${QT_PLUGINS}\" \"${Qt_BIN_DIR};${QT_LIBRARY_DIR};${QT_BINARY_DIR}\")
  204. " ${COMPONENT})
  205. endif()
  206. set(CMAKE_PACKAGE_QTGUI TRUE)
  207. configure_file("${QtDialog_SOURCE_DIR}/QtDialogCPack.cmake.in"
  208. "${QtDialog_BINARY_DIR}/QtDialogCPack.cmake" @ONLY)