[CMake] Batch converting several files

Martin Fischer m_fischer at users.sf.net
Tue Mar 11 15:44:08 EDT 2008


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






More information about the CMake mailing list