diff options
author | Brad King <brad.king@kitware.com> | 2021-06-08 16:45:20 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-06-09 14:09:58 (GMT) |
commit | 526e2ef71c5b797818bbf232e21d0152a3938197 (patch) | |
tree | cbf166ad88496f7d0b070e7bc1f38bba073f4356 /Templates | |
parent | 794ad78abb8da517e59e25ea38f5c1edced1cf46 (diff) | |
download | CMake-526e2ef71c5b797818bbf232e21d0152a3938197.zip CMake-526e2ef71c5b797818bbf232e21d0152a3938197.tar.gz CMake-526e2ef71c5b797818bbf232e21d0152a3938197.tar.bz2 |
VS: Add support for add_custom_command DEPFILE
Transform the depfile into MSBuild `AdditionalInputs` content. Add
MSBuild Targets to update `AdditionalInputs` and the `.tlog` files for
future builds without actually modifying the `.vcxproj` file.
Fixes: #20286
Diffstat (limited to 'Templates')
-rw-r--r-- | Templates/MSBuild/CustomBuildDepFile.targets | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Templates/MSBuild/CustomBuildDepFile.targets b/Templates/MSBuild/CustomBuildDepFile.targets new file mode 100644 index 0000000..2387ab5 --- /dev/null +++ b/Templates/MSBuild/CustomBuildDepFile.targets @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <!-- Update AdditionalInputs with depfile-discovered inputs. --> + <Target Name="CMakeCustomBuildDepFileAdditionalInputs" BeforeTargets="CustomBuild" Condition="'@(CustomBuild)' != ''"> + <ItemGroup> + <!-- Save original AdditionalInputs generated by CMake. --> + <CustomBuild> + <CMakeAdditionalInputs>%(CustomBuild.AdditionalInputs)</CMakeAdditionalInputs> + </CustomBuild> + <!-- Read depfile-discovered inputs. --> + <CustomBuild Condition="Exists('%(CustomBuild.DepFileAdditionalInputsFile)')"> + <DepFileAdditionalInputs>$([System.IO.File]::ReadAllText('%(CustomBuild.DepFileAdditionalInputsFile)').TrimEnd())</DepFileAdditionalInputs> + </CustomBuild> + <!-- Add depfile-discovered inputs to AdditionalInputs. --> + <CustomBuild Condition="'%(CustomBuild.DepFileAdditionalInputs)' != ''"> + <AdditionalInputs Condition="'%(CustomBuild.AdditionalInputs)' == ''">%(CustomBuild.DepFileAdditionalInputs)</AdditionalInputs> + <AdditionalInputs Condition="'%(CustomBuild.AdditionalInputs)' != ''">%(CustomBuild.AdditionalInputs);%(CustomBuild.DepFileAdditionalInputs)</AdditionalInputs> + </CustomBuild> + </ItemGroup> + </Target> + + <!-- Update the tracking log with depfile-discovered inputs. --> + <Target Name="CMakeCustomBuildDepFileTrackingLog" AfterTargets="CustomBuild" Condition="'@(CustomBuild)' != ''"> + <!-- Compute the tracking log content for each CustomBuild item individually. --> + <ItemGroup> + <!-- Read depfile-discovered inputs. --> + <CustomBuild Condition="Exists('%(CustomBuild.DepFileAdditionalInputsFile)')"> + <DepFileAdditionalInputs>$([System.IO.File]::ReadAllText('%(CustomBuild.DepFileAdditionalInputsFile)').TrimEnd())</DepFileAdditionalInputs> + </CustomBuild> + <!-- Generate tracking log representation of all inputs. --> + <CustomBuild> + <ReadTLog>^%(CustomBuild.Identity)
</ReadTLog> + </CustomBuild> + <CustomBuild Condition="'%(CustomBuild.CMakeAdditionalInputs)' != ''"> + <ReadTLog>%(ReadTLog)$([System.String]::Copy('%(CustomBuild.CMakeAdditionalInputs)').Trim(';').Replace(';', '
'))
</ReadTLog> + </CustomBuild> + <CustomBuild Condition="'%(CustomBuild.DepFileAdditionalInputs)' != ''"> + <ReadTLog>%(ReadTLog)$([System.String]::Copy('%(CustomBuild.DepFileAdditionalInputs)').Trim(';').Replace(';', '
'))
</ReadTLog> + </CustomBuild> + </ItemGroup> + <!-- Compute the combined tracking log for all CustomBuild items together. --> + <PropertyGroup> + <CustomBuildReadTLog>@(CustomBuild->'%(ReadTLog)','')</CustomBuildReadTLog> + </PropertyGroup> + <!-- Replace the combined tracking log on disk. --> + <WriteLinesToFile File="$(TLogLocation)CustomBuild.read.1.tlog" Overwrite="true" Lines="$(CustomBuildReadTLog.ToUpper())" /> + </Target> +</Project> |