View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004034CMakeCMakepublic2006-11-09 03:372011-05-02 14:46
ReporterGaetan Lehmann 
Assigned ToDavid Cole 
PrioritynormalSeverityfeatureReproducibilityalways
StatusclosedResolutionno change required 
PlatformOSOS Version
Product Version 
Target VersionFixed in VersionCMake 2.8.4 
Summary0004034: using a variable in the name of a macro.
DescriptionCurrently with cmake, we can do:

   SET(type "US")
   SET(IUS "tralala")

then writting ${I{type}} is the same than writting ${IUS}. That's very convenient in many cases (and that's the base of WrapITK).
However, it's not possible to do the same with the name of the macro:

   MACRO(MY_MACRO_PYTHON)
     ...
   ENDMACRO(MY_MACRO_PYTHON)
   SET(lang PYTHON)

 then calling

  MY_MACRO_${lang}()

doesn't work. This feature would be very useful to easily add a language support in ITK (for example).
TagsNo tags attached.
Attached Files

 Relationships
has duplicate 0011845closedDavid Cole Add an EVAL command to evaluate a string as a CMake script 

  Notes
(0024142)
David Cole (manager)
2010-12-15 09:01

Is this even feasible, or a good idea?

You could certainly achieve the same thing, although it would be more verbose, using a bunch of if("${lang}" STREQUAL "PYTHON") commands...
(0024201)
Gaetan Lehmann (reporter)
2010-12-16 08:10

It wouldn't be possible if the lang value is not known when writing the cmake script.
I wanted to use that feature in wrapitk to be able to add a new language simply by adding a new folder in the Languages folder. We can then do something like (and much more, this is simply an example):

file(GLOB local_files *)
foreach(f ${local_files})
  file(RELATIVE_PATH lang "${CMAKE_CURRENT_SOURCE_DIR}" "${f}")
  if(IS_DIRECTORY "${f}")
    init_${lang}()
  endif()
endforeach(f)
(0024202)
David Cole (manager)
2010-12-16 08:19

Rather than:

  init_${lang}()

You could instead write:

  include(${lang}.cmake)

And have the ${lang}.cmake file contain the code that would have been in your macro, but have it just at file scope.

While this technique requires more files, and probably care taken in those sets of files not to trounce on each other's variables and what not, it should be achievable with present day CMake. You could even do this with much older versions of CMake...

Since this workaround to the problem at hand exists, and the implementation of this feature would add much complexity (if it's even do-able...), I am going to resolve this issue as "no change required".

Please re-open and comment with further notes and elaborations if you disagree with this resolution.

Thanks.
(0024203)
Gaetan Lehmann (reporter)
2010-12-16 08:26

This would work, but would make quite difficult to pass parameters to the code, and would probably be quite inefficient if the code needs do be called many times.
But if that's too difficult to add, I'll do without that feature :-)
(0024865)
David Cole (manager)
2011-01-18 11:23

If you require your "${lang}.cmake" file to declare a single macro called MyLanguageMacro (or whatever), and have the parameters be well defined to that macro, then you could:

  include(${lang}.cmake)
  MyLanguageMacro("${a0}" "${a1}" "${a2}")

  include(${other_lang}.cmake)
  MyLanguageMacro("${a0}" "${a1}" "${a2}")
  MyLanguageMacro("${b0}" "${b1}" "${b2}")
(0024866)
David Cole (manager)
2011-01-18 11:24

Suitable workarounds for this "issue" are noted in the various notes on this bug. Please use a work-around. We will not be adding "variable expansion into function call" capabilities to the CMake language any time soon.
(0026360)
David Cole (manager)
2011-05-02 14:46

Closing resolved issues that have not been updated in more than 3 months.

 Issue History
Date Modified Username Field Change
2008-10-07 16:51 Bill Hoffman Assigned To Bill Hoffman => Ken Martin
2010-12-14 11:16 David Cole Assigned To Ken Martin =>
2010-12-15 08:59 David Cole Assigned To => Brad King
2010-12-15 09:01 David Cole Note Added: 0024142
2010-12-16 08:10 Gaetan Lehmann Note Added: 0024201
2010-12-16 08:15 David Cole Assigned To Brad King => David Cole
2010-12-16 08:19 David Cole Note Added: 0024202
2010-12-16 08:19 David Cole Status assigned => resolved
2010-12-16 08:19 David Cole Fixed in Version => CMake 2.8.4
2010-12-16 08:19 David Cole Resolution open => no change required
2010-12-16 08:26 Gaetan Lehmann Note Added: 0024203
2010-12-16 08:26 Gaetan Lehmann Status resolved => feedback
2010-12-16 08:26 Gaetan Lehmann Resolution no change required => reopened
2011-01-18 11:23 David Cole Note Added: 0024865
2011-01-18 11:23 David Cole Status feedback => assigned
2011-01-18 11:24 David Cole Note Added: 0024866
2011-01-18 11:24 David Cole Status assigned => resolved
2011-01-18 11:24 David Cole Resolution reopened => no change required
2011-05-02 14:46 David Cole Note Added: 0026360
2011-05-02 14:46 David Cole Status resolved => closed
2012-06-01 11:21 David Cole Relationship added has duplicate 0011845


Copyright © 2000 - 2018 MantisBT Team