[CMake] Why doesn't cmake generate the file?

Tyler Roscoe tyler at cryptio.net
Wed Dec 2 14:22:26 EST 2009


On Wed, Dec 02, 2009 at 07:58:43PM +0100, Jörg Förstner wrote:
> I thought CMake would find the custom command and generate the file "gen.h"
> Instead an error occurs, this is the output:
> 
> -- Configuring done
> CMake Error in libfoo.so/CMakeLists.txt:
>   Cannot find source file "gen.h".  Tried extensions .c .C .c++ .cc
>   .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx
> 
> Why doesn't CMake generate the file?

> ------------------
> # Set variable containing all source files
> SET( SRCS
>   foo1.c
> )
> 
> # Tell CMake that "gen.h" is a generated file
> SET_SOURCE_FILE_PROPERTIES( gen.h PROPERTIES GENERATED 1 )
> 
> # Define custom command to generate "gen.h"
> ADD_CUSTOM_COMMAND(
>   OUTPUT  gen.h
>   COMMAND echo "this command would generate 'gen.h' from data.txt"
>   DEPENDS data.txt
> )
> 
> # Define to build a target shared object library named "libfoo.so" from the source files "${SRCS}".
> # The file "foo1.c" depends on the generated include file "gen.h"
> ADD_LIBRARY( foo SHARED ${SRCS} gen.h )
> ------------------

Conceptually this looks correct.

Have you tried this with a custom command that actually creates gen.h?
The example you posted just echoes and doesn't generate anything.

tyler


More information about the CMake mailing list