[CMake] Re: Processing new extensions with cmake

Brad King brad.king at kitware.com
Tue Apr 11 09:48:14 EDT 2006


Michael Biebl wrote:
> FWIW, this is my solution so far:
> 
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> MACRO(PROCESS_IIFILES _i_FILES _ii_FILES)
>         SET(_i_FILES)
>         FOREACH(_current_FILE ${ARGN})
>                 GET_FILENAME_COMPONENT(_tmp_FILE ${_current_FILE} ABSOLUTE)
>                 GET_FILENAME_COMPONENT(_abs_PATH ${_tmp_FILE} PATH)
>                 GET_FILENAME_COMPONENT(_basename ${_tmp_FILE} NAME_WE)
> 
>                 SET(_i_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.i)
>                 ADD_CUSTOM_TARGET(${_basename} ALL
>                         COMMAND echo "Processing: ${_current_FILE}"
>                         COMMAND
> ${CMAKE_BINARY_DIR}/tools/install_service -i
> ${CMAKE_CURRENT_SOURCE_DIR}/${_current_FILE} -o ${_i_FILE}
>                         DEPENDS ${_current_FILE})
>                 ADD_DEPENDENCIES(${_basename} install_service)
>                 SET(${_i_FILES} ${${_i_FILES}} ${_i_FILE})
> 
>         ENDFOREACH(_current_FILE)
> ENDMACRO(PROCESS_IIFILES)
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> SET(II_FILES
>         test1.ii
>         test2.ii
>         test3.ii
> )
> 
> PROCESS_IIFILES(I_FILES ${II_FILES})
> 
> INSTALL_FILES(/share/data/ FILES ${I_FILES})
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> 
> This works, more or less. But there is still one huge downside with
> this solution. The ifiles are always regenerated on calling "make" and
> I only want them to be regenerated if the file itself or the
> install_service binary has changed. Ideas, how I could do that?

Read the docs for ADD_CUSTOM_TARGET.  It is supposed to be used for a 
rule that runs every time it is built.  Use ADD_CUSTOM_COMMAND for the 
individual rules, and then have one ADD_CUSTOM_TARGET that lists all the 
custom command outputs as its dependencies.

-Brad


More information about the CMake mailing list