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

Jörg Förstner Joerg.Foerstner at ubidyne.com
Wed Dec 2 13:58:43 EST 2009


Hi,

I have a generator which is given a data file "data.txt" and then generates an include file "gen.h".
"gen.h" is told to CMake to be a generated file.
"gen.h" is added to the library.

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?


Example code:
------------------
# 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 )
------------------

PS: I'm using CMake V2.6, if this might be useful to know.

Best Regards,
Joerg

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20091202/f396cccf/attachment.htm>


More information about the CMake mailing list