diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b78262cb..a65938d2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake index cbd50f19b..31b58a54e 100644 --- a/cmake/findDependencies.cmake +++ b/cmake/findDependencies.cmake @@ -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) diff --git a/cmake/qtCompat.cmake b/cmake/qtCompat.cmake new file mode 100644 index 000000000..68eee2d7a --- /dev/null +++ b/cmake/qtCompat.cmake @@ -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) \ No newline at end of file diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 213ad5918..fb2fe938c 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -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") diff --git a/gui/cppchecklibrarydata.cpp b/gui/cppchecklibrarydata.cpp index 68534e311..c3fa58069 100644 --- a/gui/cppchecklibrarydata.cpp +++ b/gui/cppchecklibrarydata.cpp @@ -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"); } diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index 15ce2324b..04077ff9b 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -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: diff --git a/gui/test/benchmark/simple/CMakeLists.txt b/gui/test/benchmark/simple/CMakeLists.txt index 036b4e3cb..6bc1222cc 100644 --- a/gui/test/benchmark/simple/CMakeLists.txt +++ b/gui/test/benchmark/simple/CMakeLists.txt @@ -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() diff --git a/gui/test/cppchecklibrarydata/CMakeLists.txt b/gui/test/cppchecklibrarydata/CMakeLists.txt index 419e643c5..9569e8017 100644 --- a/gui/test/cppchecklibrarydata/CMakeLists.txt +++ b/gui/test/cppchecklibrarydata/CMakeLists.txt @@ -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) \ No newline at end of file +target_link_libraries(test-cppchecklibrarydata ${QT_CORE_LIB} ${QT_TEST_LIB}) \ No newline at end of file diff --git a/gui/test/filelist/CMakeLists.txt b/gui/test/filelist/CMakeLists.txt index 883840557..315e9954c 100644 --- a/gui/test/filelist/CMakeLists.txt +++ b/gui/test/filelist/CMakeLists.txt @@ -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) \ No newline at end of file +target_link_libraries(test-filelist ${QT_CORE_LIB} ${QT_TEST_LIB}) \ No newline at end of file diff --git a/gui/test/projectfile/CMakeLists.txt b/gui/test/projectfile/CMakeLists.txt index 8fd101356..3947aef51 100644 --- a/gui/test/projectfile/CMakeLists.txt +++ b/gui/test/projectfile/CMakeLists.txt @@ -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) \ No newline at end of file +target_link_libraries(test-projectfile ${QT_CORE_LIB} ${QT_TEST_LIB}) \ No newline at end of file diff --git a/gui/test/translationhandler/CMakeLists.txt b/gui/test/translationhandler/CMakeLists.txt index 1cd8d33d4..0aadbe702 100644 --- a/gui/test/translationhandler/CMakeLists.txt +++ b/gui/test/translationhandler/CMakeLists.txt @@ -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) \ No newline at end of file +target_link_libraries(test-translationhandler ${QT_CORE_LIB} ${QT_WIDGETS_LIB} ${QT_TEST_LIB}) \ No newline at end of file diff --git a/gui/test/xmlreportv2/CMakeLists.txt b/gui/test/xmlreportv2/CMakeLists.txt index b09cc432e..c34537fdf 100644 --- a/gui/test/xmlreportv2/CMakeLists.txt +++ b/gui/test/xmlreportv2/CMakeLists.txt @@ -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() diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index 44b5c46e7..351121954 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -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(); diff --git a/tools/triage/CMakeLists.txt b/tools/triage/CMakeLists.txt index 0486d56d4..286b43ec7 100644 --- a/tools/triage/CMakeLists.txt +++ b/tools/triage/CMakeLists.txt @@ -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