I believe you can have cmake read the contents of a file into a variable. If the file that lists the generated files is a semi-colon or space delimited (assuming no spaces in the names or paths) then you can read the file directly into a cmake variable, then use that variable as the source list to add_executable or add_library.

file(STRINGS filename variable [LIMIT_COUNT num]
[LIMIT_INPUT numBytes] [LIMIT_OUTPUT numBytes]
[LENGTH_MINIMUM numBytes] [LENGTH_MAXIMUM numBytes]
[NEWLINE_CONSUME] [REGEX regex]
[NO_HEX_CONVERSION])


STRINGS will parse a list of ASCII strings from a file and store it in a variable. Binary data in the file are ignored. Carriage return (CR) characters are ignored. It works also for Intel Hex and Motorola S- record files, which are automatically converted to binary format when reading them. Disable this using NO_HEX_CONVERSION.


file(READ filename variable [LIMIT numBytes] [OFFSET offset] [HEX])

READ will read the content of a file and store it into the variable. It will start at the given offset and read up to numBytes. If the argument HEX is given, the binary data will be converted to hexadecimal representation and this will be stored in the variable.

I may have an example in my hdf5 cmake build that does close to what you want.


_________________________________________________________
Mike Jackson                  mike.jack...@bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio



On Feb 27, 2009, at 8:01 AM, Steve Huston wrote:

Thanks for the advice, Bill.

My situation is somewhat different, though. The output source files
are not known ahead of time. Thus, the general scheme is:

- build runs the source generator; one of the outputs is a file
containing the names of the generated sources.
- rerun cmake to regenerate the build now that the complete list of
sources is known.
- rerun the build with the complete set of sources

I tried to make that all happen automatically in the build.

-Steve

--
Steve Huston, Riverace Corporation
Check out my networked programming blog at
http://stevehuston.wordpress.com/


-----Original Message-----
From: Bill Hoffman [mailto:bill.hoff...@kitware.com]
Sent: Thursday, February 26, 2009 9:04 PM
To: Steve Huston
Cc: cmake@cmake.org
Subject: Re: [CMake] Technique for generating projects that
depend on generated sources


Steve Huston wrote:
I'm working on a project that involves generating a large
chunk of the
sources from separate definitions. The set of generated source
files
is not known before it is generated.

The approach I've tried so far (and I'm very new to cmake) is to
define a custom_command that does the source generation, then run
cmake over again to regenerate the project files.

I tried this out with Microsoft Visual Studio... When I
tried a build
from inside Visual Studio the command to generate the
sources happened
like I want, but when it tried to re-run cmake to regenerate the
project with the now-known set of generated sources, an error was
thrown because cmake couldn't update VS macros while VS is
running.

So close, yet so far... ;-)

Is there a common pattern for how to address this type of
situation?


Look at the FAQ:

http://www.cmake.org/Wiki/CMake_FAQ#How_do_I_generate_an_execu
table.2C_then_use_the_executable_to_generate_a_file.3F

-Bill

_______________________________________________
Powered by www.kitware.com

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

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

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

_______________________________________________
Powered by www.kitware.com

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

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

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

Reply via email to