some preparations for Qt6 support (#3777) · cppchecksolutions/cppcheck@d528555 · GitHub
Skip to content

Commit d528555

Browse files
authored
some preparations for Qt6 support (cppcheck-opensource#3777)
* findDependencies.cmake: cleaned up find_package() call for Qt * some CMake preparations for Qt6 support * some Qt6 compilation fixes
1 parent 047930f commit d528555

14 files changed

Lines changed: 94 additions & 67 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 3 additions & 0 deletions

‎cmake/findDependencies.cmake‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
if (BUILD_GUI)
2+
list(APPEND qt_components Core Gui Widgets PrintSupport LinguistTools Help)
3+
if (WITH_QCHART)
4+
list(APPEND qt_components Charts)
5+
endif()
26
if (BUILD_TESTS)
3-
if (NOT WITH_QCHART)
4-
find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help Test REQUIRED)
5-
else()
6-
find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help Test Charts REQUIRED)
7-
endif()
8-
else()
9-
if (NOT WITH_QCHART)
10-
find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help REQUIRED)
11-
else()
12-
find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport LinguistTools Help Charts REQUIRED)
13-
endif()
7+
list(APPEND qt_components Test)
148
endif()
9+
find_package(Qt5 COMPONENTS ${qt_components} REQUIRED)
1510
endif()
1611

1712
if (HAVE_RULES)

‎cmake/qtCompat.cmake‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# "versionless" Qt is not supported until 5.15 we need to use wrappers
2+
3+
function(qt_wrap_ui out)
4+
qt5_wrap_ui(_uis_hdrs ${ARGN})
5+
set("${out}" ${_uis_hdrs} PARENT_SCOPE)
6+
endfunction()
7+
8+
function(qt_add_resources out)
9+
qt5_add_resources(_resources ${ARGN})
10+
set("${out}" ${_resources} PARENT_SCOPE)
11+
endfunction()
12+
13+
function(qt_add_translation out)
14+
qt5_add_translation(_qms ${ARGN})
15+
set("${out}" ${_qms} PARENT_SCOPE)
16+
endfunction()
17+
18+
function(qt_wrap_cpp out)
19+
qt5_wrap_cpp(_sources ${ARGN})
20+
set("${out}" ${_sources} PARENT_SCOPE)
21+
endfunction()
22+
23+
set(QT_CORE_LIB Qt5::Core)
24+
set(QT_TEST_LIB Qt5::Test)
25+
set(QT_WIDGETS_LIB Qt5::Widgets)
26+
set(QT_GUI_LIB Qt5::Gui)
27+
set(QT_HELP_LIB Qt5::Help)
28+
set(QT_PRINTSUPPORT_LIB Qt5::PrintSupport)
29+
set(QT_CHARTS_LIB Qt5::Charts)

‎gui/CMakeLists.txt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ if (BUILD_GUI)
1212
file(GLOB srcs "*.cpp")
1313
file(GLOB uis "*.ui")
1414
file(GLOB tss "*.ts")
15-
QT5_WRAP_UI(uis_hdrs ${uis})
16-
QT5_ADD_RESOURCES(resources "gui.qrc")
17-
QT5_ADD_TRANSLATION(qms ${tss})
15+
QT_WRAP_UI(uis_hdrs ${uis})
16+
QT_ADD_RESOURCES(resources "gui.qrc")
17+
QT_ADD_TRANSLATION(qms ${tss})
1818
list(APPEND cppcheck-gui-deps ${hdrs} ${uis_hdrs} ${resources} ${qms} )
1919
add_custom_target(gui-build-deps SOURCES ${cppcheck-gui-deps})
2020

@@ -38,10 +38,10 @@ if (BUILD_GUI)
3838
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
3939
target_link_libraries(cppcheck-gui tinyxml2)
4040
endif()
41-
target_link_libraries(cppcheck-gui Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport Qt5::Help)
41+
target_link_libraries(cppcheck-gui ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB} ${QT_PRINTSUPPORT_LIB} ${QT_HELP_LIB})
4242
if(WITH_QCHART)
4343
target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART)
44-
target_link_libraries(cppcheck-gui Qt5::Charts)
44+
target_link_libraries(cppcheck-gui ${QT_CHARTS_LIB})
4545
endif()
4646
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
4747
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0")

