[CMake] ADD_CUSTOM_COMMAND() without anything else: dangling dependency?

joerg.faschingbauer at aon.at joerg.faschingbauer at aon.at
Sun Mar 14 07:54:06 EDT 2010


Hi,

I use ADD_CUSTOM_COMMAND() to generate a header file in one directory.
That header file is included from a source file in another directory,
which is then aggregated into a library. The dependency is stated via
an OBJECT_DEPENDS property. Like,

in one directory 'generated-headers',

    ADD_CUSTOM_COMMAND(
        OUTPUT generated-header.h
        COMMAND touch generated-header.h
        )

and, in the library directory,

    INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/generated-headers)
    ADD_LIBRARY(
        library
        library.c
    )
    SET_PROPERTY(
        SOURCE library.c
        PROPERTY OBJECT_DEPENDS ${CMAKE_BINARY_DIR}/generated-headers/generated-header.h)

CMake doesn't seem to generate any targets for the generated-headers
directory, resulting in

Scanning dependencies of target library
make[2]: *** No rule to make target `generated-headers/generated-header.h', needed by `library/CMakeFiles/library.dir/library.c.o'.  Stop.

What am I doing wrong?

What I want to express with the above construct is that library.c.o
depends on the header which is not yet there, and thus has to be
generated before library.c.o is built. This is what 'make' understands
when it descends into the 'library' directory. However the dependency
appears to point to nowhere.

(See the problematic package in the attached problem.tar.bz2 file.)

Everything's ok if I put a dummy file and a library in the
'generated-headers' directory, like

    ADD_CUSTOM_COMMAND(
        OUTPUT generated-header.h dummy.c
        COMMAND touch generated-header.h dummy.c
        )
    
    ADD_LIBRARY(
        generated
        generated-header.h
        dummy.c
    )

(See the ok package in the attached ok.tar.bz2 file.)

Tested with both CMake 2.8.0 as downloaded from cmake.org, and
2.6-patch 4 (?) as available under Gentoo.

Thanks in advance,
Joerg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: problem.tar.bz2
Type: application/octet-stream
Size: 570 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100314/76ed237a/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ok.tar.bz2
Type: application/octet-stream
Size: 566 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100314/76ed237a/attachment-0003.obj>


More information about the CMake mailing list