Skip to content

Commit 473efa0

Browse files
author
feihong
committed
adapting more Qt header file include paths
1 parent f474b3f commit 473efa0

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

generator/CMakeLists.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,19 @@ foreach(wrapper IN LISTS wrapper_list)
5858
set(PYTHONQT_WRAPPER_${WRAPPER}_SOURCES ${PYTHONQT_WRAPPER_${WRAPPER}_SOURCES} PARENT_SCOPE)
5959
endforeach()
6060

61-
get_target_property(_qt_include_dirs Qt${QT_VERSION_MAJOR}::Core INTERFACE_INCLUDE_DIRECTORIES)
62-
foreach(_qt_include_dir IN LISTS _qt_include_dirs)
63-
get_filename_component(_qt_install_prefix "${_qt_include_dir}" PATH)
64-
if (EXISTS "${_qt_install_prefix}/include/QtCore")
65-
set(_qt_dir "${_qt_install_prefix}")
61+
get_target_property(_qtcore_include_dirs Qt${QT_VERSION_MAJOR}::Core INTERFACE_INCLUDE_DIRECTORIES)
62+
foreach(_qtcore_include_dir IN LISTS _qtcore_include_dirs)
63+
if (EXISTS "${_qtcore_include_dir}/QtCore")
64+
set(_qt_include_prefix "${_qtcore_include_dir}")
6665
break()
6766
endif()
6867
endforeach()
6968

7069
add_custom_command(OUTPUT ${PYTHONQT_WRAPPER_SOURCES}
71-
COMMAND ${CMAKE_COMMAND} -E env QTDIR=${_qt_dir} --modify ${LIBRARY_SEARCH_PATH}=path_list_prepend:$<TARGET_FILE_DIR:Qt${QT_VERSION_MAJOR}::Widgets> $<TARGET_FILE:${PROJECT_NAME}>
72-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} #[[$<TARGET_FILE_DIR:${PROJECT_NAME}>]]
70+
COMMAND ${CMAKE_COMMAND} -E env --modify ${LIBRARY_SEARCH_PATH}=path_list_prepend:$<TARGET_FILE_DIR:Qt${QT_VERSION_MAJOR}::Widgets>
71+
$<TARGET_FILE:${PROJECT_NAME}> --qt-include-prefix="${_qt_include_prefix}"
72+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
7373
DEPENDS ${PROJECT_NAME}
74-
VERBATIM
7574
)
7675

7776
set_source_files_properties(${PYTHONQT_WRAPPER_SOURCES} PROPERTIES
@@ -82,5 +81,3 @@ set_source_files_properties(${PYTHONQT_WRAPPER_SOURCES} PROPERTIES
8281
add_custom_target(PythonQtWrapper
8382
DEPENDS ${PROJECT_NAME} ${PYTHONQT_WRAPPER_SOURCES}
8483
)
85-
86-
message("_qt5Core_install_prefix " ${_qt5Core_install_prefix})

generator/main.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void displayHelp(GeneratorSet *generatorSet);
6161
namespace
6262
{
6363

64-
QStringList getIncludeDirectories(const QString &commandLineIncludes)
64+
QStringList getIncludeDirectories(const QString &commandLineIncludes, const QString &qtIncludePrefix)
6565
{
6666
QStringList includes;
6767
includes << QString(".");
@@ -121,11 +121,20 @@ namespace
121121
includes << (qtdir + "/QtOpenGL");
122122
includes << qtdir;
123123
}
124+
if (!qtIncludePrefix.isEmpty() && QFile::exists(qtIncludePrefix)) {
125+
std::cout << "qt include prefix: " << qtIncludePrefix.toLocal8Bit().constData() << std::endl;
126+
includes << (qtIncludePrefix + "/QtXml");
127+
includes << (qtIncludePrefix + "/QtNetwork");
128+
includes << (qtIncludePrefix + "/QtCore");
129+
includes << (qtIncludePrefix + "/QtGui");
130+
includes << (qtIncludePrefix + "/QtOpenGL");
131+
includes << qtIncludePrefix;
132+
}
124133
return includes;
125134
}
126135

127136
bool
128-
preprocess(const QString &sourceFile, const QString &targetFile, const QString &commandLineIncludes = QString())
137+
preprocess(const QString &sourceFile, const QString &targetFile, const QString &commandLineIncludes = QString(), const QString &qtIncludPrefix = {})
129138
{
130139
rpp::pp_environment env;
131140
rpp::pp preprocess(env);
@@ -146,7 +155,7 @@ namespace
146155
preprocess.operator()(ba.constData(), ba.constData() + ba.size(), null_out);
147156

148157
foreach(QString
149-
include, getIncludeDirectories(commandLineIncludes)) {
158+
include, getIncludeDirectories(commandLineIncludes, qtIncludPrefix)) {
150159
preprocess.push_include_path(QDir::toNativeSeparators(include).toStdString());
151160
}
152161

@@ -177,10 +186,10 @@ namespace
177186
return true;
178187
}
179188

180-
unsigned int getQtVersion(const QString &commandLineIncludes)
189+
unsigned int getQtVersion(const QString &commandLineIncludes, const QString &qtIncludPrefix = {})
181190
{
182191
QRegularExpression re("#define\\s+QTCORE_VERSION\\s+0x([0-9a-f]+)", QRegularExpression::CaseInsensitiveOption);
183-
for (const QString &includeDir: getIncludeDirectories(commandLineIncludes))
192+
for (const QString &includeDir: getIncludeDirectories(commandLineIncludes, qtIncludPrefix))
184193
{
185194
QFileInfo fi(QDir(includeDir), "qtcoreversion.h");
186195
if (fi.exists())
@@ -315,7 +324,7 @@ int main(int argc, char *argv[])
315324

316325
if (!qtVersion) {
317326
printf("Trying to determine Qt version...\n");
318-
qtVersion = getQtVersion(args.value("include-paths"));
327+
qtVersion = getQtVersion(args.value("include-paths"), args.value("qt-include-prefix"));
319328
if (!qtVersion)
320329
{
321330
fprintf(stderr, "Aborting\n"); // the error message was printed by getQtVersion
@@ -337,7 +346,7 @@ int main(int argc, char *argv[])
337346
printf("PreProcessing - Generate [%s] using [%s] and include-paths [%s]\n",
338347
qPrintable(pp_file), qPrintable(fileName), qPrintable(args.value("include-paths")));
339348
ReportHandler::setContext("Preprocess");
340-
if (!preprocess(fileName, pp_file, args.value("include-paths"))) {
349+
if (!preprocess(fileName, pp_file, args.value("include-paths"), args.value("qt-include-prefix"))) {
341350
fprintf(stderr, "Preprocessor failed on file: '%s'\n", qPrintable(fileName));
342351
return 1;
343352
}

0 commit comments

Comments
 (0)