aboutsummaryrefslogtreecommitdiffstats
path: root/src/qtmsbuild/qt_vars.targets
blob: a41b3ba73ffe56bb4393ea73f76172d12f9f2c92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<?xml version="1.0" encoding="utf-8"?>
<!--
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt VS Tools.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
-->
<!--
///////////////////////////////////////////////////////////////////////////////////////////////////
// Read Qt Build Variables
// -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup Condition="'$(QtVsProjectSettings)' == 'true'">
    <QtOuterBuildDependsOn>QtVarsPrepare;QtVars;$(QtDependsOn)</QtOuterBuildDependsOn>
    <CleanDependsOn>$(CleanDependsOn);QtVarsClean</CleanDependsOn>
  </PropertyGroup>

  <!--
  /////////////////////////////////////////////////////////////////////////////////////////////////
  /// TARGET QtVars
  /////////////////////////////////////////////////////////////////////////////////////////////////
  // Call qmake with generated .pro file to export Qt variables into MSBuild .props file
  // -->
  <Target
    Name="QtVars"
    Condition="'$(QtVsProjectSettings)' == 'true'"
    DependsOnTargets="QtMocInit;QtUicInit"
    Inputs="$(MSBuildProjectFile)" Outputs="$(QtVarsFilePath)">

    <CreateProperty
      Condition="Exists('$(QtInstall)')"
      Value="$(QtInstall)">
      <Output TaskParameter="ValueSetByTask" PropertyName="QtInstallDir" />
    </CreateProperty>
    <CreateProperty
      Condition="!Exists('$(QtInstall)') AND '$(QtInstall)' != ''"
      Value="HKEY_CURRENT_USER\Software\Digia\Versions\$(QtInstall)">
      <Output TaskParameter="ValueSetByTask" PropertyName="QtInstallRegKey" />
    </CreateProperty>
    <CreateProperty
      Condition="!Exists('$(QtInstall)') AND '$(QtInstall)' != ''"
      Value="$([MSBuild]::GetRegistryValue('$(QtInstallRegKey)','InstallDir'))">
      <Output TaskParameter="ValueSetByTask" PropertyName="QtInstallRegDir" />
    </CreateProperty>
    <CreateProperty
      Condition="!Exists('$(QtInstall)') AND '$(QtInstall)' != ''"
      Value="$(QtInstallRegDir)">
      <Output TaskParameter="ValueSetByTask" PropertyName="QtInstallDir" />
    </CreateProperty>
    <CreateProperty
      Condition="!$([System.IO.Path]::IsPathRooted('$(QtPathBinaries)'))"
      Value="$(QtInstallDir)\$(QtPathBinaries)">
      <Output TaskParameter="ValueSetByTask" PropertyName="QtToolsPath" />
    </CreateProperty>
    <CreateProperty
      Condition="$([System.IO.Path]::IsPathRooted('$(QtPathBinaries)'))"
      Value="$(QtPathBinaries)">
      <Output TaskParameter="ValueSetByTask" PropertyName="QtToolsPath" />
    </CreateProperty>

    <!--// Modules and additional .pro file lines -->
    <ItemGroup>
      <QtModuleList Include="$(QtModules)"/>
      <QMakeCodeLine Include="$(QMakeCodeLines)"/>
    </ItemGroup>

    <!--// Generate INCLUDEPATH value -->
    <ItemGroup>
      <QtIncludesList Include="$(QtHeaderSearchPath)"/>
      <QtIncludes Include=
"$([System.IO.Path]::Combine($(QtInstallDir),$([System.String]::Copy('%(QtIncludesList.Identity)'))))"/>
      <QtIncludesList Remove="@(QtIncludesList)"/>
    </ItemGroup>
    <PropertyGroup>
      <QtIncludes>@(QtIncludes->'&quot;%(Identity)&quot;', ' ')</QtIncludes>
    </PropertyGroup>

    <!--// Generate LIBS value -->
    <ItemGroup>
      <QtLibsList Include="$(QtLibrarySearchPath)"/>
      <QtLibs Include=
"$([System.IO.Path]::Combine($(QtInstallDir),$([System.String]::Copy('%(QtLibsList.Identity)'))))"/>
      <QtLibsList Include="@(QtLibsList)"/>
    </ItemGroup>
    <PropertyGroup>
      <QtLibs>@(QtLibs->'&quot;-L%(Identity)&quot;', ' ')</QtLibs>
    </PropertyGroup>

    <Message
      Importance="high"
      Text="Reading Qt configuration ($(QtToolsPath)\qmake.exe)"/>

    <PropertyGroup>

      <!--// .pro file configuration -->
      <QtVarsProFileConfig
        Condition="'$(Configuration)' == 'Debug'">
        CONFIG -= debug release debug_and_release
        CONFIG += debug
      </QtVarsProFileConfig>
      <QtVarsProFileConfig
        Condition="'$(Configuration)' != 'Debug'">
        CONFIG -= debug release debug_and_release
        CONFIG += release
      </QtVarsProFileConfig>

      <!--// .pro file input parameters -->
      <QtVarsProFileInput>
        <!--
# Selected Qt modules -->
        QT += @(QtModuleList->'%(Identity)', ' ')
        <!--
# Custom additional .pro file code (from property page) -->
        @(QMakeCodeLine->'%(Identity)','%0D%0A')
      </QtVarsProFileInput>
      <!--
# Custom additional header search paths (from property page) -->
      <QtVarsProFileInput Condition="'$(QtHeaderSearchPath)' != ''">
        $(QtVarsProFileInput)
        INCLUDEPATH += $(QtIncludes)
      </QtVarsProFileInput>
      <!--
# Custom additional library search paths (from property page) -->
      <QtVarsProFileInput Condition="'$(QtLibrarySearchPath)' != ''">
        $(QtVarsProFileInput)
        LIBS += $(QtLibs)
      </QtVarsProFileInput>
      <!--
# Undef UNICODE macro if project is configured with multi-byte char set -->
      <QtVarsProFileInput Condition="'$(CharacterSet)' == 'MultiByte'">
        $(QtVarsProFileInput)
        DEFINES -= UNICODE _UNICODE
      </QtVarsProFileInput>
    </PropertyGroup>

    <!--// Write .pro file to temp path -->
    <RemoveDir
      Directories="$(QtVarsWorkDir)"/>
    <MakeDir
      Directories="$(QtVarsWorkDir)"/>
    <WriteLinesToFile
      File="$(QtVarsWorkDir)\qtvars.pro"
      Lines="$(QtVarsProFileConfig)
            ;$(QtVarsProFileInput)"/>

    <!--// Write start of Qt vars data file:
        //  * Open property group tag -->
    <PropertyGroup>
      <!--
######## BEGIN generated XML (.props) ##############################################################
##    -->
      <QtVarsDataFileText>
        <![CDATA[
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
        ]]>
      </QtVarsDataFileText>
      <!--
