CMAKE_AUTORCC: *_Info.json contains (incorrect) absolute source-dir paths when doing out-of-tree builds
Whilst working on the open-source project webcamoid and configuring cmake
to do out-of-tree builds including QT translations (here showing our change to put *.qm
binary translation files under the build directory:
$ git diff StandAlone/Translations/CMakeLists.txt
diff --git a/StandAlone/Translations/CMakeLists.txt b/StandAlone/Translations/CMakeLists.txt
index 1a6219ca..7260659b 100644
--- a/StandAlone/Translations/CMakeLists.txt
+++ b/StandAlone/Translations/CMakeLists.txt
@@ -80,7 +80,7 @@ if (LRELEASE_TOOL)
add_custom_target(tranlation_${LANG}_qm ALL
${LRELEASE_TOOL} -removeidentical
-compress ${CMAKE_SOURCE_DIR}/StandAlone/share/ts/${LANG}.ts
- -qm ${CMAKE_SOURCE_DIR}/StandAlone/share/ts/${LANG}.qm
+ -qm ${CMAKE_BINARY_DIR}/StandAlone/share/ts/${LANG}.qm
DEPENDS tranlation_${LANG}_ts
BYPRODUCTS StandAlone/share/ts/${LANG}.qm
VERBATIM)
I found that, when processing QT's translation files via rcc
and the CMAKE_AUTORCC
target, the auto-generated *_Info.json
contained incorrect absolute paths for the INPUT
file list for the built QT binary translation files (*.qm
). The paths are to the source directory not the build directory, despite the build product *.qm
files being in the correct out-of-tree build directory.
This is on Debian 11 Bullseye with cmake version 3.18.4
but I do not see any changes in the current cmake
development code.
I've tracked it down to the *_Info.json
INPUT
being written with absolute paths from cmQtAutoGen::RccLister::list()
in Source/cmQtAutoGen.cxx
where it converts relative paths to absolute:
// Convert relative paths to absolute paths
for (std::string& entry : files) {
entry = cmSystemTools::CollapseFullPath(entry, fileDir);
}
return true;
}
These paths are written to the *_Info.json
by cmQtAutoGenInitializer::SetupWriteRccInfo()
with:
info.SetArray("INPUTS", qrc.Resources);
info.Save(qrc.InfoFile);
}
Resulting, in my case, with (fragment shown) ../builds/webcamoid/StandAlone/src/CMakeFiles/StandAlone_autogen.dir/AutoRcc_translations_Q6JQXYBHPE_Info.json
:
{
"BUILD_DIR" : "/srv/NAS/Sunny/SourceCode/builds/webcamoid/StandAlone/src/StandAlone_autogen",
"CMAKE_BINARY_DIR" : "/srv/NAS/Sunny/SourceCode/builds/webcamoid",
"CMAKE_CURRENT_BINARY_DIR" : "/srv/NAS/Sunny/SourceCode/builds/webcamoid/StandAlone/src",
"CMAKE_CURRENT_SOURCE_DIR" : "/srv/NAS/Sunny/SourceCode/webcamoid/StandAlone/src",
"CMAKE_SOURCE_DIR" : "/srv/NAS/Sunny/SourceCode/webcamoid",
"INCLUDE_DIR" : "/srv/NAS/Sunny/SourceCode/builds/webcamoid/StandAlone/src/StandAlone_autogen/include",
"INPUTS" :
[
"/srv/NAS/Sunny/SourceCode/webcamoid/StandAlone/share/ts/tr.qm",
"/srv/NAS/Sunny/SourceCode/webcamoid/StandAlone/share/ts/it.qm",
...
whereas the build product *.qm
files are actually under the appropriate out-of-tree build directory under the CMAKE_BINARY_DIR
prefix:
SourceCode/webcamoid$ find . ../builds/webcamoid/ -name '*.qm'
../builds/webcamoid/StandAlone/share/ts/si.qm
../builds/webcamoid/StandAlone/share/ts/hu.qm
...
In our case the obvious solution would be to not call cmSystemTools::CollapseFullPath()
and to prefix the paths with CMAKE_SOURCE_DIR
or CMAKE_BINARY_DIR
if they're different before the write info.SetArray("INPUTS", qrc.Resources);
.
I'm not sure if that would break other project layouts though.
I'm currently hoping to add a workaround with a custom action in our project to correct these paths once the *_Info.json
has been written.