some preparations for Qt6 support (#3777)

* findDependencies.cmake: cleaned up find_package() call for Qt

* some CMake preparations for Qt6 support

* some Qt6 compilation fixes
This commit is contained in:
Oliver Stöneberg 2022-02-07 17:35:25 +01:00 committed by GitHub
parent 047930fd17
commit d528555002
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 95 additions and 68 deletions

View File

@ -13,6 +13,9 @@ include(cmake/compileroptions.cmake)
include(cmake/compilerDefinitions.cmake)
include(cmake/buildFiles.cmake)
include(cmake/cxx11.cmake)
if (BUILD_GUI)
include(cmake/qtCompat.cmake)
endif()
use_cxx11()

View File

@ -1,17 +1,12 @@
if (BUILD_GUI)
if (BUILD_TESTS)
if (NOT WITH_QCHART)
find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help Test REQUIRED)
else()
find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help Test Charts REQUIRED)
endif()
else()
if (NOT WITH_QCHART)
find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help REQUIRED)
else()
find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help Charts REQUIRED)
endif()
list(APPEND qt_components Core Gui Widgets PrintSupport LinguistTools Help)
if (WITH_QCHART)
list(APPEND qt_components Charts)
endif()
if (BUILD_TESTS)
list(APPEND qt_components Test)
endif()
find_package(Qt5 COMPONENTS ${qt_components} REQUIRED)
endif()
if (HAVE_RULES)

29
cmake/qtCompat.cmake Normal file
View File

@ -0,0 +1,29 @@
# "versionless" Qt is not supported until 5.15 we need to use wrappers
function(qt_wrap_ui out)
qt5_wrap_ui(_uis_hdrs ${ARGN})
set("${out}" ${_uis_hdrs} PARENT_SCOPE)
endfunction()
function(qt_add_resources out)
qt5_add_resources(_resources ${ARGN})
set("${out}" ${_resources} PARENT_SCOPE)
endfunction()
function(qt_add_translation out)
qt5_add_translation(_qms ${ARGN})
set("${out}" ${_qms} PARENT_SCOPE)
endfunction()
function(qt_wrap_cpp out)
qt5_wrap_cpp(_sources ${ARGN})
set("${out}" ${_sources} PARENT_SCOPE)
endfunction()
set(QT_CORE_LIB Qt5::Core)
set(QT_TEST_LIB Qt5::Test)
set(QT_WIDGETS_LIB Qt5::Widgets)
set(QT_GUI_LIB Qt5::Gui)
set(QT_HELP_LIB Qt5::Help)
set(QT_PRINTSUPPORT_LIB Qt5::PrintSupport)
set(QT_CHARTS_LIB Qt5::Charts)

View File

@ -12,9 +12,9 @@ if (BUILD_GUI)
file(GLOB srcs "*.cpp")
file(GLOB uis "*.ui")
file(GLOB tss "*.ts")
QT5_WRAP_UI(uis_hdrs ${uis})
QT5_ADD_RESOURCES(resources "gui.qrc")
QT5_ADD_TRANSLATION(qms ${tss})
QT_WRAP_UI(uis_hdrs ${uis})
QT_ADD_RESOURCES(resources "gui.qrc")
QT_ADD_TRANSLATION(qms ${tss})
list(APPEND cppcheck-gui-deps ${hdrs} ${uis_hdrs} ${resources} ${qms} )
add_custom_target(gui-build-deps SOURCES ${cppcheck-gui-deps})
@ -38,10 +38,10 @@ if (BUILD_GUI)
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
target_link_libraries(cppcheck-gui tinyxml2)
endif()
target_link_libraries(cppcheck-gui Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport Qt5::Help)
target_link_libraries(cppcheck-gui ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB} ${QT_PRINTSUPPORT_LIB} ${QT_HELP_LIB})
if(WITH_QCHART)
target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART)
target_link_libraries(cppcheck-gui Qt5::Charts)
target_link_libraries(cppcheck-gui ${QT_CHARTS_LIB})
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0")

View File

