CMakeLists.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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(WIN32 AND 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. endif()
  80. else()
  81. set(QT_MIN_VERSION "4.4.0")
  82. find_package(Qt4 REQUIRED)
  83. if(NOT QT4_FOUND)
  84. message(SEND_ERROR "Failed to find Qt 4.4 or greater.")
  85. return()
  86. endif()
  87. include(${QT_USE_FILE})
  88. set(CMake_QT_LIBRARIES ${QT_LIBRARIES})
  89. if(WIN32 AND EXISTS "${QT_QMAKE_EXECUTABLE}")
  90. get_filename_component(_Qt_BIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH)
  91. if(EXISTS "${_Qt_BIN_DIR}/QtCore4.dll")
  92. set(Qt_BIN_DIR ${_Qt_BIN_DIR})
  93. endif()
  94. endif()
  95. endif()
  96. set(SRCS
  97. AddCacheEntry.cxx
  98. AddCacheEntry.h
  99. CMakeSetup.cxx
  100. CMakeSetupDialog.cxx
  101. CMakeSetupDialog.h
  102. FirstConfigure.cxx
  103. FirstConfigure.h
  104. QCMake.cxx
  105. QCMake.h
  106. QCMakeCacheView.cxx
  107. QCMakeCacheView.h
  108. QCMakeWidgets.cxx
  109. QCMakeWidgets.h
  110. )
  111. QT4_WRAP_UI(UI_SRCS
  112. CMakeSetupDialog.ui
  113. Compilers.ui
  114. CrossCompiler.ui
  115. AddCacheEntry.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. )
  126. QT4_ADD_RESOURCES(RC_SRCS CMakeSetup.qrc)
  127. set(SRCS ${SRCS} ${UI_SRCS} ${MOC_SRCS} ${RC_SRCS})
  128. if(WIN32)
  129. set(SRCS ${SRCS} CMakeSetup.rc)
  130. endif()
  131. if(APPLE)
  132. set(SRCS ${SRCS} CMakeSetup.icns)
  133. set(MACOSX_BUNDLE_ICON_FILE CMakeSetup.icns)
  134. set_source_files_properties(CMakeSetup.icns PROPERTIES
  135. MACOSX_PACKAGE_LOCATION Resources)
  136. endif()
  137. if(CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
  138. install(FILES ${CMake_SOURCE_DIR}/Licenses/LGPLv2.1.txt
  139. DESTINATION ${CMAKE_DATA_DIR}/Licenses
  140. ${COMPONENT})
  141. set_property(SOURCE CMakeSetupDialog.cxx
  142. PROPERTY COMPILE_DEFINITIONS CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL)
  143. endif()
  144. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  145. add_executable(cmake-gui WIN32 MACOSX_BUNDLE ${SRCS})
  146. target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${CMake_QT_LIBRARIES})
  147. if(Qt_BIN_DIR)
  148. set_property(TARGET cmake-gui PROPERTY Qt_BIN_DIR ${Qt_BIN_DIR})
  149. endif()
  150. if(APPLE)
  151. file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
  152. LIMIT_COUNT 1 REGEX "^Copyright 2000-20[0-9][0-9] Kitware")
  153. set_target_properties(cmake-gui PROPERTIES
  154. OUTPUT_NAME CMake
  155. MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
  156. MACOSX_BUNDLE_SHORT_VERSION_STRING "${CMAKE_BUNDLE_VERSION}"
  157. # TBD: MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_BUNDLE_VERSION}"
  158. MACOSX_BUNDLE_COPYRIGHT "${copyright_line}"
  159. )
  160. # Create a symlink in the build tree to provide a "cmake-gui" next
  161. # to the "cmake" executable that refers to the application bundle.
  162. add_custom_command(TARGET cmake-gui POST_BUILD
  163. COMMAND ln -sf CMake.app/Contents/MacOS/CMake
  164. $<TARGET_FILE_DIR:cmake>/cmake-gui
  165. )
  166. endif()
  167. set(CMAKE_INSTALL_DESTINATION_ARGS
  168. BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}" ${COMPONENT})
  169. install(TARGETS cmake-gui
  170. RUNTIME DESTINATION bin ${COMPONENT}
  171. ${CMAKE_INSTALL_DESTINATION_ARGS})
  172. if(UNIX AND NOT APPLE)
  173. foreach (size IN ITEMS 32 128)
  174. install(
  175. FILES "${CMAKE_CURRENT_SOURCE_DIR}/CMakeSetup${size}.png"
  176. DESTINATION "share/icons/hicolor/${size}x${size}/apps"
  177. ${COMPONENT}
  178. RENAME "CMakeSetup.png")
  179. endforeach ()
  180. # install a desktop file so CMake appears in the application start menu
  181. # with an icon
  182. install(FILES CMake.desktop
  183. DESTINATION share/applications
  184. ${COMPONENT})
  185. install(FILES cmakecache.xml
  186. DESTINATION share/mime/packages
  187. ${COMPONENT})
  188. endif()
  189. if(APPLE)
  190. install(CODE "
  191. execute_process(COMMAND ln -s \"../MacOS/CMake\" cmake-gui
  192. WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)
  193. " ${COMPONENT})
  194. endif()
  195. if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
  196. # install rules for including 3rd party libs such as Qt
  197. # if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation
  198. set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/cmake-gui${CMAKE_EXECUTABLE_SUFFIX}")
  199. if(APPLE)
  200. set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/MacOS/CMake")
  201. endif()
  202. install(CODE "
  203. include(\"${CMake_SOURCE_DIR}/Modules/BundleUtilities.cmake\")
  204. set(BU_CHMOD_BUNDLE_ITEMS ON)
  205. fixup_bundle(\"${fixup_exe}\" \"${QT_PLUGINS}\" \"${QT_LIBRARY_DIR};${QT_BINARY_DIR}\")
  206. " ${COMPONENT})
  207. endif()
  208. set(CMAKE_PACKAGE_QTGUI TRUE)
  209. configure_file("${QtDialog_SOURCE_DIR}/QtDialogCPack.cmake.in"
  210. "${QtDialog_BINARY_DIR}/QtDialogCPack.cmake" @ONLY)