[CMake] Getting started with CMake macros

Eric Noulard eric.noulard at gmail.com
Tue Nov 6 04:28:21 EST 2007


2007/11/6, Thomas Sondergaard <ts_news1 at sondergaard.cc>:
> Is there a beginners guide to macros somewhere? I tried something basic
> like wrapping up find_library like this:
>
> macro(my_find_library arg1 arg2)
>    find_library(arg1 arg2)
> endmacro(my_find_library)
>
> my_find_library(CPPUNIT cppunit)
>
> To my surprise it didn't work at all. If I browse CMakeCache.txt there
> is no reference to CPPUNIT. If I call find_library directly it works!

You need to use the value (${arg1} ${arg2}) of the arguments and not
the arg name itself.

Try this:

macro(my_find_library arg1 arg2)
   message(arg1)
   message(arg2)
   message("arg1 = ${arg1}")
   message("arg2 = ${arg2}")
endmacro(my_find_library)

my_find_library(TOTO titi)

If you need more example of MACRO usage you look at
CMake distros modules directory.
For example:
CheckTypeSize.cmake
CheckFunctionExists.cmake
or any other containing MACRO.
-- 
Erk


More information about the CMake mailing list