[CMake] Generated files?

Chris Johnson cxjohnson at gmail.com
Thu Jan 29 15:36:05 EST 2015


Thanks; I appreciate the suggestions.

One thing that jumped out is the thought that foreach() is executed at
"configuration" time, not "run" time.  To me, that was counter-intuitive,
but makes more sense once more thoroughly considered.

But I have to admit, I've never seen anything in the documentation which
lists all of the commands which execute at configuration time, and which
are executed at run time.  Is there such documentation?  A link to it would
be great.

On Thu, Jan 29, 2015 at 9:51 AM, Thompson, KT <kgt at lanl.gov> wrote:

>  Hi Chris,
>
>
>
> Why not use a foreach loop? Something like this…
>
>
>
> add_executable(myprog myprog.cpp)
>
> set( files file001 fiile002 …)
>
> foreach( file in files)
>
>     add_custom_command(OUTPUT ${file}.out
>
>         COMMAND /bin/cp ${CMAKE_CURRENT_SOURCE_DIR}/${file}.in .
>
>         COMMAND myprog ${file}.in ${file}.out
>
>         DEPENDS ${file}.in myprog.cpp
>
>     )
>
> endforeach()
>
>
>
> For portability, you might want to use ‘${CMAKE_COMMAND} –E
> copy_if_different’ in place of ‘/bin/cp’ and CMAKE_CURRENT_BINARY_DIR in
> place of ‘.’
>
>
>
> -kt
>
>
>
> *From:* CMake [mailto:cmake-bounces at cmake.org] *On Behalf Of *Chris
> Johnson
> *Sent:* Thursday, January 29, 2015 8:09 AM
> *To:* cmake at cmake.org
> *Subject:* [CMake] Generated files?
>
>
>
> ​I am looking for suggestions on how to solve the following problem.  I
> need a solution which is easy to understand and safe from future
> maintenance errors.
>
>
>
> There is a project directory with one C++ program and a large number of
> "input" data files.
>
>
>
> The C++ program needs to be compiled, and then run against each of the
> input files to generate an output file of the same base name but with a
> different output suffix.  E.g. from the command line it might be:
>
>
>
>     % myprog  file001.in  file001.out
>
>
>
> Finally, the output files need to be installed in the proper location.
>
>
>
> For one input file, it might look like this:
>
>
>
>     add_executable(myprog myprog.cpp)
>
>     add_custom_command(OUTPUT file001.out
>
>         COMMAND /bin/cp ${CMAKE_CURRENT_SOURCE_DIR}/file001.in .
>
>         COMMAND myprog file001.in file001.out
>
>         DEPENDS files001.in myprog.cpp
>
>     )
>
>     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/file001.out DESTINATION
> share/docs)
>
>
>
>
>
> Listing all of the input files in my CMakeLists.txt file is not a problem,
> but it would be nice to avoid having to list the corresponding output files.
>
>
>
> How can I build a CMakeLists.txt file which will succinctly handle this
> situation?
>
>
>
> --
>
> Thanks,
>
> ..chris​
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150129/e171c6df/attachment.html>


More information about the CMake mailing list