4

Similar to the C# answer HERE I want to create a custom target to run before CLCompile (which I have already working) but that doesn't run if CLCompile will be skipped due to all targets being up to date. I have searched but cannot find what I need to test.

Would it be something like Inputs="@(CLCompile)" ?

As an alternative simply replicating the Visual Studio fast-up-to-date-check would work for me, if I can figure out how to create a task to do that I can run my task if anything at all is out of date...

Community
  • 1
  • 1
Akuma
  • 551
  • 1
  • 5
  • 21
  • 1
    `CLCompile` uses special technique called tracking to figure out if any sources need to be rebuilt. CLCompile is *never* skipped (as long as there are source files, indeed), it is always run and lets the `CL` task decide what files to compile. Also, it is not possible to tell in advance whether a file *will be* recompiled without replicating all `CL` task logic. Do you want to relax your requirements to run a target *after* CLCompile if it in fact compiled any files? This is doable but not easy and ugly because of the way some .target files are written. Also specify your VS version please. – kkm inactive - support strike Sep 11 '15 at 21:15
  • My specific need is auto versioning so has to be done up front before compilation takes place. However I have set it up using a header file which I edit using some C# code in a custom build step and that edit is happening every build which of course then results in a compile being needed even if it otherwise wasn't. Hence I am trying to prevent my custom build step from running unless a compile will take place. in the linked question the task pre-conditions were replicated to control exactly this, is CL task that hard to copy? Does it run once per file in your source (we have 1000+)? – Akuma Sep 14 '15 at 08:17
  • My back-up plan is to simply do an SVN log check to see if any source mods have taken place and pass in a flag to control my custom task execution but it's a shame there isn't an equivalent C++ solution to the linked solution. – Akuma Sep 14 '15 at 08:18
  • I understand the idea: if files *will* be recompiled, then change some "version" reflected in e.g. the final DLL. I am not exactly sure what do you what do you want to do when "versioning"--changing source (C/C++) files? resources? setting version in compiler switches? It seems to me that your best bet would be to put the changing stuff into a separate source (e. g. verison.c or version.rc), and then exclude this source file from dependencies. It will change every time "versioning" happens, but will not cause a CL recompile. Would this work? – kkm inactive - support strike Sep 14 '15 at 17:35
  • 1
    That is what I did up to not including the exclusion (good idea thanks). So now it seems updating the version.h file doesn't result in a rebuild BUT the code that updates the version.h file (which includes an SVN commit of the change) still runs every time. So although my build is now more efficient it is still running my task every time. I could perhaps separate out the SVN task and conditionally run that if a build has taken place but I can't seem to get that working either :( – Akuma Sep 18 '15 at 13:42
  • Update, the 'Exclude Directories' property only seems to prevent Visual Studio 2013 from rebuilding if version.h changed. MSBUILD still seems to be rebuilding :( – Akuma Sep 18 '15 at 14:12
  • you are on the right track. MSBuild and VS should not be different. Make sure you augment the property correctly, and put your version.h into a separate untracked directory. Verify it is not in .tlog's. Also, it is perhaps a good idea to *not* check it in. Regenerate version.h every time, do not include it in project, and let the CL task decide whether to build or not based on other changes. To figure out if build had in fact happened, the CL task outputs a couple properties, but you need to redefine CLCompile of your own, since standard .target files ignore this output. – kkm inactive - support strike Sep 18 '15 at 20:18
  • The properties are `ITaskItem[] SourcesCompiled` which lists files in fact compiled, and `bool SkippedExecution` which will be set to "false" if something *may* have been in fact compiled. This is undocumented, and I know that because I used tracking in our own compiling tools. `msbuild /pp:` is your best friend. Look where ` – kkm inactive - support strike Sep 18 '15 at 20:24
  • Thanks for your help, I'll certainly look into /pp: but it does seem this is getting more complicated than it needs to be (and certainly a lot more complicated than the .Net equivalent). Since I am already gathering change logs from svn in a pre-build script I may as well use that to determine if the project code path has changed and simply set a flag to drive my custom task. – Akuma Sep 21 '15 at 08:27

0 Answers0