@ -331,12 +331,12 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader)
mandatoryAttibuteMissing(xmlReader, "ext");
}
if (xmlReader.attributes().hasAttribute("aftercode")) {
markup.afterCode = (xmlReader.attributes().value("aftercode") == "true") ? true : false;
markup.afterCode = (xmlReader.attributes().value("aftercode") == QString("true")) ? true : false;
} else {
mandatoryAttibuteMissing(xmlReader, "aftercode");
}
if (xmlReader.attributes().hasAttribute("reporterrors")) {
markup.reportErrors = (xmlReader.attributes().value("reporterrors") == "true") ? true : false;
markup.reportErrors = (xmlReader.attributes().value("reporterrors") == QString("true")) ? true : false;
} else {
mandatoryAttibuteMissing(xmlReader, "reporterrors");
}

View File

@ -92,7 +92,7 @@ bool ProjectFile::read(const QString &filename)
while (!xmlReader.atEnd()) {
switch (xmlReader.readNext()) {
case QXmlStreamReader::StartElement:
if (xmlReader.name() == CppcheckXml::ProjectElementName) {
if (xmlReader.name() == QString(CppcheckXml::ProjectElementName)) {
insideProject = true;
projectTagFound = true;
break;
@ -101,114 +101,114 @@ bool ProjectFile::read(const QString &filename)
break;
// Read root path from inside project element
if (xmlReader.name() == CppcheckXml::RootPathName)
if (xmlReader.name() == QString(CppcheckXml::RootPathName))
readRootPath(xmlReader);
// Read root path from inside project element
if (xmlReader.name() == CppcheckXml::BuildDirElementName)
if (xmlReader.name() == QString(CppcheckXml::BuildDirElementName))
readBuildDir(xmlReader);
// Find paths to check from inside project element
if (xmlReader.name() == CppcheckXml::PathsElementName)
if (xmlReader.name() == QString(CppcheckXml::PathsElementName))
readCheckPaths(xmlReader);
if (xmlReader.name() == CppcheckXml::ImportProjectElementName)
if (xmlReader.name() == QString(CppcheckXml::ImportProjectElementName))
readImportProject(xmlReader);
if (xmlReader.name() == CppcheckXml::AnalyzeAllVsConfigsElementName)
if (xmlReader.name() == QString(CppcheckXml::AnalyzeAllVsConfigsElementName))
mAnalyzeAllVsConfigs = readBool(xmlReader);
if (xmlReader.name() == CppcheckXml::Parser)
if (xmlReader.name() == QString(CppcheckXml::Parser))
clangParser = true;
if (xmlReader.name() == CppcheckXml::BugHunting)
if (xmlReader.name() == QString(CppcheckXml::BugHunting))
bugHunting = true;
if (xmlReader.name() == CppcheckXml::CheckHeadersElementName)
if (xmlReader.name() == QString(CppcheckXml::CheckHeadersElementName))
mCheckHeaders = readBool(xmlReader);
if (xmlReader.name() == CppcheckXml::CheckUnusedTemplatesElementName)
if (xmlReader.name() == QString(CppcheckXml::CheckUnusedTemplatesElementName))
mCheckUnusedTemplates = readBool(xmlReader);
// Find include directory from inside project element
if (xmlReader.name() == CppcheckXml::IncludeDirElementName)
if (xmlReader.name() == QString(CppcheckXml::IncludeDirElementName))
readIncludeDirs(xmlReader);
// Find preprocessor define from inside project element
if (xmlReader.name() == CppcheckXml::DefinesElementName)
if (xmlReader.name() == QString(CppcheckXml::DefinesElementName))
readDefines(xmlReader);
// Find preprocessor define from inside project element
if (xmlReader.name() == CppcheckXml::UndefinesElementName)
if (xmlReader.name() == QString(CppcheckXml::UndefinesElementName))
readStringList(mUndefines, xmlReader, CppcheckXml::UndefineName);
// Find exclude list from inside project element
if (xmlReader.name() == CppcheckXml::ExcludeElementName)
if (xmlReader.name() == QString(CppcheckXml::ExcludeElementName))
readExcludes(xmlReader);
// Find ignore list from inside project element
// These are read for compatibility
if (xmlReader.name() == CppcheckXml::IgnoreElementName)
if (xmlReader.name() == QString(CppcheckXml::IgnoreElementName))
readExcludes(xmlReader);
// Function contracts
if (xmlReader.name() == CppcheckXml::FunctionContracts)
if (xmlReader.name() == QString(CppcheckXml::FunctionContracts))
readFunctionContracts(xmlReader);
// Variable constraints
if (xmlReader.name() == CppcheckXml::VariableContractsElementName)
if (xmlReader.name() == QString(CppcheckXml::VariableContractsElementName))
readVariableContracts(xmlReader);
// Find libraries list from inside project element
if (xmlReader.name() == CppcheckXml::LibrariesElementName)
if (xmlReader.name() == QString(CppcheckXml::LibrariesElementName))
readStringList(mLibraries, xmlReader, CppcheckXml::LibraryElementName);
if (xmlReader.name() == CppcheckXml::PlatformElementName)
if (xmlReader.name() == QString(CppcheckXml::PlatformElementName))
readPlatform(xmlReader);
// Find suppressions list from inside project element
if (xmlReader.name() == CppcheckXml::SuppressionsElementName)
if (xmlReader.name() == QString(CppcheckXml::SuppressionsElementName))
readSuppressions(xmlReader);
// Unknown function return values
if (xmlReader.name() == CppcheckXml::CheckUnknownFunctionReturn)
if (xmlReader.name() == QString(CppcheckXml::CheckUnknownFunctionReturn))
readStringList(mCheckUnknownFunctionReturn, xmlReader, CppcheckXml::Name);
// check all function parameter values
if (xmlReader.name() == Settings::SafeChecks::XmlRootName)
if (xmlReader.name() == QString(Settings::SafeChecks::XmlRootName))
safeChecks.loadFromXml(xmlReader);
// Addons
if (xmlReader.name() == CppcheckXml::AddonsElementName)
if (xmlReader.name() == QString(CppcheckXml::AddonsElementName))
readStringList(mAddons, xmlReader, CppcheckXml::AddonElementName);
// Tools
if (xmlReader.name() == CppcheckXml::ToolsElementName) {
if (xmlReader.name() == QString(CppcheckXml::ToolsElementName)) {
QStringList tools;
readStringList(tools, xmlReader, CppcheckXml::ToolElementName);
mClangAnalyzer = tools.contains(CLANG_ANALYZER);
mClangTidy = tools.contains(CLANG_TIDY);
}
if (xmlReader.name() == CppcheckXml::TagsElementName)
if (xmlReader.name() == QString(CppcheckXml::TagsElementName))
readStringList(mTags, xmlReader, CppcheckXml::TagElementName);
if (xmlReader.name() == CppcheckXml::TagWarningsElementName)
if (xmlReader.name() == QString(CppcheckXml::TagWarningsElementName))
readTagWarnings(xmlReader, xmlReader.attributes().value(QString(), CppcheckXml::TagAttributeName).toString());
if (xmlReader.name() == CppcheckXml::MaxCtuDepthElementName)
if (xmlReader.name() == QString(CppcheckXml::MaxCtuDepthElementName))
mMaxCtuDepth = readInt(xmlReader, mMaxCtuDepth);
if (xmlReader.name() == CppcheckXml::MaxTemplateRecursionElementName)
if (xmlReader.name() == QString(CppcheckXml::MaxTemplateRecursionElementName))
mMaxTemplateRecursion = readInt(xmlReader, mMaxTemplateRecursion);
// VSConfiguration
if (xmlReader.name() == CppcheckXml::VSConfigurationElementName)
if (xmlReader.name() == QString(CppcheckXml::VSConfigurationElementName))
readVsConfigurations(xmlReader);
break;
case QXmlStreamReader::EndElement:
if (xmlReader.name() == CppcheckXml::ProjectElementName)
if (xmlReader.name() == QString(CppcheckXml::ProjectElementName))
insideProject = false;
break;
@ -1094,13 +1094,13 @@ void ProjectFile::SafeChecks::loadFromXml(QXmlStreamReader &xmlReader)
switch (type) {
case QXmlStreamReader::StartElement:
++level;
if (xmlReader.name() == Settings::SafeChecks::XmlClasses)
if (xmlReader.name() == QString(Settings::SafeChecks::XmlClasses))
classes = true;
else if (xmlReader.name() == Settings::SafeChecks::XmlExternalFunctions)
else if (xmlReader.name() == QString(Settings::SafeChecks::XmlExternalFunctions))
externalFunctions = true;
else if (xmlReader.name() == Settings::SafeChecks::XmlInternalFunctions)
else if (xmlReader.name() == QString(Settings::SafeChecks::XmlInternalFunctions))
internalFunctions = true;
else if (xmlReader.name() == Settings::SafeChecks::XmlExternalVariables)
else if (xmlReader.name() == QString(Settings::SafeChecks::XmlExternalVariables))
externalVariables = true;
break;
case QXmlStreamReader::EndElement:

View File

@ -1,4 +1,4 @@
qt5_wrap_cpp(test-benchmark-simple_SRC benchmarksimple.h)
qt_wrap_cpp(test-benchmark-simple_SRC benchmarksimple.h)
add_custom_target(build-testbenchmark-simple-deps SOURCES ${test-benchmark-simple_SRC})
add_dependencies(gui-build-deps build-testbenchmark-simple-deps)
if(USE_BUNDLED_TINYXML2)
@ -12,7 +12,7 @@ add_executable(benchmark-simple
)
target_include_directories(benchmark-simple PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_compile_definitions(benchmark-simple PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(benchmark-simple Qt5::Core Qt5::Test)
target_link_libraries(benchmark-simple ${QT_CORE_LIB} ${QT_TEST_LIB})
if (HAVE_RULES)
target_link_libraries(benchmark-simple ${PCRE_LIBRARY})
endif()

View File

@ -1,4 +1,4 @@
qt5_wrap_cpp(test-cppchecklibrarydata_SRC testcppchecklibrarydata.h)
qt_wrap_cpp(test-cppchecklibrarydata_SRC testcppchecklibrarydata.h)
add_custom_target(build-cppchecklibrarydata-deps SOURCES ${test-cppchecklibrarydata_SRC})
add_dependencies(gui-build-deps build-cppchecklibrarydata-deps)
add_executable(test-cppchecklibrarydata
@ -7,4 +7,4 @@ add_executable(test-cppchecklibrarydata
${CMAKE_SOURCE_DIR}/gui/cppchecklibrarydata.cpp
)
target_include_directories(test-cppchecklibrarydata PRIVATE ${CMAKE_SOURCE_DIR}/gui)
target_link_libraries(test-cppchecklibrarydata Qt5::Core Qt5::Test)
target_link_libraries(test-cppchecklibrarydata ${QT_CORE_LIB} ${QT_TEST_LIB})

View File

@ -1,4 +1,4 @@
qt5_wrap_cpp(test-filelist_SRC testfilelist.h)
qt_wrap_cpp(test-filelist_SRC testfilelist.h)
add_custom_target(build-testfilelist-deps SOURCES ${test-filelist_SRC})
add_dependencies(gui-build-deps build-testfilelist-deps)
add_executable(test-filelist
@ -12,4 +12,4 @@ add_executable(test-filelist
)
target_include_directories(test-filelist PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/externals/simplecpp)
target_compile_definitions(test-filelist PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(test-filelist Qt5::Core Qt5::Test)
target_link_libraries(test-filelist ${QT_CORE_LIB} ${QT_TEST_LIB})

View File

@ -1,4 +1,4 @@
qt5_wrap_cpp(test-projectfile_SRC testprojectfile.h ${CMAKE_SOURCE_DIR}/gui/projectfile.h)
qt_wrap_cpp(test-projectfile_SRC testprojectfile.h ${CMAKE_SOURCE_DIR}/gui/projectfile.h)
add_custom_target(build-projectfile-deps SOURCES ${test-projectfile_SRC})
add_dependencies(gui-build-deps build-projectfile-deps)
add_executable(test-projectfile
@ -8,4 +8,4 @@ add_executable(test-projectfile
)
target_include_directories(test-projectfile PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)
target_compile_definitions(test-projectfile PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(test-projectfile Qt5::Core Qt5::Test)
target_link_libraries(test-projectfile ${QT_CORE_LIB} ${QT_TEST_LIB})

View File

@ -1,4 +1,4 @@
qt5_wrap_cpp(test-translationhandler_SRC testtranslationhandler.h ${CMAKE_SOURCE_DIR}/gui/translationhandler.h)
qt_wrap_cpp(test-translationhandler_SRC testtranslationhandler.h ${CMAKE_SOURCE_DIR}/gui/translationhandler.h)
add_custom_target(build-translationhandler-deps SOURCES ${test-translationhandler_SRC})
add_dependencies(gui-build-deps build-translationhandler-deps)
add_executable(test-translationhandler
@ -8,4 +8,4 @@ add_executable(test-translationhandler
${CMAKE_SOURCE_DIR}/gui/translationhandler.cpp
)
target_include_directories(test-translationhandler PRIVATE ${CMAKE_SOURCE_DIR}/gui)
target_link_libraries(test-translationhandler Qt5::Core Qt5::Widgets Qt5::Test)
target_link_libraries(test-translationhandler ${QT_CORE_LIB} ${QT_WIDGETS_LIB} ${QT_TEST_LIB})

View File

@ -1,4 +1,4 @@
qt5_wrap_cpp(test-xmlreportv2_SRC testxmlreportv2.h)
qt_wrap_cpp(test-xmlreportv2_SRC testxmlreportv2.h)
add_custom_target(build-xmlreportv2-deps SOURCES ${test-xmlreportv2_SRC})
add_dependencies(gui-build-deps build-xmlreportv2-deps)
if(USE_BUNDLED_TINYXML2)
@ -16,7 +16,7 @@ add_executable(test-xmlreportv2
)
target_include_directories(test-xmlreportv2 PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)
target_compile_definitions(test-xmlreportv2 PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(test-xmlreportv2 Qt5::Core Qt5::Test)
target_link_libraries(test-xmlreportv2 ${QT_CORE_LIB} ${QT_TEST_LIB})
if (HAVE_RULES)
target_link_libraries(test-xmlreportv2 ${PCRE_LIBRARY})
endif()

View File

@ -64,7 +64,7 @@ int XmlReport::determineVersion(const QString &filename)
while (!reader.atEnd()) {
switch (reader.readNext()) {
case QXmlStreamReader::StartElement:
if (reader.name() == ResultElementName) {
if (reader.name() == QString(ResultElementName)) {
QXmlStreamAttributes attribs = reader.attributes();
if (attribs.hasAttribute(QString(VersionAttribute))) {
int ver = attribs.value(QString(), VersionAttribute).toString().toInt();

View File

@ -10,7 +10,7 @@ if (BUILD_GUI AND BUILD_TESTS)
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
file(GLOB uis "*.ui")
qt5_wrap_ui(uis_hdrs ${uis})
qt_wrap_ui(uis_hdrs ${uis})
add_custom_target(triage-build-ui-deps SOURCES ${hdrs} ${uis_hdrs})
add_executable(
@ -22,7 +22,7 @@ if (BUILD_GUI AND BUILD_TESTS)
${PROJECT_SOURCE_DIR}/gui/codeeditor.cpp)
set_target_properties(triage PROPERTIES AUTOMOC ON)
target_include_directories(triage PRIVATE ${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/gui/)
target_link_libraries(triage Qt5::Core Qt5::Gui Qt5::Widgets)
target_link_libraries(triage ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB})
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0")
# Q_UNUSED() in generated code