[CMake] Batch converting several files

Andy Lego andy at legoandy.com
Tue Mar 11 16:24:26 EDT 2008


Hello Martin,

You cannot nest commands and constructs. Move the FOREACH before the
custom target and set a variable in it. Then use the result in the
custom target.

Andy

On Tue, Mar 11, 2008 at 12:44 PM, Martin Fischer <m_fischer at users.sf.net> wrote:
> Hi,
>
>  for a project I'm working on I need to do the following build steps:
>
>  - compile an executable from source
>  - run this executable to convert several files
>  - for each input file in source directory there will be one output file
>  in build directory.
>
>  I tried several variants of he following but didn't come up with a good
>  solution.
>
>  # create the executable
>  ADD_EXECUTABLE( convert convert.c )
>
>  GET_TARGET_PROPERTY(convert_EXE convert LOCATION)
>
>  SET( SOURCE_FILES
>          ${CMAKE_CURRENT_SOURCE_DIR}/file1
>          ${CMAKE_CURRENT_SOURCE_DIR}/file2
>          ...
>          ${CMAKE_CURRENT_SOURCE_DIR}/filen )
>
>  ADD_CUSTOM_TARGET( mytarget
>                    DEPENDS SOURCE_FILES convert
>                    FOREACH( ${FILE} ${SOURCE_FILES})
>                        COMMAND ${convert_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/$(FILE)
>  ${CMAKE_CURRENT_BINARY_DIR}/$(FILE)
>                    ENDFOREACH( ${FILE})
>                   )
>
>  Whenever I try this, ccmake complains about the FOREACH line. Of course
>  the trivial solution
>
>  ADD_CUSTOM_TARGET( mytarget
>                    DEPENDS SOURCE_FILES convert
>                    COMMAND ${convert_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/file1
>  ${CMAKE_CURRENT_BINARY_DIR}/file1
>                    COMMAND ${convert_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/file2
>  ${CMAKE_CURRENT_BINARY_DIR}/file2
>                    ...
>                   )
>
>  works. But there must be a more flexible way. So what would you suggest?
>   Do I make an error somewhere?
>
>  Thanks in advance.
>
>  Regards
>  Martin
>
>
>
>
>  _______________________________________________
>  CMake mailing list
>  CMake at cmake.org
>  http://www.cmake.org/mailman/listinfo/cmake
>



-- 
http://legoandy.com -o- http://capitalmtb.org

Support my 150 mile bike ride to fight MS:
http://bikecan.nationalmssociety.org/site/TR?px=3921627&pg=personal&fr_id=9066


More information about the CMake mailing list