[CMake] Generating Source Files

Bill Hoffman bill.hoffman at kitware.com
Wed Apr 8 13:53:26 EDT 2009


Jeremy Cowgar wrote:
> Bill Hoffman wrote:
>> One more option would be to run the parser every time cmake is run.  
>> If you had an option to the parser that just spit out the list of 
>> files you needed to compile, and it ran relatively fast, you could do 
>> this:
>>
>> # only run if parser.e is newer than source.cmake
>> if(parser.e IS_NEWER_THAN source.cmake)
>>    execute_process(COMMAND myparser  parser.e --sources sources.cmake)
>> endif()
> 
> I like this solution much better, but I have simplified things for my 
> example. I have been stating parser.e is the only input file. While that 
> is true, parser.e is known to depend on a set of other files. So, in the 
> above example I would need to check IS_NEWER_THAN a list of files I have:
> 
> SET( EU_CORE_FILES common.e emit.e error.e fwdref.e global.e inline.e 
> keylist.e main.e mode.e opnames.e parser.e
>  pathopen.e reswords.e scanner.e scinot.e shift.e symtab.e )
> 
> Is there a simple way of doing that?
> 

Yes, with a function like this:

function(newer file)
   math(EXPR ENDRANGE "${ARGC} - 1")
   foreach(c RANGE 1 ${ENDRANGE}})
     set(inputfile ${ARGV${c}})
     if("${inputfile}" IS_NEWER_THAN  "${file}")
       set(IS_NEWER TRUE PARENT_SCOPE)
       return()
     endif()
   endforeach()
   set(IS_NEWER FALSE PARENT_SCOPE)
endfunction(newer)
SET( EU_CORE_FILES common.e emit.e error.e fwdref.e global.e inline.e
   keylist.e main.e mode.e opnames.e parser.e
   pathopen.e reswords.e scanner.e scinot.e shift.e symtab.e )
newer( source.cmake ${EU_CORE_FILES})
message("IS_NEWER = ${IS_NEWER}")
#IS_NEWER should be TRUE if any of the EU_CORE_FILES are newer than
# source.cmake

I like this solution as well, as you don't have to be running cmake from 
cmake.   It does mean that you have to be able to run the parser at 
first cmake time.

-Bill




More information about the CMake mailing list