[CMake] macros with arguments

Tom Kacvinsky tom.kacvinsky at vectorcast.com
Tue May 19 15:30:13 EDT 2015


On Tue, May 19, 2015 at 1:28 PM, Tom Kacvinsky <tom.kacvinsky at vectorcast.com
> wrote:

> HI,
>
> Background:  trying to build several executables that have the same target
> link libraries, compile flags, etc..., but different source files.  Rather
> than duplicate all of the necessary bits for each target, I thought I'd
> write a macro that takes in arguments (the target name and list of files).
>
> But I am am unsure (based on the cmake documentation for macro()) as how
> to pick out the target and list of files so I can do the right thing with
> add_executable.
>
> Any ideas?
>
> Thanks,
>
> Tom
>

I figured this out.

macro(macro_name target_name)
    add_executable(${target_name} ${ARGN})
    target_link_libraries(${target_name} ...)
endmacro(macro_name)

Sorry for the noise

Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150519/9d96915e/attachment.html>


More information about the CMake mailing list