CMake: Fix handling of static dependencies that have spaces in path

The absolute paths of certain static dependencies can have spaces in
them. The _qt5_$${CMAKE_MODULE_NAME}_process_prl_file fails to handle
this, and simply replaces all spaces with semicolons, which obviously
breaks the list of dependencies, and a consuming application fails to
link with a message like:

LINK : fatal error LNK1181: cannot open input file 'C:\Program.obj'

This change partially restores the functionality that was added in
102e1822ffcdc9954d3c698f863734a8083e349c specifically the part
that changes qmake to export an additional variable
QMAKE_PRL_LIBS_FOR_CMAKE. This variable has the same content as
QMAKE_PRL_LIBS except it uses a semicolon as a separator, so that
CMake can correctly parse the separate lib entries.

This is much cleaner than trying to parse the original QMAKE_PRL_LIBS
variable with a complicated regular expression.

Amends eda28621f6c1a68774719f382be53ec109123b18.

Task-number: QTBUG-38913
Change-Id: I1d18fb779606505bc92320d8ce13232c7022e212
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Alexandru Croitor 2019-06-20 11:46:49 +02:00
parent 78d67d17a6
commit 6ad08b9cad
2 changed files with 18 additions and 3 deletions

View File

@ -56,9 +56,16 @@ function(_qt5_$${CMAKE_MODULE_NAME}_process_prl_file prl_file_location Configura
get_filename_component(_qt5_install_libs \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/lib\" ABSOLUTE)
if(EXISTS \"${prl_file_location}\")
file(STRINGS \"${prl_file_location}\" _prl_strings REGEX \"QMAKE_PRL_LIBS[ \\t]*=\")
string(REGEX REPLACE \"QMAKE_PRL_LIBS[ \\t]*=[ \\t]*([^\\n]*)\" \"\\\\1\" _static_depends ${_prl_strings})
string(REGEX REPLACE \"[ \\t]+\" \";\" _static_depends ${_static_depends})
file(STRINGS \"${prl_file_location}\" _prl_strings REGEX \"QMAKE_PRL_LIBS_FOR_CMAKE[ \\t]*=\")
# file(STRINGS) replaces all semicolons read from the file with backslash semicolons.
# We need to do a reverse transformation in CMake. For that we replace all backslash
# semicolons with just semicolons, but due to the qmake substitution feature
# creating this file, we need to double the amount of backslashes, so the final file
# should have three backslashes and one semicolon.
string(REGEX REPLACE \"\\\\\\;\" \";\" _prl_strings \"${_prl_strings}\")
string(REGEX REPLACE \"QMAKE_PRL_LIBS_FOR_CMAKE[ \\t]*=[ \\t]*([^\\n]*)\" \"\\\\1\" _static_depends \"${_prl_strings}\")
string(REGEX REPLACE \"[ \\t]+\" \";\" _standard_libraries \"${CMAKE_CXX_STANDARD_LIBRARIES}\")
set(_search_paths)
string(REPLACE \"\\$\\$[QT_INSTALL_LIBS]\" \"${_qt5_install_libs}\" _static_depends \"${_static_depends}\")

View File

@ -1023,6 +1023,14 @@ MakefileGenerator::writePrlFile(QTextStream &t)
for (ProStringList::Iterator it = libs.begin(); it != libs.end(); ++it)
t << qv(project->values((*it).toKey()));
t << endl;
t << "QMAKE_PRL_LIBS_FOR_CMAKE = ";
QString sep;
for (ProStringList::Iterator it = libs.begin(); it != libs.end(); ++it) {
t << sep << project->values((*it).toKey()).join(';').replace('\\', "\\\\");
sep = ';';
}
t << endl;
}
}