[CMake] How to copy dependent files

Tron Thomas tron.thomas at verizon.net
Thu Dec 11 23:44:18 EST 2008


I have a project configured with CMake that needs to have  set of XML  
files copied to the directory where executables are built so that a  
unit test that relies on these files can execute.

I tried to create a custom command that should copy the files and  
tried to set that command up as dependency of the unit test  
application.  However when the application builds the files are not  
copied to the needed directory.

Here is the gist of how I tried to perform the copy:

file(GLOB SourceXMLFiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/XML XML/ 
*.xml)

foreach(File ${SourceXMLFiles})
	set(XMLFiles "${XMLFiles} ${EXECUTABLE_OUTPUT_PATH}/${File}")
endforeach(File)

add_custom_command(OUTPUT ${XMLFiles}
	COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory
		${CMAKE_CURRENT_SOURCE_DIR}/XML	${EXECUTABLE_OUTPUT_PATH}
	DEPENDS ${SourceXMLFiles})

add_dependencies(UnitTest ${XMLFiles})

What can be done to copy the needed files to the unit test directory?



More information about the CMake mailing list