[CMake] Bug? add_custom_command() ignores head file outputs
Adam B
adamb at videx.com
Fri Aug 24 13:27:01 EDT 2012
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 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.
Here's a simplified setup to reproduce the problem:
---------project_dir/-----------
CMakeLists.txt
hello.c
hello.h
update_hello_h.sh
--------CMakeLists.txt---------
cmake_minimum_required(VERSION 2.8)
project(cmake_test)
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM ON) #so hello.h never gets cleaned away
add_custom_command(OUTPUT hello.h COMMAND ./update_hello_h.sh DEPENDS update_hello_h.sh)
add_executable(hello hello.c)
------------hello.c----------------
#include <stdio.h>
#include "hello.h"
int main(int argc, char ** argv)
{
printf(HELLO_MSG "\n");
return 0;
}
-----------hello.h----------------
#define HELLO_MSG "Hello Fri Aug 24 09:01:53 PDT 2012"
-------update_hello_h.sh-----
#!/bin/sh
echo "#define HELLO_MSG" \"Hello `date`\" > hello.h
----------------------------------
What I would expect is for CMake to add a makefile rule to execute ./update_hello_h.sh if it's newer than hello.h. No such rule gets generated. However, if you add hello.c like so:
add_custom_command(OUTPUT hello.h hello.c COMMAND ./update_hello_h.sh DEPENDS update_hello_h.sh)
Then a rule gets generated. Is this a bug or am I missing something? I feel like I'm lying to CMake by telling it that hello.c is an output when it really isn't.
I'm using CMake 2.8.0 on Ubuntu 10.04.
Much thanks!
- Adam B.
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/5205d9b1/attachment.htm>
More information about the CMake
mailing list