<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>Why doesn't cmake generate the file?</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Arial">Hi,</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I have a generator which is given a data file &quot;data.txt&quot; and then generates an include file &quot;gen.h&quot;.</FONT>

<BR><FONT SIZE=2 FACE="Arial">&quot;gen.h&quot; is told to CMake to be a generated file.</FONT>

<BR><FONT SIZE=2 FACE="Arial">&quot;gen.h&quot; is added to the library.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">I thought CMake would find the custom command and generate the file &quot;gen.h&quot;</FONT>

<BR><FONT SIZE=2 FACE="Arial">Instead an error occurs, this is the output:</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">-- Configuring done</FONT>

<BR><FONT SIZE=2 FACE="Arial">CMake Error in libfoo.so/CMakeLists.txt:</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; Cannot find source file &quot;gen.h&quot;.&nbsp; Tried extensions .c .C .c++ .cc</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Why doesn't CMake generate the file?</FONT>
</P>
<BR>

<P><FONT SIZE=2 FACE="Arial">Example code:</FONT>

<BR><FONT SIZE=2 FACE="Arial">------------------</FONT>

<BR><FONT SIZE=2 FACE="Arial"># Set variable containing all source files</FONT>

<BR><FONT SIZE=2 FACE="Arial">SET( SRCS</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; foo1.c</FONT>

<BR><FONT SIZE=2 FACE="Arial">)</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial"># Tell CMake that &quot;gen.h&quot; is a generated file</FONT>

<BR><FONT SIZE=2 FACE="Arial">SET_SOURCE_FILE_PROPERTIES( gen.h PROPERTIES GENERATED 1 )</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial"># Define custom command to generate &quot;gen.h&quot;</FONT>

<BR><FONT SIZE=2 FACE="Arial">ADD_CUSTOM_COMMAND(</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; OUTPUT&nbsp; gen.h</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; COMMAND echo &quot;this command would generate 'gen.h' from data.txt&quot;</FONT>

<BR><FONT SIZE=2 FACE="Arial">&nbsp; DEPENDS data.txt</FONT>

<BR><FONT SIZE=2 FACE="Arial">)</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial"># Define to build a target shared object library named &quot;libfoo.so&quot; from the source files &quot;${SRCS}&quot;.</FONT>

<BR><FONT SIZE=2 FACE="Arial"># The file &quot;foo1.c&quot; depends on the generated include file &quot;gen.h&quot;</FONT>

<BR><FONT SIZE=2 FACE="Arial">ADD_LIBRARY( foo SHARED ${SRCS}<B> gen.h</B> )</FONT>

<BR><FONT SIZE=2 FACE="Arial">------------------</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">PS: I'm using CMake V2.6, if this might be useful to know.</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Best Regards,</FONT>

<BR><FONT SIZE=2 FACE="Arial">Joerg</FONT>
</P>

</BODY>
</HTML>