[CMake] Dependency checker

Michael Wild themiwi at gmail.com
Fri Sep 10 05:19:59 EDT 2010


On 9. Sep, 2010, at 17:43 , KSpam wrote:

> Benjamin,
> 
>> Thank you for your quick answer. I had a quick glance - what I don't
>> quite understand is how can I integrate this into my custom cmake
>> script? I have a ADD_CUSTOM_COMMAND, and in the depends I need this list
>> of dependent files (the generated files, not the xsd's themselves).
>> 
>> If you could shed some light on this, that would be very helpful
> 
> I have done something similar (with a different file type).  The low tech 
> solution is to use "file(READ ${fileName} fileContents)" to get the contents of 
> the file, and then search through the file contents for dependencies.  Another 
> option that might work would be "file(STRINGS" with the REGEX option in order 
> to reduce the resulting matches.
> 
> You can then use "string(REGEX MATCH" to search through the file contents for 
> the dependency match and then add the dependency to "DEPENDS" in your 
> add_custom_command.
> 
> This approach does not read the XML, but it should work as long as you can 
> create a reasonable regular expression to find the dependencies in the file.
> 
> A more complicated option would be to create a separate application that reads 
> the file and prints a list of dependencies.  You could then wrap that 
> executable in a custom command and parse the results into your dependency 
> list.
> 
> Respectfully,
> Justin


There are a two problems with this approach though:

- Dependency checking isn't re-run if a file changes, only if CMake re-runs
- You can't safely use regexes with XML: (see http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454)

Another approach would be to skip dependency checking altogether and always recompile all of the input files whenever one of them changes. Of course, the usefulness of this depends on how slow the process is and on how many files you expect there to be.

Michael

--
There is always a well-known solution to every human problem -- neat, plausible, and wrong.
H. L. Mencken

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100910/d6f5912e/attachment.pgp>


More information about the CMake mailing list