[CMake] if(MATCHES) broken??

George Neill georgen at neillnet.com
Wed Nov 19 18:09:28 EST 2008


Matthew,

On Wed, Nov 19, 2008 at 5:56 PM, Matthew Woehlke
<mw_triad at users.sourceforge.net> wrote:
> Can someone explain to me:
> - why this doesn't work (prints "CFLAGS match broken!!")
> - if it's supposed to work or if this is a bug
> - a great work-around to this problem ;-)
>
> This is with cmake 2.6.2
>
> ================================================
> macro(foo bar)
>  if("${bar}" MATCHES "CFLAGS")
>    message(STATUS "CFLAGS matched")
>  elseif("${bar}" STREQUAL "CFLAGS")
>    message(STATUS "CFLAGS match broken!!!")
>  endif()
> endmacro()
>
> function(nonce)
>  foreach(arg ${ARGN})
>    foo("${arg}")
>  endforeach()
> endfunction()
>
> set(CFLAGS happyjoy)
>
> foo(CFLAGS)
> ================================================
>
> Background: I'm trying to write a function that is invoked like:
>
> foobar(mylib CFLAGS -DFOO -DBAR SOURCES foo.c bar.c LINK_LIBRARIES mib)
>
> Maybe there is some great mechanism for dealing with this sort of
> list-splitting that I don't know about? Meanwhile, what I am doing is
> something like this:
>
> - For each arg, 'if("${ARG}" MATCHES "CFLAGS|SOURCES|LINK_LIBRARIES', set
> _arg_mode to ${arg}, otherwise based on ${_arg_mode}, do a list(APPEND) to
> one of _cflags, _sources, _libs.
> - add_library(${NAME} ${_sources})
> - do some target_link_libraries, set_target_properties based on _cflags,
> _libs, etc.

Here's a macro I wrote and a discussion I started some time ago,

http://www.cmake.org/pipermail/cmake/2008-May/021361.html

It's probably pretty close to what you are looking to do.

HTH,
George.


More information about the CMake mailing list