##
######## END generated XML (.props) ################################################################
      -->
    </PropertyGroup>
    <WriteLinesToFile File="$(QtVarsWorkPath)" Lines="$(QtVarsDataFileText)" Overwrite="true"/>

    <!--// Ensure C++ compiler in PATH -->
    <Exec Command="WHERE /Q cl.exe"
      WorkingDirectory="$(QtVarsWorkDir)" IgnoreExitCode="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorLevel"/>
    </Exec>
    <SetEnv Condition="'$(ErrorLevel)' != '0'"
      Name="PATH" Prefix="true" Value="$(ExecutablePath)"/>

    <!--// Run qmake: convert Makefile vars to .props (XML) file -->
    <PropertyGroup>
      <Cmd><![CDATA[("$(QtToolsPath)\qmake.exe") 1> qtvars.log 2>&1]]></Cmd>
    </PropertyGroup>
    <Exec WorkingDirectory="$(QtVarsWorkDir)" IgnoreExitCode="true" Command="$(Cmd)">
      <Output TaskParameter="ExitCode" PropertyName="ErrorLevel"/>
    </Exec>

    <!--// Check qmake result -->
    <PropertyGroup Condition="'$(ErrorLevel)' != '0' OR !Exists('$(QtVarsWorkDir)\Makefile')">
      <QMakeError>true</QMakeError>
    </PropertyGroup>

    <!--// Get qmake console output -->
    <ItemGroup>
      <QMakeError Include="($(QtToolsPath)\qmake.exe)"/>
      <QMakeError Include="%24PWD=$(QtVarsWorkDir)"/>
    </ItemGroup>
    <ReadLinesFromFile
        File="$(QtVarsWorkDir)\qtvars.log">
      <Output TaskParameter="Lines" ItemName="QMakeError"/>
    </ReadLinesFromFile>
    <ItemGroup>
      <QMakeError
        Condition="$([System.String]::Copy('%(Identity)').StartsWith('Info: creating stash file'))"
        Remove="@(QMakeError)"/>
      <QMakeError
        Condition="!Exists('$(QtVarsWorkDir)\Makefile')"
        Include="Error creating Makefile"/>
    </ItemGroup>

    <!--// If error, show qmake console output and stop build -->
    <Error
      Condition="'$(QMakeError)' == 'true'"
      File="$(MSBuildProjectFile)"
      Text="ERROR running qmake%0D%0Aqmake: @(QMakeError->'%(Identity)','%0D%0Aqmake: ')%0D%0A"/>
    <Message
      Importance="high"
      Condition="'$(QMakeError)' != 'true' AND '$(QtVarsDebug)' == 'true'"
      Text="qmake: @(QMakeError->'%(Identity)','%0D%0Aqmake: ')"/>

    <!--// Parse variable definition expressions -->
    <ParseVarDefs
      Condition="'$(QtVars)' != ''" QtVars="$(QtVars)">
      <Output TaskParameter="OutVarDefs" ItemName="QtVarDef"/>
    </ParseVarDefs>

    <!--// Read variables from Makefile -->
    <GetVarsFromMakefile
      Makefile="$(QtVarsWorkDir)\Makefile" VarDefs="@(QtVarDef)">
      <Output TaskParameter="OutVars" ItemName="QtVar"/>
    </GetVarsFromMakefile>

    <!--// Write variables as MSBuild properties to .props file -->
    <PropertyGroup>
      <QtMakefileVars Condition="'@(QtVar)' != ''">
        <![CDATA[@(QtVar->'<Qt_%(Identity)_>%(Value)</Qt_%(Identity)_>','%0D%0A')]]>
      </QtMakefileVars>
    </PropertyGroup>
    <WriteLinesToFile Condition="'$(QtMakefileVars)' != ''"
      File="$(QtVarsWorkPath)" Lines="$([System.String]::Copy($(QtMakefileVars)))"/>

    <!--// Qt settings list for backup -->
    <ItemGroup>
      <QtInstall Include="$(QtInstall)"/>
      <QtModules Include="$(QtModules)"/>
      <QtPathBinaries Include="$(QtPathBinaries)"/>
      <QtPathLibraryExecutables Include="$(QtPathLibraryExecutables)"/>
      <QtHeaderSearchPath Include="$(QtHeaderSearchPath)"/>
      <QtLibrarySearchPath Include="$(QtLibrarySearchPath)"/>
      <QtVariables Include="$(QtVars)"/>
      <QMakeCodeLines Include="$(QMakeCodeLines)"/>
    </ItemGroup>

    <!--// Write end of .props (XML) file
        //  * Add Qt tools output directories to include path
        //  * Save settings backup
        //  * Close property group tag
        //  * Create QtVar items to export Qt variables to the calling instance of MSBuild
        //  * Close project tag -->
    <PropertyGroup>
      <!--