‎gui/cppchecklibrarydata.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,12 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader)
331331
mandatoryAttibuteMissing(xmlReader, "ext");
332332
}
333333
if (xmlReader.attributes().hasAttribute("aftercode")) {
334-
markup.afterCode = (xmlReader.attributes().value("aftercode") == "true") ? true : false;
334+
markup.afterCode = (xmlReader.attributes().value("aftercode") == QString("true")) ? true : false;
335335
} else {
336336
mandatoryAttibuteMissing(xmlReader, "aftercode");
337337
}
338338
if (xmlReader.attributes().hasAttribute("reporterrors")) {
339-
markup.reportErrors = (xmlReader.attributes().value("reporterrors") == "true") ? true : false;
339+
markup.reportErrors = (xmlReader.attributes().value("reporterrors") == QString("true")) ? true : false;
340340
} else {
341341
mandatoryAttibuteMissing(xmlReader, "reporterrors");
342342
}

‎gui/projectfile.cpp‎

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ bool ProjectFile::read(const QString &filename)
9292
while (!xmlReader.atEnd()) {
9393
switch (xmlReader.readNext()) {
9494
case QXmlStreamReader::StartElement:
95-
if (xmlReader.name() == CppcheckXml::ProjectElementName) {
95+
if (xmlReader.name() == QString(CppcheckXml::ProjectElementName)) {
9696
insideProject = true;
9797
projectTagFound = true;
9898
break;
@@ -101,114 +101,114 @@ bool ProjectFile::read(const QString &filename)
101101
break;
102102

103103
// Read root path from inside project element
104-
if (xmlReader.name() == CppcheckXml::RootPathName)
104+
if (xmlReader.name() == QString(CppcheckXml::RootPathName))
105105
readRootPath(xmlReader);
106106

107107
// Read root path from inside project element
108-
if (xmlReader.name() == CppcheckXml::BuildDirElementName)
108+
if (xmlReader.name() == QString(CppcheckXml::BuildDirElementName))
109109
readBuildDir(xmlReader);
110110

111111
// Find paths to check from inside project element
112-
if (xmlReader.name() == CppcheckXml::PathsElementName)
112+
if (xmlReader.name() == QString(CppcheckXml::PathsElementName))
113113
readCheckPaths(xmlReader);
114114

115-
if (xmlReader.name() == CppcheckXml::ImportProjectElementName)
115+
if (xmlReader.name() == QString(CppcheckXml::ImportProjectElementName))
116116
readImportProject(xmlReader);
117117

118-
if (xmlReader.name() == CppcheckXml::AnalyzeAllVsConfigsElementName)
118+
if (xmlReader.name() == QString(CppcheckXml::AnalyzeAllVsConfigsElementName))
119119
mAnalyzeAllVsConfigs = readBool(xmlReader);
120120

121-
if (xmlReader.name() == CppcheckXml::Parser)
121+
if (xmlReader.name() == QString(CppcheckXml::Parser))
122122
clangParser = true;
123123

124-
if (xmlReader.name() == CppcheckXml::BugHunting)
124+
if (xmlReader.name() == QString(CppcheckXml::BugHunting))
125125
bugHunting = true;
126126

127-
if (xmlReader.name() == CppcheckXml::CheckHeadersElementName)
127+
if (xmlReader.name() == QString(CppcheckXml::CheckHeadersElementName))
128128
mCheckHeaders = readBool(xmlReader);
129129

130-
if (xmlReader.name() == CppcheckXml::CheckUnusedTemplatesElementName)
130+
if (xmlReader.name() == QString(CppcheckXml::CheckUnusedTemplatesElementName))
131131
mCheckUnusedTemplates = readBool(xmlReader);
132132

133133
// Find include directory from inside project element
134-
if (xmlReader.name() == CppcheckXml::IncludeDirElementName)
134+
if (xmlReader.name() == QString(CppcheckXml::IncludeDirElementName))
135135
readIncludeDirs(xmlReader);
136136

137137
// Find preprocessor define from inside project element
138-
if (xmlReader.name() == CppcheckXml::DefinesElementName)
138+
if (xmlReader.name() == QString(CppcheckXml::DefinesElementName))
139139
readDefines(xmlReader);
140140

141141
// Find preprocessor define from inside project element
142-
if (xmlReader.name() == CppcheckXml::UndefinesElementName)
142+
if (xmlReader.name() == QString(CppcheckXml::UndefinesElementName))
143143
readStringList(mUndefines, xmlReader, CppcheckXml::UndefineName);
144144

145145
// Find exclude list from inside project element
146-
if (xmlReader.name() == CppcheckXml::ExcludeElementName)
146+
if (xmlReader.name() == QString(CppcheckXml::ExcludeElementName))
147147
readExcludes(xmlReader);
148148

149149
// Find ignore list from inside project element
150150
// These are read for compatibility
151-
if (xmlReader.name() == CppcheckXml::IgnoreElementName)
151+
if (xmlReader.name() == QString(CppcheckXml::IgnoreElementName))
152152
readExcludes(xmlReader);
153153

154154
// Function contracts
155-
if (xmlReader.name() == CppcheckXml::FunctionContracts)
155+
if (xmlReader.name() == QString(CppcheckXml::FunctionContracts))
156156
readFunctionContracts(xmlReader);
157157

158158
// Variable constraints
159-
if (xmlReader.name() == CppcheckXml::VariableContractsElementName)
159+
if (xmlReader.name() == QString(CppcheckXml::VariableContractsElementName))
160160
readVariableContracts(xmlReader);
161161

162162
// Find libraries list from inside project element
163-
if (xmlReader.name() == CppcheckXml::LibrariesElementName)
163+
if (xmlReader.name() == QString(CppcheckXml::LibrariesElementName))
164164
readStringList(mLibraries, xmlReader, CppcheckXml::LibraryElementName);
165165

166-
if (xmlReader.name() == CppcheckXml::PlatformElementName)
166+
if (xmlReader.name() == QString(CppcheckXml::PlatformElementName))
167167
readPlatform(xmlReader);
168168

169169
// Find suppressions list from inside project element
170-
if (xmlReader.name() == CppcheckXml::SuppressionsElementName)
170+
if (xmlReader.name() == QString(CppcheckXml::SuppressionsElementName))
171171
readSuppressions(xmlReader);
172172

173173
// Unknown function return values
174-
if (xmlReader.name() == CppcheckXml::CheckUnknownFunctionReturn)
174+
if (xmlReader.name() == QString(CppcheckXml::CheckUnknownFunctionReturn))
175175
readStringList(mCheckUnknownFunctionReturn, xmlReader, CppcheckXml::Name);
176176

177177
// check all function parameter values
178-
if (xmlReader.name() == Settings::SafeChecks::XmlRootName)
178+
if (xmlReader.name() == QString(Settings::SafeChecks::XmlRootName))
179179
safeChecks.loadFromXml(xmlReader);
180180

181181
// Addons
182-
if (xmlReader.name() == CppcheckXml::AddonsElementName)
182+
if (xmlReader.name() == QString(CppcheckXml::AddonsElementName))
183183
readStringList(mAddons, xmlReader, CppcheckXml::AddonElementName);
184184

185185
// Tools
186-
if (xmlReader.name() == CppcheckXml::ToolsElementName) {
186+
if (xmlReader.name() == QString(CppcheckXml::ToolsElementName)) {
187187
QStringList tools;
188188
readStringList(tools, xmlReader, CppcheckXml::ToolElementName);
189189
mClangAnalyzer = tools.contains(CLANG_ANALYZER);
190190
mClangTidy = tools.contains(CLANG_TIDY);
191191
}
192192

193-
if (xmlReader.name() == CppcheckXml::TagsElementName)
193+
if (xmlReader.name() == QString(CppcheckXml::TagsElementName))
194194
readStringList(mTags, xmlReader, CppcheckXml::TagElementName);
195195

196-
if (xmlReader.name() == CppcheckXml::TagWarningsElementName)
196+
if (xmlReader.name() == QString(CppcheckXml::TagWarningsElementName))
197197
readTagWarnings(xmlReader, xmlReader.attributes().value(QString(), CppcheckXml::TagAttributeName).toString());
198198

199-
if (xmlReader.name() == CppcheckXml::MaxCtuDepthElementName)
199+
if (xmlReader.name() == QString(CppcheckXml::MaxCtuDepthElementName))
200200
mMaxCtuDepth = readInt(xmlReader, mMaxCtuDepth);
201201

202-
if (xmlReader.name() == CppcheckXml::MaxTemplateRecursionElementName)
202+
if (xmlReader.name() == QString(CppcheckXml::MaxTemplateRecursionElementName))
203203
mMaxTemplateRecursion = readInt(xmlReader, mMaxTemplateRecursion);
204204

205205
// VSConfiguration
206-
if (xmlReader.name() == CppcheckXml::VSConfigurationElementName)
206+
if (xmlReader.name() == QString(CppcheckXml::VSConfigurationElementName))
207207
readVsConfigurations(xmlReader);
208208
break;
209209

210210
case QXmlStreamReader::EndElement:
211-
if (xmlReader.name() == CppcheckXml::ProjectElementName)
211+
if (xmlReader.name() == QString(CppcheckXml::ProjectElementName))
212212
insideProject = false;
213213
break;
214214

@@ -1094,13 +1094,13 @@ void ProjectFile::SafeChecks::loadFromXml(QXmlStreamReader &xmlReader)
10941094
switch (type) {
10951095
case QXmlStreamReader::StartElement:
10961096
++level;
1097-
if (xmlReader.name() == Settings::SafeChecks::XmlClasses)
1097+
if (xmlReader.name() == QString(Settings::SafeChecks::XmlClasses))
10981098
classes = true;
1099-
else if (xmlReader.name() == Settings::SafeChecks::XmlExternalFunctions)
1099+
else if (xmlReader.name() == QString(Settings::SafeChecks::XmlExternalFunctions))
11001100
externalFunctions = true;
1101-
else if (xmlReader.name() == Settings::SafeChecks::XmlInternalFunctions)
1101+
else if (xmlReader.name() == QString(Settings::SafeChecks::XmlInternalFunctions))
11021102
internalFunctions = true;
1103-
else if (xmlReader.name() == Settings::SafeChecks::XmlExternalVariables)
1103+
else if (xmlReader.name() == QString(Settings::SafeChecks::XmlExternalVariables))
11041104
externalVariables = true;
11051105
break;
11061106
case QXmlStreamReader::EndElement:

‎gui/test/benchmark/simple/CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
qt5_wrap_cpp(test-benchmark-simple_SRC benchmarksimple.h)
1+
qt_wrap_cpp(test-benchmark-simple_SRC benchmarksimple.h)
22
add_custom_target(build-testbenchmark-simple-deps SOURCES ${test-benchmark-simple_SRC})
33
add_dependencies(gui-build-deps build-testbenchmark-simple-deps)
44
if(USE_BUNDLED_TINYXML2)
@@ -12,7 +12,7 @@ add_executable(benchmark-simple
1212
)
1313
target_include_directories(benchmark-simple PRIVATE ${CMAKE_SOURCE_DIR}/lib)
1414
target_compile_definitions(benchmark-simple PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
15-
target_link_libraries(benchmark-simple Qt5::Core Qt5::Test)
15+
target_link_libraries(benchmark-simple ${QT_CORE_LIB} ${QT_TEST_LIB})
1616
if (HAVE_RULES)
1717
target_link_libraries(benchmark-simple ${PCRE_LIBRARY})
1818
endif()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
qt5_wrap_cpp(test-cppchecklibrarydata_SRC testcppchecklibrarydata.h)
1+
qt_wrap_cpp(test-cppchecklibrarydata_SRC testcppchecklibrarydata.h)
22
add_custom_target(build-cppchecklibrarydata-deps SOURCES ${test-cppchecklibrarydata_SRC})
33
add_dependencies(gui-build-deps build-cppchecklibrarydata-deps)
44
add_executable(test-cppchecklibrarydata
@@ -7,4 +7,4 @@ add_executable(test-cppchecklibrarydata
77
${CMAKE_SOURCE_DIR}/gui/cppchecklibrarydata.cpp
88
)
99
target_include_directories(test-cppchecklibrarydata PRIVATE ${CMAKE_SOURCE_DIR}/gui)
10-
target_link_libraries(test-cppchecklibrarydata Qt5::Core Qt5::Test)
10+
target_link_libraries(test-cppchecklibrarydata ${QT_CORE_LIB} ${QT_TEST_LIB})

‎gui/test/filelist/CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
qt5_wrap_cpp(test-filelist_SRC testfilelist.h)
1+
qt_wrap_cpp(test-filelist_SRC testfilelist.h)
22
add_custom_target(build-testfilelist-deps SOURCES ${test-filelist_SRC})
33
add_dependencies(gui-build-deps build-testfilelist-deps)
44
add_executable(test-filelist
@@ -12,4 +12,4 @@ add_executable(test-filelist
1212
)
1313
target_include_directories(test-filelist PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/externals/simplecpp)
1414
target_compile_definitions(test-filelist PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
15-
target_link_libraries(test-filelist Qt5::Core Qt5::Test)
15+
target_link_libraries(test-filelist ${QT_CORE_LIB} ${QT_TEST_LIB})
Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)