forked from qt-creator/qt-creator
CMake Build: Allow building with Qt5 and Qt6
Emulate Qt5's functions/targets with Qt6 equivalents. Change-Id: I6bfc5c8a649f0ddc5f1117bc5b2d0f41cb72c821 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -30,13 +30,17 @@ set(CMAKE_AUTORCC ON)
|
|||||||
set(CMAKE_AUTOUIC ON)
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
|
||||||
if (WITH_TESTS)
|
if (WITH_TESTS)
|
||||||
set(_TEST_QT_COMPONENT Test)
|
set(QT_TEST_COMPONENT Test)
|
||||||
set(_TEST_DEPENDS Qt5::Test)
|
set(IMPLICIT_DEPENDS Qt5::Test)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (BUILD_WITH_PCH)
|
||||||
|
list(APPEND IMPLICIT_DEPENDS Qt5::Core)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(Qt5
|
find_package(Qt5
|
||||||
COMPONENTS Concurrent Core LinguistTools Network PrintSupport Qml Quick
|
COMPONENTS Concurrent Core Gui LinguistTools Network PrintSupport Qml Quick
|
||||||
QuickWidgets Sql Widgets ${_TEST_QT_COMPONENT}
|
QuickWidgets Sql Widgets Xml ${QT_TEST_COMPONENT}
|
||||||
REQUIRED
|
REQUIRED
|
||||||
)
|
)
|
||||||
|
|
||||||
|
68
cmake/FindQt5.cmake
Normal file
68
cmake/FindQt5.cmake
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#.rst:
|
||||||
|
# FindQt5
|
||||||
|
# -------
|
||||||
|
#
|
||||||
|
# Qt5 wrapper around Qt6 CMake code.
|
||||||
|
#
|
||||||
|
|
||||||
|
unset(__arguments)
|
||||||
|
if (Qt5_FIND_QUIETLY)
|
||||||
|
list(APPEND __arguments QUIET)
|
||||||
|
endif()
|
||||||
|
if (Qt5_FIND_REQUIRED)
|
||||||
|
list(APPEND __arguments REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (Qt5_FIND_COMPONENTS)
|
||||||
|
# for some reason QUIET doesn't really work when passed to the arguments list
|
||||||
|
if (Qt5_FIND_QUIETLY)
|
||||||
|
list(APPEND __arguments OPTIONAL_COMPONENTS)
|
||||||
|
else()
|
||||||
|
list(APPEND __arguments COMPONENTS)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(Qt6 CONFIG COMPONENTS Core QUIET)
|
||||||
|
if (NOT Qt6_FOUND)
|
||||||
|
find_package(Qt5 CONFIG ${__arguments} ${Qt5_FIND_COMPONENTS})
|
||||||
|
|
||||||
|
# Remove Qt6 from the not found packages in Qt5 mode
|
||||||
|
get_property(not_found_packages GLOBAL PROPERTY "PACKAGES_NOT_FOUND")
|
||||||
|
if(not_found_packages)
|
||||||
|
list(REMOVE_ITEM not_found_packages Qt6)
|
||||||
|
set_property(GLOBAL PROPERTY "PACKAGES_NOT_FOUND" "${not_found_packages}")
|
||||||
|
endif()
|
||||||
|
return()
|
||||||
|
else()
|
||||||
|
find_package(Qt6 CONFIG ${__arguments} ${Qt5_FIND_COMPONENTS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
foreach(comp IN LISTS Qt5_FIND_COMPONENTS)
|
||||||
|
if(TARGET Qt6::${comp})
|
||||||
|
if (NOT TARGET Qt5::${comp})
|
||||||
|
set_property(TARGET Qt6::${comp} PROPERTY IMPORTED_GLOBAL TRUE)
|
||||||
|
add_library(Qt5::${comp} ALIAS Qt6::${comp})
|
||||||
|
endif()
|
||||||
|
if (TARGET Qt6::${comp}Private AND NOT TARGET Qt5::${comp}Private)
|
||||||
|
set_property(TARGET Qt6::${comp}Private PROPERTY IMPORTED_GLOBAL TRUE)
|
||||||
|
add_library(Qt5::${comp}Private ALIAS Qt6::${comp}Private)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set(Qt5_FOUND ${Qt6_FOUND})
|
||||||
|
|
||||||
|
foreach(tool qmake lrelease)
|
||||||
|
if (TARGET Qt6::${tool} AND NOT TARGET Qt5::${tool})
|
||||||
|
add_executable(Qt5::${tool} IMPORTED GLOBAL)
|
||||||
|
get_target_property(imported_location Qt6::${tool} IMPORTED_LOCATION_RELEASE)
|
||||||
|
set_target_properties(Qt5::${tool} PROPERTIES IMPORTED_LOCATION "${imported_location}")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
if (NOT DEFINED qt5_wrap_cpp)
|
||||||
|
function(qt5_wrap_cpp outfiles)
|
||||||
|
qt6_wrap_cpp(${outfiles} ${ARGN})
|
||||||
|
set(${outfiles} ${${outfiles}} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
endif()
|
@@ -415,7 +415,7 @@ function(add_qtc_library name)
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_qtc_depends(${name}
|
add_qtc_depends(${name}
|
||||||
PRIVATE ${_arg_DEPENDS} ${_TEST_DEPENDS}
|
PRIVATE ${_arg_DEPENDS} ${IMPLICIT_DEPENDS}
|
||||||
PUBLIC ${_arg_PUBLIC_DEPENDS}
|
PUBLIC ${_arg_PUBLIC_DEPENDS}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -626,7 +626,7 @@ function(add_qtc_plugin target_name)
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_qtc_depends(${target_name}
|
add_qtc_depends(${target_name}
|
||||||
PRIVATE ${_arg_DEPENDS} ${_DEP_PLUGINS} ${_TEST_DEPENDS}
|
PRIVATE ${_arg_DEPENDS} ${_DEP_PLUGINS} ${IMPLICIT_DEPENDS}
|
||||||
PUBLIC ${_arg_PUBLIC_DEPENDS}
|
PUBLIC ${_arg_PUBLIC_DEPENDS}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -799,7 +799,7 @@ function(add_qtc_executable name)
|
|||||||
add_executable("${name}" ${_arg_SOURCES})
|
add_executable("${name}" ${_arg_SOURCES})
|
||||||
target_include_directories("${name}" PRIVATE "${CMAKE_BINARY_DIR}/src" ${_arg_INCLUDES})
|
target_include_directories("${name}" PRIVATE "${CMAKE_BINARY_DIR}/src" ${_arg_INCLUDES})
|
||||||
target_compile_definitions("${name}" PRIVATE ${_arg_DEFINES} ${TEST_DEFINES} ${DEFAULT_DEFINES})
|
target_compile_definitions("${name}" PRIVATE ${_arg_DEFINES} ${TEST_DEFINES} ${DEFAULT_DEFINES})
|
||||||
target_link_libraries("${name}" PRIVATE ${_arg_DEPENDS} ${_TEST_DEPENDS})
|
target_link_libraries("${name}" PRIVATE ${_arg_DEPENDS} ${IMPLICIT_DEPENDS})
|
||||||
|
|
||||||
set(skip_translation OFF)
|
set(skip_translation OFF)
|
||||||
if (_arg_SKIP_TRANSLATION)
|
if (_arg_SKIP_TRANSLATION)
|
||||||
@@ -846,7 +846,7 @@ function(add_qtc_test name)
|
|||||||
add_executable(${name} ${_arg_SOURCES})
|
add_executable(${name} ${_arg_SOURCES})
|
||||||
|
|
||||||
add_qtc_depends(${name}
|
add_qtc_depends(${name}
|
||||||
PRIVATE ${_arg_DEPENDS} ${_TEST_DEPENDS}
|
PRIVATE ${_arg_DEPENDS} ${IMPLICIT_DEPENDS}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(${name} PRIVATE "${CMAKE_BINARY_DIR}/src" ${_arg_INCLUDES})
|
target_include_directories(${name} PRIVATE "${CMAKE_BINARY_DIR}/src" ${_arg_INCLUDES})
|
||||||
|
@@ -44,6 +44,7 @@
|
|||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <utils/algorithm.h>
|
||||||
#include <utils/icon.h>
|
#include <utils/icon.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
@@ -442,7 +443,7 @@ void NavigatorView::changeSelection(const QItemSelection & /*newSelection*/, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool blocked = blockSelectionChangedSignal(true);
|
bool blocked = blockSelectionChangedSignal(true);
|
||||||
setSelectedModelNodes(nodeSet.toList());
|
setSelectedModelNodes(Utils::toList(nodeSet));
|
||||||
blockSelectionChangedSignal(blocked);
|
blockSelectionChangedSignal(blocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -80,7 +80,7 @@ QStringList QmlProjectItem::files() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return files.toList();
|
return Utils::toList(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -50,5 +50,16 @@
|
|||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
#include <QTextStream>
|
||||||
|
using Qt::endl;
|
||||||
|
using Qt::forcesign;
|
||||||
|
using Qt::noshowbase;
|
||||||
|
using Qt::dec;
|
||||||
|
using Qt::showbase;
|
||||||
|
using Qt::hex;
|
||||||
|
using Qt::noforcesign;
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user