On 06/01/2010 09:57 PM, Michael Wild wrote: > > On 1. Jun, 2010, at 17:02 , Hariharan wrote: > >> I do use ADD_CUSTOM_COMMAND to generate the files, but the actual generation >> is done by a different Perl script. In some cases, there is no direct >> correlation between the name of the source file and the name of the >> destination file; and the number of generated files is quite large. However, >> assuming I could get a list of the generated files from the script, is there >> any way I can use that information (can i set the sources to this, for >> example) ? >> This output would be the actual list of files that I need to compile.
The following gensrc.pl generates source files and prints their names: foreach (1,2,3) { open($f,">","src_$_.c"); print $f "void f_$_(void){}\n"; close($f); print "src_$_.c "; } print "\n"; The following CMakeLists.txt CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) PROJECT(GENSRC C) EXECUTE_PROCESS( COMMAND perl ${CMAKE_SOURCE_DIR}/gensrc.pl OUTPUT_VARIABLE GENSRCS OUTPUT_STRIP_TRAILING_WHITESPACE ) SEPARATE_ARGUMENTS(GENSRCS) ADD_LIBRARY(gensrc ${GENSRCS}) executes gensrc.pl at configure time, collects the source files and uses them to build a library. Perhaps, this suits your needs, but take heed of MW's advice: If the generated files change you must reconfigure, regenerate and rebuild; the latter by itself is not sufficient. Possibly, you can go one step further: CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) PROJECT(GENSRC C) EXECUTE_PROCESS( COMMAND perl ${CMAKE_SOURCE_DIR}/gensrc.pl OUTPUT_VARIABLE GENSRCS OUTPUT_STRIP_TRAILING_WHITESPACE ) SEPARATE_ARGUMENTS(GENSRCS) ADD_LIBRARY(gensrc ${GENSRCS} timestamp) EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E touch timestamp) ADD_CUSTOM_COMMAND( OUTPUT timestamp COMMAND ${CMAKE_COMMAND} . COMMAND ${CMAKE_COMMAND} --build . DEPENDS gensrc.pl ) Here, you have an additional dependency of the project's target on a file just recording a timestamp at configure time. Furthermore, this timestamp file depends on gensrc.pl, and the associated custom command reconfigures, regenerates and rebuilds the project; thus, touching the timestamp file by the way. If gensrc.pl, i.e. the set of the generated files, changes a simple "make" has the project reconfigure, regenerate and rebuild, and obviously, one could have further dependencies of the timestamp file, e.g. on input data to gensrc.pl. For the time being, I have seen this appoach working for *nix Makefiles, but I don't know if it's suitable w.r.t. other generators. Moreover, I'm in doubt if it could be denoted as a clean solution. Regards, Michael _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake