[CMake] if(MATCHES) broken??

Matthew Woehlke mw_triad at users.sourceforge.net
Wed Nov 19 17:56:44 EST 2008


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.

-- 
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
-- 
Sendmail administration is not black magic. There are legitimate 
technical reasons why it requires the sacrifice of a live chicken.
   -- Unknown



More information about the CMake mailing list