######## BEGIN generated XML (.props) ##############################################################
##    -->
      <QtVarsDataFileText>
        <![CDATA[
    <Qt_INCLUDEPATH_
      >%24(Qt_INCLUDEPATH_)%3B@(QtIncludePath->Distinct(),'%3B')</Qt_INCLUDEPATH_>
    <QtBkup_QtInstall
      >@(QtInstall,'%3B')</QtBkup_QtInstall>
    <QtBkup_QtModules
      >@(QtModules,'%3B')</QtBkup_QtModules>
    <QtBkup_QtPathBinaries
      >@(QtPathBinaries,'%3B')</QtBkup_QtPathBinaries>
    <QtBkup_QtPathLibraryExecutables
      >@(QtPathLibraryExecutables,'%3B')</QtBkup_QtPathLibraryExecutables>
    <QtBkup_QtHeaderSearchPath
      >@(QtHeaderSearchPath,'%3B')</QtBkup_QtHeaderSearchPath>
    <QtBkup_QtLibrarySearchPath
      >@(QtLibrarySearchPath,'%3B')</QtBkup_QtLibrarySearchPath>
    <QtBkup_QtVars
      >@(QtVariables,'%3B')</QtBkup_QtVars>
    <QtBkup_QMakeCodeLines
      >@(QMakeCodeLines,'%3B')</QtBkup_QMakeCodeLines>
  </PropertyGroup>
</Project>
        ]]>
      </QtVarsDataFileText>
      <!--
