[CMake] Dependency scanning for non-supported languages?

Talin viridia at gmail.com
Wed Dec 30 15:30:30 EST 2009


That is more along the lines of what I was looking for. Thanks! :)

One further question: Using the technique you describe, the dependency file
will need to be regenerated each time a source file changes - i.e. if I add
a new "import" statement to a source file, the list of dependencies will
change, which will require the dependency file to be rebuilt. Can that
rebuild happen as part of the normal build, or can that only be done at
CMake time?

More generally, I know of two different approaches to generating dependency
lists: pre-build and post-build. With pre-build, you have some scanner that
parses the source before compilation and spits out a list of dependencies.
With post-build, the compiler emits a list of the dependencies that were
actually used during compilation. This file is used during the next build.
If the dependency file is missing (which it will be the first time), then
the target is built unconditionally. Post-build is significantly easier to
implement when you have languages such as Java which allows for implicit
imports or when you have a language that requires a very smart scanner to
determine in advance what files will be needed.

On Wed, Dec 30, 2009 at 11:21 AM, Alan W. Irwin
<irwin at beluga.phys.uvic.ca>wrote:

> On 2009-12-30 10:42-0800 Talin wrote:
>
>  I guess what I am asking is - if I modified my build script to generate a
>> text file (Makefile, CMakeLists.txt or whatever) containing the
>> dependencies, would CMake be able to use it? I know that with GNU
>> makefiles
>> there is a way to generate additional makefiles as part of the build
>> process
>> (although it is rather complex and clumsy), I wonder if CMake can support
>> something similar?
>>
>
> Sorry for entering this conversation late, but I want to make the point
> that
> you can essentially do anything related to builds that you like with CMake.
> I presume (since your language is not officially supported by CMake) that
> you are building libraries and executables with add_custom_command, and you
> want some way to get the right file dependencies in the DEPENDS of that
> add_custom_command.
>
> Here is one way to do that.
>
> At cmake time, you run execute_process to generate the file with
> lists of dependent files, then use file(READ...) and string parsing to
> create a CMake list variable containing those file dependencies.  Then
> use that variable as the object of the add_custom_command DEPENDS, and
> you are done.
>
> Another way to do this that skips the file(READ...) and string parsing
> steps
> is to have your external dependency generation script that you execute with
> execute_process create a file that contains the single line of CMake logic,
>
> set(LANGUAGE_DEPENDS depend1 depend2 ... dependn)
>
> You then simply include that file and use
>
> add_custom_command(... DEPENDS ${LANGUAGE_DEPENDS})
>
> I hope these ideas help.
>
> Alan
> __________________________
> Alan W. Irwin
>
> Astronomical research affiliation with Department of Physics and Astronomy,
> University of Victoria (astrowww.phys.uvic.ca).
>
> Programming affiliations with the FreeEOS equation-of-state implementation
> for stellar interiors (freeeos.sf.net); PLplot scientific plotting
> software
> package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
> Linux Links project (loll.sf.net); and the Linux Brochure Project
> (lbproject.sf.net).
> __________________________
>
> Linux-powered Science
> __________________________
>



-- 
-- Talin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091230/4f4cebba/attachment-0001.htm>


More information about the CMake mailing list