[CMake] Using a variable as a method name

Damien R damienrg+list at gmail.com
Sat Jun 2 06:16:50 EDT 2012


On 1 June 2012 17:22, David Cole <david.cole at kitware.com> wrote:

> Not directly, but as a workaround, you could write that into a file, and
> then include the file.
>
> i.e.:
>
> file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/tmp.cmake" "BAR_${FOO}(arg1 arg2)")
> include(${CMAKE_CURRENT_BINARY_DIR}/tmp.cmake)
>

Hi, there is also a variation based on the workaround given by David:

suppose you want to call:
bar_${foo1}(arg1 arg2)
bar_${foo2}(arg1 arg2)

you can create 2 files:
- bar1.cmake
macro(bar)
...
endmacro()

- bar2.cmake
macro(bar)
...
endmacro()

After that you can replace:
bar_${foo1}(arg1 arg2)
bar_${foo2}(arg1 arg2)
by:
include(${foo1}.cmake)
bar(...)
include(${foo2}.cmake)
bar(...)

where:
${foo1} = bar1
${foo2} = bar2

Regards,
Damien R.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120602/e6411151/attachment.htm>


More information about the CMake mailing list