[CMake] Converting implicit makefile rules

Alexander Neundorf a.neundorf-work at gmx.net
Mon Jul 6 15:56:31 EDT 2009


On Monday 06 July 2009, Nick Davidson wrote:
> Dear List,
>
> Is there an idomatic way of converting an implicit makefile rule to a
> CMakeLists construct?
> Currently I'm resorting to writing a macro which processes list
> variables with foreach and adds various linked custom targets but I'm
> finding lots of confusion when passing lists as arguments to macros.
>
> I tried the following:
>
> macro (MakeCustomTarget TARGET_FILE CPP XML)
>   add_custom_target(TARGET_FILE ALL
>     COMMAND process ${TARGET_FILE} ${CPP}
>     COMMAND process ${TARGET_FILE} ${XML})
>   message(STATUS "Cannot find xgettext")
> endmacro (MakeCustomTarget TARGET_FILE CPP XML)
>
> calling MakeCustomTarget("TargetFile" ${LIST1} ${LIST2}) where LIST1 and
> LIST2 are semi-colon separated lists causes the first two elements of
> whatever the LIST1 was to get passed as CPP and XML - I had to resort to
> quoting the arguments and then turning them back in to lists with a set.
>
> macro (MakeCustomTarget TARGET_FILE CPP XML)
>   set(CPP_LIST ${CPP})
>   set(XML_LIST ${XML})
>     add_custom_target(TARGET_FILE ALL
>     COMMAND process ${TARGET_FILE} ${CPP_LIST}
>     COMMAND process ${TARGET_FILE} ${XML_LIST})
> endmacro (MakeCustomTarget TARGET_FILE CPP XML)
>
> MakePot("project.pot" "${LIST1}" "${LIST2}")
>
> Is this behavior expected? 

Yes.

What you could do is to use the names of the variables as argument, not the 
contents. Then in the macro you have to dereference them once to get the name 
of the variable, and twice to get the actual content:

macro (MakeCustomTarget TARGET_FILE CPP XML)
   foreach(currentCpp ${${CPP}}
   ...
endmacro...


MakePot("project.pot" LIST1 LIST2)
 

> I'm running Debian Lenny and Cmake 2.6-patch0

2.6.0 wasn't a very good release, I would suggest >= 2.6.2.

Alex


More information about the CMake mailing list