cmake/Source/QtDialog/CMakeLists.txt

370 lines
12 KiB
CMake
Raw Normal View History

2016-10-30 18:24:19 +01:00
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
2013-03-16 19:13:01 +02:00
project(QtDialog)
2015-11-17 17:22:37 +01:00
CMake_OPTIONAL_COMPONENT(cmake-gui)
2022-11-16 20:14:03 +01:00
set(QT_COMPONENTS
2021-09-14 00:13:48 +02:00
Core
Widgets
Gui
)
2014-08-03 19:52:23 +02:00
2021-09-14 00:13:48 +02:00
set(CMake_QT_MAJOR_VERSION "A" CACHE
STRING "Expected Qt major version. Valid values are A (auto-select), 5, 6.")
set(SUPPORTED_QT_VERSIONS "A" 5 6)
set_property(CACHE CMake_QT_MAJOR_VERSION PROPERTY STRINGS ${SUPPORTED_QT_VERSIONS})
if(NOT CMake_QT_MAJOR_VERSION STREQUAL "A")
if(NOT CMake_QT_MAJOR_VERSION IN_LIST SUPPORTED_QT_VERSIONS)
message(FATAL_ERROR "Supported Qt versions are \"${SUPPORTED_QT_VERSIONS}\"."
" But CMake_QT_MAJOR_VERSION is set to ${CMake_QT_MAJOR_VERSION}.")
endif()
set(INSTALLED_QT_VERSION ${CMake_QT_MAJOR_VERSION})
else()
find_package(Qt6Widgets QUIET)
set(INSTALLED_QT_VERSION 6)
if(NOT Qt6Widgets_FOUND)
find_package(Qt5Widgets QUIET)
if(NOT Qt5Widgets_FOUND)
message(FATAL_ERROR "Could not find a valid Qt installation.")
2019-11-11 23:01:05 +01:00
endif()
2021-09-14 00:13:48 +02:00
set(INSTALLED_QT_VERSION 5)
2019-11-11 23:01:05 +01:00
endif()
2021-09-14 00:13:48 +02:00
endif()
2019-11-11 23:01:05 +01:00
2021-09-14 00:13:48 +02:00
find_package(Qt${INSTALLED_QT_VERSION}
COMPONENTS ${QT_COMPONENTS}
REQUIRED QUIET
)
2021-09-14 00:13:48 +02:00
set(CMake_QT_EXTRA_LIBRARIES)
2013-11-03 12:27:13 +02:00
2021-09-14 00:13:48 +02:00
# Try to find the package WinExtras for the task bar progress
if(WIN32)
find_package(Qt${INSTALLED_QT_VERSION}WinExtras QUIET)
2022-11-16 20:14:03 +01:00
if(Qt${INSTALLED_QT_VERSION}WinExtras_FOUND)
add_compile_definitions(QT_WINEXTRAS)
2021-09-14 00:13:48 +02:00
list(APPEND CMake_QT_EXTRA_LIBRARIES Qt${INSTALLED_QT_VERSION}::WinExtras)
list(APPEND QT_COMPONENTS WinExtras)
2016-10-30 18:24:19 +01:00
endif()
2021-09-14 00:13:48 +02:00
endif()
2016-10-30 18:24:19 +01:00
2021-09-14 00:13:48 +02:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt${INSTALLED_QT_VERSION}Widgets_EXECUTABLE_COMPILE_FLAGS}")
2018-01-26 17:06:56 +01:00
2021-09-14 00:13:48 +02:00
if(CMake_QT_STATIC_QXcbIntegrationPlugin_LIBRARIES)
list(APPEND CMake_QT_EXTRA_LIBRARIES ${CMake_QT_STATIC_QXcbIntegrationPlugin_LIBRARIES})
set_property(SOURCE CMakeSetup.cxx
PROPERTY COMPILE_DEFINITIONS USE_QXcbIntegrationPlugin)
endif()
if(CMake_QT_STATIC_QWindowsIntegrationPlugin_LIBRARIES)
list(APPEND CMake_QT_EXTRA_LIBRARIES ${CMake_QT_STATIC_QWindowsIntegrationPlugin_LIBRARIES})
set_property(SOURCE CMakeSetup.cxx
PROPERTY COMPILE_DEFINITIONS USE_QWindowsIntegrationPlugin)
endif()
# We need to install platform plugin and add qt.conf for Qt5 on Mac and Windows.
if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
function(_qt_get_plugin_name_with_version target out_var)
string(REGEX REPLACE "^Qt::(.+)" "Qt${INSTALLED_QT_VERSION}::\\1"
qt_plugin_with_version "${target}")
if(TARGET "${qt_plugin_with_version}")
set("${out_var}" "${qt_plugin_with_version}" PARENT_SCOPE)
2015-04-27 22:25:09 +02:00
else()
2021-09-14 00:13:48 +02:00
set("${out_var}" "" PARENT_SCOPE)
2015-04-27 22:25:09 +02:00
endif()
2021-09-14 00:13:48 +02:00
endfunction()
macro(install_qt_plugin _qt_plugin_name _qt_plugins_var)
if(TARGET "${_qt_plugin_name}")
get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION)
else()
_qt_get_plugin_name_with_version("Qt::${_qt_plugin_name}" _qt_plugin_with_version_name)
if(TARGET "${_qt_plugin_with_version_name}")
get_target_property(_qt_plugin_path "${_qt_plugin_with_version_name}" LOCATION)
endif()
endif()
if(EXISTS "${_qt_plugin_path}")
get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME)
get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH)
get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME)
if(APPLE)
set(_qt_plugin_dir "PlugIns")
elseif(WIN32)
set(_qt_plugin_dir "plugins")
endif()
set(_qt_plugin_dest "${_qt_plugin_dir}/${_qt_plugin_type}")
install(FILES "${_qt_plugin_path}"
DESTINATION "${_qt_plugin_dest}"
2015-11-17 17:22:37 +01:00
${COMPONENT})
2021-09-14 00:13:48 +02:00
set(${_qt_plugins_var}
"${${_qt_plugins_var}};\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${_qt_plugin_dest}/${_qt_plugin_file}")
2015-11-17 17:22:37 +01:00
endif()
2021-09-14 00:13:48 +02:00
endmacro()
macro(install_qt_plugins _comps _plugins_var)
2022-11-16 20:14:03 +01:00
foreach(_qt_comp IN LISTS ${_comps})
if(INSTALLED_QT_VERSION VERSION_LESS 6)
2021-09-14 00:13:48 +02:00
set(_qt_module_plugins ${Qt${INSTALLED_QT_VERSION}${_qt_comp}_PLUGINS})
else()
get_target_property(_qt_module_plugins Qt${INSTALLED_QT_VERSION}::${_qt_comp} QT_PLUGINS)
endif()
2022-11-16 20:14:03 +01:00
foreach(_qt_plugin IN LISTS _qt_module_plugins)
if(INSTALLED_QT_VERSION VERSION_GREATER_EQUAL 6)
2021-09-14 00:13:48 +02:00
# Qt6 provides the plugins as individual packages that need to be found.
find_package(Qt${INSTALLED_QT_VERSION}${_qt_plugin} QUIET
PATHS ${Qt${INSTALLED_QT_VERSION}${_qt_comp}_DIR})
endif()
install_qt_plugin("${_qt_plugin}" "${_plugins_var}")
endforeach()
endforeach()
endmacro()
if(APPLE)
2022-11-16 20:14:03 +01:00
if(INSTALLED_QT_VERSION VERSION_EQUAL 5)
2021-09-14 00:13:48 +02:00
install_qt_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS)
if(TARGET Qt5::QMacStylePlugin)
install_qt_plugin("Qt5::QMacStylePlugin" QT_PLUGINS)
endif()
else()
# FIXME: Minimize plugins for Qt6.
install_qt_plugins(QT_COMPONENTS QT_PLUGINS)
2015-11-17 17:22:37 +01:00
endif()
2021-09-14 00:13:48 +02:00
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
"[Paths]\nPlugins = ${_qt_plugin_dir}\n")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
DESTINATION "${CMAKE_INSTALL_PREFIX}/Resources"
${COMPONENT})
elseif(WIN32 AND NOT CMake_QT_STATIC_QWindowsIntegrationPlugin_LIBRARIES)
2022-11-16 20:14:03 +01:00
if(INSTALLED_QT_VERSION VERSION_EQUAL 5)
2021-09-14 00:13:48 +02:00
install_qt_plugin("Qt5::QWindowsIntegrationPlugin" QT_PLUGINS)
else()
# FIXME: Minimize plugins for Qt6.
install_qt_plugins(QT_COMPONENTS QT_PLUGINS)
endif()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
"[Paths]\nPlugins = ../${_qt_plugin_dir}\n")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
DESTINATION bin
${COMPONENT})
2013-11-03 12:27:13 +02:00
endif()
2021-09-14 00:13:48 +02:00
endif()
2014-08-03 19:52:23 +02:00
2021-09-14 00:13:48 +02:00
get_property(_Qt_Core_LOCATION TARGET Qt${INSTALLED_QT_VERSION}::Core PROPERTY LOCATION)
get_filename_component(Qt_BIN_DIR "${_Qt_Core_LOCATION}" PATH)
if(APPLE)
get_filename_component(Qt_BIN_DIR "${Qt_BIN_DIR}" PATH)
2013-03-16 19:13:01 +02:00
endif()
2022-11-16 20:14:03 +01:00
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_library(
CMakeGUILib STATIC
2013-03-16 19:13:01 +02:00
AddCacheEntry.cxx
AddCacheEntry.h
CMakeSetupDialog.cxx
CMakeSetupDialog.h
2021-09-14 00:13:48 +02:00
Compilers.h
EnvironmentDialog.cxx
EnvironmentDialog.h
2013-03-16 19:13:01 +02:00
FirstConfigure.cxx
FirstConfigure.h
QCMake.cxx
QCMake.h
QCMakeCacheView.cxx
QCMakeCacheView.h
2021-09-14 00:13:48 +02:00
QCMakePreset.cxx
QCMakePreset.h
QCMakePresetComboBox.cxx
QCMakePresetComboBox.h
QCMakePresetItemModel.cxx
QCMakePresetItemModel.h
2023-07-02 19:51:09 +02:00
QCMakeSizeType.h
2013-03-16 19:13:01 +02:00
QCMakeWidgets.cxx
QCMakeWidgets.h
2016-03-13 13:35:51 +01:00
RegexExplorer.cxx
RegexExplorer.h
WarningMessagesDialog.cxx
WarningMessagesDialog.h
2013-03-16 19:13:01 +02:00
)
2022-11-16 20:14:03 +01:00
# CMake_QT_EXTRA_LIBRARIES have to come before the main libraries on the link line
target_link_libraries(
CMakeGUILib
PUBLIC
CMakeLib
${CMake_QT_EXTRA_LIBRARIES}
Qt${INSTALLED_QT_VERSION}::Core
Qt${INSTALLED_QT_VERSION}::Widgets
)
2021-09-14 00:13:48 +02:00
set(UI_SRCS
2013-03-16 19:13:01 +02:00
CMakeSetupDialog.ui
Compilers.ui
CrossCompiler.ui
AddCacheEntry.ui
2021-09-14 00:13:48 +02:00
EnvironmentDialog.ui
2016-03-13 13:35:51 +01:00
RegexExplorer.ui
WarningMessagesDialog.ui
2013-03-16 19:13:01 +02:00
)
2021-09-14 00:13:48 +02:00
set(MOC_SRCS
2013-03-16 19:13:01 +02:00
AddCacheEntry.h
Compilers.h
CMakeSetupDialog.h
2021-09-14 00:13:48 +02:00
EnvironmentDialog.h
2013-03-16 19:13:01 +02:00
FirstConfigure.h
QCMake.h
QCMakeCacheView.h
2021-09-14 00:13:48 +02:00
QCMakePresetComboBox.h
QCMakePresetItemModel.h
2013-03-16 19:13:01 +02:00
QCMakeWidgets.h
2016-03-13 13:35:51 +01:00
RegexExplorer.h
WarningMessagesDialog.h
2013-03-16 19:13:01 +02:00
)
2021-09-14 00:13:48 +02:00
set(QRC_SRCS CMakeSetup.qrc)
2022-11-16 20:14:03 +01:00
if(INSTALLED_QT_VERSION VERSION_LESS 6)
2021-09-14 00:13:48 +02:00
qt5_wrap_ui(UI_BUILT_SRCS ${UI_SRCS})
qt5_wrap_cpp(MOC_BUILT_SRCS ${MOC_SRCS})
qt5_add_resources(QRC_BUILT_SRCS ${QRC_SRCS})
else()
qt_wrap_ui(UI_BUILT_SRCS ${UI_SRCS})
qt_wrap_cpp(MOC_BUILT_SRCS ${MOC_SRCS})
qt_add_resources(QRC_BUILT_SRCS ${QRC_SRCS})
2013-03-16 19:13:01 +02:00
endif()
2021-09-14 00:13:48 +02:00
add_library(CMakeGUIQRCLib OBJECT ${QRC_BUILT_SRCS})
2022-11-16 20:14:03 +01:00
if(FALSE) # CMake's bootstrap binary does not support automoc
2021-09-14 00:13:48 +02:00
set(CMAKE_AUTOMOC 1)
set(CMAKE_AUTORCC 1)
set(CMAKE_AUTOUIC 1)
2022-11-16 20:14:03 +01:00
else()
target_sources(
CMakeGUILib
PRIVATE
${UI_BUILT_SRCS}
${MOC_BUILT_SRCS}
)
endif()
2011-01-16 11:35:12 +01:00
2016-10-30 18:24:19 +01:00
if(USE_LGPL)
install(FILES ${CMake_SOURCE_DIR}/Licenses/LGPLv${USE_LGPL}.txt
2015-11-17 17:22:37 +01:00
DESTINATION ${CMAKE_DATA_DIR}/Licenses
${COMPONENT})
2014-08-03 19:52:23 +02:00
set_property(SOURCE CMakeSetupDialog.cxx
2016-10-30 18:24:19 +01:00
PROPERTY COMPILE_DEFINITIONS USE_LGPL="${USE_LGPL}")
2014-08-03 19:52:23 +02:00
endif()
2021-09-14 00:13:48 +02:00
add_library(CMakeGUIMainLib STATIC CMakeSetup.cxx)
2022-11-16 20:14:03 +01:00
target_link_libraries(
CMakeGUIMainLib
PUBLIC
CMakeGUILib
)
2022-11-16 20:14:03 +01:00
add_executable(cmake-gui WIN32 MACOSX_BUNDLE CMakeGUIExec.cxx)
target_link_libraries(cmake-gui
PRIVATE
CMakeGUIMainLib
CMakeGUIQRCLib
$<TARGET_NAME_IF_EXISTS:CMakeVersion>
ManifestLib
Qt${INSTALLED_QT_VERSION}::Core
)
2021-09-14 00:13:48 +02:00
2018-04-23 21:13:27 +02:00
if(WIN32)
2022-11-16 20:14:03 +01:00
target_sources(CMakeGUIMainLib INTERFACE CMakeSetup.rc)
2021-09-14 00:13:48 +02:00
endif()
if(APPLE)
target_sources(CMakeGUIMainLib INTERFACE CMakeSetup.icns)
set(MACOSX_BUNDLE_ICON_FILE CMakeSetup.icns)
set_source_files_properties(CMakeSetup.icns PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
2018-04-23 21:13:27 +02:00
endif()
2020-08-30 11:54:41 +02:00
if(CMake_JOB_POOL_LINK_BIN)
set_property(TARGET cmake-gui PROPERTY JOB_POOL_LINK "link-bin")
endif()
2017-07-20 19:35:53 +02:00
# cmake-gui has not been updated for `include-what-you-use`.
# Block the tool until this is done.
2021-09-14 00:13:48 +02:00
set_target_properties(CMakeGUILib CMakeGUIMainLib cmake-gui PROPERTIES
2017-07-20 19:35:53 +02:00
CXX_INCLUDE_WHAT_YOU_USE ""
)
# Files generated by MOC, RCC, and UIC may produce clang-tidy warnings.
# We generate a dummy .clang-tidy file in the binary directory that disables
# all clang-tidy checks except one that will never match. This one check is
# necessary; clang-tidy reports an error when no checks are enabled.
# Since the Qt code generators will generate source files in the binary tree,
# clang-tidy will load the configuration from this dummy file when the sources
# are built.
file(WRITE "${QtDialog_BINARY_DIR}/.clang-tidy" "
---
Checks: '-*,llvm-twine-local'
...
")
2013-03-16 19:13:01 +02:00
if(APPLE)
2014-08-03 19:52:23 +02:00
file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
LIMIT_COUNT 1 REGEX "^Copyright 2000-20[0-9][0-9] Kitware")
2013-03-16 19:13:01 +02:00
set_target_properties(cmake-gui PROPERTIES
2014-08-03 19:52:23 +02:00
OUTPUT_NAME CMake
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${CMAKE_BUNDLE_VERSION}"
# TBD: MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_BUNDLE_VERSION}"
MACOSX_BUNDLE_COPYRIGHT "${copyright_line}"
2016-03-29 18:52:50 +02:00
MACOSX_BUNDLE_GUI_IDENTIFIER "org.cmake.cmake"
2014-08-03 19:52:23 +02:00
)
# Create a symlink in the build tree to provide a "cmake-gui" next
# to the "cmake" executable that refers to the application bundle.
add_custom_command(TARGET cmake-gui POST_BUILD
COMMAND ln -sf CMake.app/Contents/MacOS/CMake
$<TARGET_FILE_DIR:cmake>/cmake-gui
)
2013-03-16 19:13:01 +02:00
endif()
2011-01-16 11:35:12 +01:00
2015-11-17 17:22:37 +01:00
install(TARGETS cmake-gui
RUNTIME DESTINATION bin ${COMPONENT}
2022-11-16 20:14:03 +01:00
BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}" ${COMPONENT})
2011-01-16 11:35:12 +01:00
2015-04-27 22:25:09 +02:00
if(UNIX AND NOT APPLE)
2022-11-16 20:14:03 +01:00
foreach(size IN ITEMS 32 128)
2015-04-27 22:25:09 +02:00
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/CMakeSetup${size}.png"
2016-03-13 13:35:51 +01:00
DESTINATION "${CMAKE_XDGDATA_DIR}/icons/hicolor/${size}x${size}/apps"
2015-11-17 17:22:37 +01:00
${COMPONENT}
2015-04-27 22:25:09 +02:00
RENAME "CMakeSetup.png")
2022-11-16 20:14:03 +01:00
endforeach()
2015-04-27 22:25:09 +02:00
2013-03-16 19:13:01 +02:00
# install a desktop file so CMake appears in the application start menu
# with an icon
2017-07-20 19:35:53 +02:00
install(FILES cmake-gui.desktop
2016-03-13 13:35:51 +01:00
DESTINATION "${CMAKE_XDGDATA_DIR}/applications"
2015-11-17 17:22:37 +01:00
${COMPONENT})
install(FILES cmakecache.xml
2016-03-13 13:35:51 +01:00
DESTINATION "${CMAKE_XDGDATA_DIR}/mime/packages"
2015-11-17 17:22:37 +01:00
${COMPONENT})
2013-03-16 19:13:01 +02:00
endif()
2013-03-16 19:13:01 +02:00
if(APPLE)
2015-11-17 17:22:37 +01:00
install(CODE "
execute_process(COMMAND ln -s \"../MacOS/CMake\" cmake-gui
WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin)
" ${COMPONENT})
2013-03-16 19:13:01 +02:00
endif()
2015-11-17 17:22:37 +01:00
if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
2013-03-16 19:13:01 +02:00
# install rules for including 3rd party libs such as Qt
# if a system Qt is used (e.g. installed in /usr/lib/), it will not be included in the installation
set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/cmake-gui${CMAKE_EXECUTABLE_SUFFIX}")
if(APPLE)
2014-08-03 19:52:23 +02:00
set(fixup_exe "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/MacOS/CMake")
2013-03-16 19:13:01 +02:00
endif()
install(CODE "
include(\"${CMake_SOURCE_DIR}/Modules/BundleUtilities.cmake\")
set(BU_CHMOD_BUNDLE_ITEMS ON)
2015-11-17 17:22:37 +01:00
fixup_bundle(\"${fixup_exe}\" \"${QT_PLUGINS}\" \"${Qt_BIN_DIR};${QT_LIBRARY_DIR};${QT_BINARY_DIR}\")
" ${COMPONENT})
2013-03-16 19:13:01 +02:00
endif()
set(CMAKE_PACKAGE_QTGUI TRUE)
2022-11-16 20:14:03 +01:00
configure_file(QtDialogCPack.cmake.in QtDialogCPack.cmake @ONLY)