[CMake] Generating Source Files

Jeremy Cowgar jeremy at cowgar.com
Wed Apr 8 19:43:00 EDT 2009


Bill Hoffman wrote:
> Yes, that is the only way to make it work right now.  It would be nice 
> to be able to add an arbitrary file that cmake would re-run when it 
> changes.  Please create a feature request for this.  However, for now 
> configure_file input is the only way to get your files in the list of 
> files that are checked with each make run.

Bill (and others)... Thanks for keeping with me through this. I would 
have not figured it out on my own and as it stands now, CMake seems to 
be able to do the job and do it well. I'm going to keep working on it, 
make it build the other binaries (we have the interpreter, compiler, 
backend, unit testing tool, doc tool, disassembly tool and a few other 
misc tools).

Thank you very much, really. It's going to be much nicer using CMake.

I came up with this:

MACRO( EUC BASE_DIR SOURCE_FILES PRG_NAME )
  SET( _UPDATE 0 )
  FOREACH( file ${SOURCE_FILES} )
    SET( _FULL_FILE "${BASE_DIR}/${file}" )
    CONFIGURE_FILE( "${_FULL_FILE}" 
"${CMAKE_CURRENT_BINARY_DIR}/${file}.flag" )
    IF( "${_FULL_FILE}" IS_NEWER_THAN 
"${CMAKE_CURRENT_BINARY_DIR}/${PRG_NAME}.cmake" )
      SET( _UPDATE 1 )
    ENDIF()
  ENDFOREACH()

  IF( _UPDATE )
    MESSAGE( "Translating ${PRG_NAME}.ex..." )
    EXECUTE_PROCESS(
      COMMAND ${TRANSLATOR} -cmakefile "${BASE_DIR}/${PRG_NAME}.ex"
      WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" )
  ENDIF()

  INCLUDE( "${CMAKE_CURRENT_BINARY_DIR}/${PRG_NAME}.cmake" )
ENDMACRO( EUC )

So, now I can reuse it for a few programs. Does that look OK? It seems 
to work well.

Jeremy



More information about the CMake mailing list