##
######## END generated XML (.props) ################################################################
      -->
    </PropertyGroup>
    <WriteLinesToFile File="$(QtVarsWorkPath)" Lines="$(QtVarsDataFileText)"/>

    <!--// Create $(QtVarsOutputDir) -->
    <MakeDir Directories="$(QtVarsOutputDir)"/>

    <!--// Copy generated .props to $(QtVarsOutputDir) -->
    <Delete
      Condition="'$(ErrorLevel)' == '0'"
      Files="$(QtVarsFilePath)"/>
    <Copy
      Condition="'$(ErrorLevel)' == '0'"
      SourceFiles="$(QtVarsWorkPath)" DestinationFiles="$(QtVarsFilePath)"/>

    <!--// Copy generated qtvars_plugin_import.cpp to $(QtVarsOutputDir) -->
    <Delete
      Condition="'$(ErrorLevel)' == '0'"
      Files="$(QtVarsOutputDir)\qtvars_plugin_import.cpp"/>
    <Copy
      Condition="'$(ErrorLevel)' == '0' AND Exists('$(QtVarsWorkDir)\qtvars_plugin_import.cpp')"
      SourceFiles="$(QtVarsWorkDir)\qtvars_plugin_import.cpp"
      DestinationFiles="$(QtVarsOutputDir)\qtvars_plugin_import.cpp"/>

    <!--// Remove work dir -->
    <RemoveDir
      Condition="'$(QtVarsDebug)' != 'true'"
      Directories="$(QtVarsWorkDir)"/>

    <!--// In design-time, copy generated .props to randomly named file -->
    <PropertyGroup>
      <QtVarsDesignTimeNew
        Condition="'$(ErrorLevel)' == '0' AND '$(QtVSToolsBuild)' == 'true'"
        >$([System.IO.Path]::Combine('$(TEMP)','$([System.IO.Path]::GetRandomFileName()).designtime.props'))
      </QtVarsDesignTimeNew>
    </PropertyGroup>
    <Copy
      Condition="'$(ErrorLevel)' == '0' AND '$(QtVSToolsBuild)' == 'true'"
      SourceFiles="$(QtVarsFilePath)" DestinationFiles="$(QtVarsDesignTimeNew)"/>
    <WriteLinesToFile
      Condition="'$(ErrorLevel)' == '0' AND '$(QtVSToolsBuild)' == 'true'"
      File="$(QtVarsIndexPathDesignTime)" Overwrite="true" Lines="$(QtVarsDesignTimeNew)"/>

    <!--// Clean-up -->
    <ItemGroup>
      <QtModuleList Remove="@(QtModuleList)"/>
      <QMakeCodeLine Remove="@(QMakeCodeLine)"/>
      <QtIncludes Remove="@(QtIncludes)"/>
      <QtLibs Remove="@(QtLibs)"/>
      <QMakeError Remove="@(QMakeError)"/>
      <QtInstall Remove="@(QtInstall)"/>
      <QtModules Remove="@(QtModules)"/>
      <QtPathBinaries Remove="@(QtPathBinaries)"/>
      <QtPathLibraryExecutables Remove="@(QtPathLibraryExecutables)"/>
      <QtHeaderSearchPath Remove="@(QtHeaderSearchPath)"/>
      <QtLibrarySearchPath Remove="@(QtLibrarySearchPath)"/>
      <QtVariables Remove="@(QtVariables)"/>
      <QMakeCodeLines Remove="@(QMakeCodeLines)"/>
      <QtVarDef Remove="@(QtVarDef)"/>
      <QtVar Remove="@(QtVar)"/>
    </ItemGroup>
    <PropertyGroup>
      <QtIncludes/>
      <QtLibs/>
      <QtVarsProFileConfig/>
      <QtVarsProFileInput/>
      <QtVarsDataFileText/>
      <Cmd/>
      <QtMakefileVars/>
    </PropertyGroup>
  </Target>

  <!--
  /////////////////////////////////////////////////////////////////////////////////////////////////
  /// TARGET QtVarsPrepare
  /////////////////////////////////////////////////////////////////////////////////////////////////
  // Force QtVars target to run when Qt settings have changed
  // -->
  <Target Name="QtVarsPrepare" BeforeTargets="QtVars" Condition="Exists('$(QtVarsFilePath)')">
    <Delete Files="$(QtVarsFilePath)" Condition="Exists('$(QtVarsFilePath)')
        AND '$(QtBkup_QtInstall)' != '$(QtInstall)'" />
    <Delete Files="$(QtVarsFilePath)" Condition="Exists('$(QtVarsFilePath)')
        AND '$(QtBkup_QtModules)' != '$(QtModules)'" />
    <Delete Files="$(QtVarsFilePath)" Condition="Exists('$(QtVarsFilePath)')
        AND '$(QtBkup_QtPathBinaries)' != '$(QtPathBinaries)'" />
    <Delete Files="$(QtVarsFilePath)" Condition="Exists('$(QtVarsFilePath)')
        AND '$(QtBkup_QtPathLibraryExecutables)' != '$(QtPathLibraryExecutables)'" />
    <Delete Files="$(QtVarsFilePath)" Condition="Exists('$(QtVarsFilePath)')
        AND '$(QtBkup_QtHeaderSearchPath)' != '$(QtHeaderSearchPath)'" />
    <Delete Files="$(QtVarsFilePath)" Condition="Exists('$(QtVarsFilePath)')
        AND '$(QtBkup_QtLibrarySearchPath)' != '$(QtLibrarySearchPath)'" />
    <Delete Files="$(QtVarsFilePath)" Condition="Exists('$(QtVarsFilePath)')
        AND '$(QtBkup_QtVars)' != '$(QtVars)'" />
    <Delete Files="$(QtVarsFilePath)" Condition="Exists('$(QtVarsFilePath)')
        AND '$(QtBkup_QMakeCodeLines)' != '$(QMakeCodeLines)'" />
  </Target>

  <!--
  /////////////////////////////////////////////////////////////////////////////////////////////////
  /// TARGET QtVarsClean
  /////////////////////////////////////////////////////////////////////////////////////////////////
  // Delete all files generated by the QtVars target
  // -->
  <Target Name="QtVarsClean">
    <RemoveDir Directories="$(QtVarsOutputDir)"/>
  </Target>

  <!--
  /////////////////////////////////////////////////////////////////////////////////////////////////
  /// TARGET QtVarsDesignTime
  /////////////////////////////////////////////////////////////////////////////////////////////////
  // Force QtVars target to run (called when project properties change)
  // -->
  <Target Name="QtVarsDesignTime">
    <CallTarget Targets="QtVarsClean"/>
    <CallTarget Targets="QtVars"/>
  </Target>

</Project>