[CMake] Generated files?
Petr Kmoch
petr.kmoch at gmail.com
Thu Jan 29 11:15:42 EST 2015
Hi Chris.
I believe a function should do the trick:
function(ProcessFile inFile)
get_filename_component(outFile ${inFile} NAME_WE)
set(outFile ${outFile}.out)
add_custom_command(
OUTPUT ${outFile}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${inFile}
${CMAKE_CURRENT_BINARY_DIR}
COMMAND myprog ${inFile} ${outFile}
DEPENDS ${inFile} myprog.cpp
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${outFile} DESTINATION
share/docs)
endfunction()
(Modulo syntax errors, untested)
Petr
On Thu, Jan 29, 2015 at 4:09 PM, Chris Johnson <cxjohnson at gmail.com> wrote:
> 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
>
> --
>
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150129/5f410bb6/attachment.html>
More information about the CMake
mailing list