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:[email protected]] On Behalf Of Chris Johnson
Sent: Thursday, January 29, 2015 8:09 AM
To: [email protected]
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
--
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