[CMake] Bug? add_custom_command() ignores head file outputs

Adam B adamb at videx.com
Fri Aug 24 16:26:31 EDT 2012


On 08/24/2012 11:09 AM, Andreas Pakulat wrote:
> Hi,
>
> On Fri, Aug 24, 2012 at 7:27 PM, Adam B<adamb at videx.com>  wrote:
>> Hello all,
>>
>> I'm relatively new to CMake but I've encountered some unexpected behavior.
>> Perhaps it's by design or perhaps it's a bug - you tell me.  The short story
>> is this:
> It is a bug, but not in CMake, its in your cmake code.
>
>> It appears that add_custom_command() is ignored if the only OUTPUT is a C
>> header file (.h).  The generated makefiles do not include the custom
>> command.  However, if I also list a C source file (.c) as a second output,
>> the makefiles get the command.
> If you look at the add_custom_command documentation you'll notice that
> it says "if a target defined in the same directory depends on the
> output of a custom command a dependency rule is set up so the custom
> command runs before the target is being built" (slightly different
> wording, written from the top of my head). Your target however only
> has the .c file in its source list and hence nothing in your target
> depends on an output of the custom command and hence no such rule is
> set up. You can either include the .h file in the list of sources for
> your target (CMake does not generate compile-rules for files it
> recognizes as C/C++ headers), you can setup a custom target that
> depends on the .h file and has some no-op as command and make your
> executable depend on the custom target or (as you already did) have
> the .c file in the output of the custom command.
The light comes on!  Thanks for the detailed explanation, Andreas.  Adding the .h file to the executable sources list did the trick.  (And thank you Eike for suggesting that too.)

> Andreas



Videx, Inc. | 1105 NE Circle Blvd. | Corvallis, OR 97330 | (541) 738-5500
This email is intended only for the addressee(s) and may include material that is privileged, confidential, and protected from disclosure.  No contract is intended.  ©2012 Videx, Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120824/8ae4f3bd/attachment-0001.htm>


More information about the CMake mailing list