First: thanks for your questions to the CMake list. However, when you send an email to the list, please just ask the question -- that is, please do *not* ask me by name. I know I've answered a few questions for you in the last few weeks, but I am not the only one here, and asking me by name may discourage somebody else from answering earlier if they are able to. The list is a community resource, and all should feel welcome to chime in on any discussion where they can add something useful.

I think using "file(WRITE..." followed by "file(APPEND..." is the simplest way of performing file concatenation using the CMake language.

However, I would never write a custom command rule that writes files into the source tree of a project. For one thing, it precludes having two separate build trees for a single source tree that do not clobber each other - the build trees should be independent of each other... but when you push output to the source tree, multiple builds can never be independent of each other.

It might be simpler or more elegant to use a different language (python, perl, ?) for this task, but if you must do it in CMake, what you have is just fine.

I'm certain you could make the code easier to understand by naming variables more descriptively (FILE1, FILE2, FILE3, ... are not very descriptive) and by adding some comments. Also, there's no reason to file(WRITE the script itself in your example: the script could simply be written, and be a part of your source code, and then just called from the custom command. That would remove a leap of indirection that a developer reading the code has to make mentally to understand what you've got. If the script file is just a script file, and they can look at it as such, then the add_custom_command becomes easier to read, because it doesn't have the crazy file(WRITE with backslashes in it to interpret.

HTH,
David C.

--

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://public.kitware.com/mailman/listinfo/cmake

Reply via email to