[CMake] Generated files?

Thompson, KT kgt at lanl.gov
Thu Jan 29 10:51:10 EST 2015


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<http://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<http://file001.in> .
        COMMAND myprog file001.in<http://file001.in> file001.out
        DEPENDS files001.in<http://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/2c8a2d65/attachment-0001.html>


More information about the CMake mailing list