[CMake] Dependency scanning for non-supported languages?

Talin viridia at gmail.com
Thu Dec 31 03:08:22 EST 2009


I got it working, thanks!

Turns out that whenever my dependency generator changes the deps file, CMake
notices this fact (because the file is included) and does a reconfigure
anyway. So all I have to do is "make" and everything works. Sweet!

In case you are interested, here's what I did:

The dependency file generator creates a dependency entry for each target in
the library:

set(TART_TESTING_ASSERTS_DEPS

 "/home/talin/Projects/tart/trunk/stdlib/tart/core/AssertionFailureException.tart"
    "/home/talin/Projects/tart/trunk/stdlib/tart/core/Debug.tart"
    "/home/talin/Projects/tart/trunk/stdlib/tart/core/Iterable.tart"
    "/home/talin/Projects/tart/trunk/stdlib/tart/core/String.tart"
)

set(TART_TESTING_TEST_DEPS
    "/home/talin/Projects/tart/trunk/libtesting/tart/testing/Asserts.tart"
    "/home/talin/Projects/tart/trunk/stdlib/tart/core/Debug.tart"
    "/home/talin/Projects/tart/trunk/stdlib/tart/core/Throwable.tart"
    "/home/talin/Projects/tart/trunk/stdlib/tart/reflect/ComplexType.tart"
    "/home/talin/Projects/tart/trunk/stdlib/tart/reflect/Method.tart"
    "/home/talin/Projects/tart/trunk/stdlib/tart/reflect/Type.tart"
)


The name of the variable is generated by taking the target name, replacing
all '/' with '_', and then converting to upper case. So
"tart/testing/Test.tart" becomes "TART_TESTING_TEST_DEPS".

I then import the dependency file in my CMakeLists.txt:

include(${CMAKE_CURRENT_BINARY_DIR}/libtesting.deps OPTIONAL)


For each target, I generate the name of the variable that contains the deps
for that target, using the same algorithm as used in the generator program:

# Generate the deps variable name
string(REGEX REPLACE ".tart\$" "" DEPS_NAME "${SRC_FILE}")
string(TOUPPER "${DEPS_NAME}" DEPS_NAME)
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" DEPS_NAME "${DEPS_NAME}")


And then use recursive variable expansion to make the deps name a dependency
of the target:

DEPENDS "${SRC_FILE}" tartc ${${DEPS_NAME}_DEPS}


Finally, at the end of the CMakeLists.txt, I invoke the dependency generator
program to generate the new deps file for the next build:

# Generate dependency info
add_custom_command(
    OUTPUT libtesting.deps
    COMMAND gendeps -o libtesting.deps ${TESTING_BC_FILES}
    DEPENDS ${TESTING_BC_FILES} gendeps
    COMMENT "Generating dependencies for libtesting.bc")


CMake will notice that the date stamp has changed and reconfigure next time
I run make. One final touch I want to make is to not change the date stamp
on the output file unless the contents have changed.

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

> On 2009-12-30 12:30-0800 Talin wrote:
>
>  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?
>>
>
> Good question.  The dependency information is used by CMake (at CMake time)
> to configure a custom command to be run at build time with the correct
> dependencies.  Thus, the answer to your question must be that build time is
> too late to collect the dependency information used by CMake.  Instead, you
> must do that at CMake time like I outlined.
>
>
> 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/20091231/c2a03343/attachment.htm>


More information about the CMake mailing list