<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="" text="#000000">
Hello all,<br>
<br>
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:<br>
<br>
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.<br>
<br>
Here's a simplified setup to reproduce the problem:<br>
<br>
---------project_dir/-----------<br>
<br>
CMakeLists.txt<br>
hello.c<br>
hello.h<br>
update_hello_h.sh<br>
<br>
--------CMakeLists.txt---------<br>
<br>
cmake_minimum_required(VERSION 2.8)<br>
project(cmake_test)<br>
<br>
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM ON) #so hello.h
never gets cleaned away<br>
<br>
add_custom_command(OUTPUT hello.h COMMAND ./update_hello_h.sh
DEPENDS update_hello_h.sh)<br>
<br>
add_executable(hello hello.c)<br>
<br>
------------hello.c----------------<br>
<br>
#include <stdio.h><br>
#include "hello.h"<br>
int main(int argc, char ** argv)<br>
{<br>
printf(HELLO_MSG "\n");<br>
return 0;<br>
}<br>
<br>
-----------hello.h----------------<br>
<br>
#define HELLO_MSG "Hello Fri Aug 24 09:01:53 PDT 2012"<br>
<br>
-------update_hello_h.sh-----<br>
<br>
#!/bin/sh<br>
echo "#define HELLO_MSG" \"Hello `date`\" > hello.h<br>
<br>
----------------------------------<br>
<br>
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:<br>
<br>
add_custom_command(OUTPUT hello.h hello.c COMMAND
./update_hello_h.sh DEPENDS update_hello_h.sh)<br>
<br>
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.<br>
<br>
I'm using CMake 2.8.0 on Ubuntu 10.04.<br>
<br>
Much thanks!<br>
- Adam B.<br>
<BR />
<BR />
<HR />
Videx, Inc. | 1105 NE Circle Blvd. | Corvallis, OR 97330 | (541) 738-5500<BR />
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.<BR />
<BR />
</body>
</html>