Hi folks,

I'm very new to cmake, so apologies if this is an obvious question,
but I haven't found a way to do this after reading the documentation,
and a lot of googling.

I am trying to cmake-ify a build where the bulk of the sources are
generated.  I have a tool (python script) which reads a set of
templates and then generates many source and header files (~250).
I don't know in advance what the source files will be--it's
dependent upon the templates.  I've done this:

set(GEN_DIR gen)
set(GENERATOR path/to/script)
set(TEMPLATES template1 template2 template3)

execute_process(COMMAND ${GENERATOR} -d -o ${GEN_DIR} ${TEMPLATES}
  OUTPUT_VARIABLE GENERATED_SOURCES)

execute_process(COMMAND ${CMAKE} -E echo ${GENERATED_SOURCES})

This part works, running the generator in "dry run" mode to output
a list of files which will be generated, but not actually doing any
generation.  Running cmake gives me output like this:
gen/ome/xml/model/OME.cpp
gen/ome/xml/model/OME.h
gen/ome/xml/model/BinaryOnly.cpp
gen/ome/xml/model/BinaryOnly.h
gen/ome/xml/model/Image.cpp
gen/ome/xml/model/Image.h
gen/ome/xml/model/Pixels.cpp
gen/ome/xml/model/Pixels.h
gen/ome/xml/model/Plane.cpp
gen/ome/xml/model/Plane.h
gen/ome/xml/model/Channel.cpp
gen/ome/xml/model/Channel.h
gen/ome/xml/model/MetadataOnly.cpp
gen/ome/xml/model/MetadataOnly.h

So far, so good.  I've then tried to make the source generation occur
with a custom command.  This includes the templates as dependencies so
that the source will be regenerated if the templates change.

add_custom_command(OUTPUT ${GENERATED_SOURCES}
  COMMAND {GENERATOR} -o ${GEN_DIR} ${TEMPLATES}
  DEPENDS ${TEMPLATES}
  COMMENT Generate sources)

add_library(test SHARED ${GENERATED_SOURCES})

But this results in a broken Makefile.

gen/ome/xml/model/OME.cpp
gen/ome/xml/model/OME.h
gen/ome/xml/model/BinaryOnly.cpp
gen/ome/xml/model/BinaryOnly.h
gen/ome/xml/model/Image.cpp
gen/ome/xml/model/Image.h
gen/ome/xml/model/Pixels.cpp
gen/ome/xml/model/Pixels.h
[…]
: template1

i.e. the rules are broken due to being split over multiple lines.

I'm obviously doing something quite wrong here, but I'm not sure what.
Or indeed, if I'm approaching this from the right direction--maybe I
should be doing this completely differently.

Any thoughts and suggestions would be greatly appreciated!


Many thanks,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.

Attachment: signature.asc
Description: Digital signature

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to