[CMake] Re: [CMake-Promote] Re: Language barrier

Brad King brad.king at kitware.com
Mon Jan 2 12:02:51 EST 2006


E. Wing wrote:
> As for why CMake needs a "real" language. Take this stupid example:
> 
> TRY_COMPILE(MY_RESULT ...)
> IF(${MY_RESULT} MATCHES "Unknown symbol _foo")
>  # Do stuff to add libraries that contain _foo
>  ...
> ENDIF(${MY_RESULT} MATCHES "Unknown symbol _foo")
> 
> When TRY_COMPILE fails, this code works fine. But when TRY_COMPILE
> passes, CMake barfs on the line because of a syntax error and aborts
> the generation process. This is apparently because ${MY_OUTPUT}
> expands to nothing and you have an invalid IF statement.
[snip]
> I'm not a language expert so I don't really know why these things keep
> breaking for me, but based on Brad's post, I suspect he knows why and
> has better examples and I'm hoping he'll chime in here.

I agree this discussion should be moved to the main cmake list, so 
please post further questions on this topic there.  However to complete 
the thread here and not leave this question unanswered...

Either of these will work:

# Use the IF(string MATCHES regex) signature.
# Double-quotes ensure the first argument is a valid string.
IF("${MY_RESULT}" MATCHES "Unknown symbol _foo")
   ...
ENDIF("${MY_RESULT}" MATCHES "Unknown symbol _foo")

# Use the IF(variable MATCHES regex) signature.
IF(MY_RESULT MATCHES "Unknown symbol _foo")
   ...
ENDIF(MY_RESULT MATCHES "Unknown symbol _foo")

Read the IF command's documentation carefully.

-Brad


More information about the CMake mailing list