From 6a77aa5ee036621b1f79827edce481eafe20d29f Mon Sep 17 00:00:00 2001 From: Miguel Costa Date: Mon, 8 Jul 2019 14:50:29 +0200 Subject: Use Qt (qmake) variables in VS projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Values in project property pages can now reference Qt/qmake variables, using the syntax $(Qt__), where is the name of a Qt variable (e.g. $(Qt_INCLUDEPATH_) ). To extract the variable values, a qmake project (.pro file) is generated and processed ahead of the VS project build. The qmake processing will generate a MSBuild properties file containing the Qt variables definitions to import in the VS project. Change-Id: I51572bd3798533d305ee6464044a8fe3504aa115 Reviewed-by: Oliver Wolff Reviewed-by: Jörg Bornemann --- src/qtmsbuild/qt.props | 42 +++++ src/qtmsbuild/qt.targets | 1 + src/qtmsbuild/qt_vars.targets | 337 +++++++++++++++++++++++++++++++++++++++++ src/qtvstools/QtVsTools.csproj | 6 + 4 files changed, 386 insertions(+) create mode 100644 src/qtmsbuild/qt_vars.targets diff --git a/src/qtmsbuild/qt.props b/src/qtmsbuild/qt.props index 4f7fa0d5..08f42d6c 100644 --- a/src/qtmsbuild/qt.props +++ b/src/qtmsbuild/qt.props @@ -83,6 +83,48 @@ $(QtInstallDir) + + + + DEFINES;INCLUDEPATH;LIBS + + + $([System.IO.Path]::Combine( + '$(TEMP)', '$([System.IO.Path]::GetRandomFileName())'))\ + $([System.IO.Path]::Combine('$(ProjectDir)', '$(IntDir)')) + qtvars_$(Platform)_$(Configuration) + $(QtVarsFileNameWithoutExt).props + $(QtVarsWorkDir)$(QtVarsFileName) + $(QtVarsOutputDir)$(QtVarsFileName) + + + + + + + + + $(Qt_DEFINES_);%(PreprocessorDefinitions) + $(Qt_INCLUDEPATH_);%(AdditionalIncludeDirectories) + + + $(Qt_LIBS_);%(AdditionalDependencies) + + + + + + + + QtVars;$(QtDependsOn) + + + + + + + + + + QtSkipBuild;$(QtSkipBuildTargets) + @(QtModuleList->'%(Identity)', ' ') + @(QtVariableList->'%(Identity)', ' ') + + + + + + + + + + + + + + + + + + + + + + + + + + + + CONFIG -= debug release debug_and_release + CONFIG += debug + + + CONFIG -= debug release debug_and_release + CONFIG += release + + + + + + fileName = "qtvars_$(Platform)_$(Configuration).props" + + modules = $(QtModuleNames) + + varNames = $(QtVarNames) + + @(QMakeCodeLine->'%(Identity)','%0D%0A') + + + + + + NUL)" + qtvars.target = qtvars + qtvars.commands = CMD /V:ON /C \ + \"@ECHO OFF &\ + SET VALUE= &\ + (FOR %%x IN (%24(LIBS)) DO (\ + SET y=%%x&\ + IF NOT \"!y:~0,9!\"==\"/LIBPATH:\"\ + SET VALUE=!y!%3B!VALUE!& $$nop \ + ))&\ + SET PROP=^!VALUE:~0,-2!^&\ + ECHO !PROP!>>$$fileName&\" + QMAKE_EXTRA_TARGETS += qtvars +} + +## Append Qt variables to .props (XML) file +# +for (varName, $$list($$sorted(varNames))) { + propName = "Qt_$${varName}_" + text = "<$${propName}>"$$formatMsBuildString($$eval($$varName))"" + write_file($$fileName, text, append) +} + ]]> + + + + + + + + + + + + + + + + $(QtInstall)|$(QtModuleNames) + ]]> + + + + + + + + + qtvars.log 2>&1]]> + + + + + + + + + + + + + + + + + + + + + + @(QtVarProp->'%24(%(Identity))', '%0D%0A') + + + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/qtvstools/QtVsTools.csproj b/src/qtvstools/QtVsTools.csproj index d75c8d43..2134d88a 100644 --- a/src/qtvstools/QtVsTools.csproj +++ b/src/qtvstools/QtVsTools.csproj @@ -564,6 +564,12 @@ Always true + + QtMsBuild\qt_vars.targets + Designer + Always + true +