[CMake] Problem with multiple expressions with if()

Tom Kacvinsky tom.kacvinsky at vectorcast.com
Fri May 15 16:29:18 EDT 2015


On Fri, May 15, 2015 at 2:17 PM, Petr Kmoch <petr.kmoch at gmail.com> wrote:

> `if(${LINUX64})` will expand to `if()` if LINUX64 is either not defined,
> or holds an empty string. In both cases, it's a syntax error. If you want
> to check whether LINUX64 is set to a truthy value, either quote it, or
> don't dereference it:
>
> if((CMAKE_SYSTEM_NAME MATCHES "SunOS") OR LINUX64)
>
> Note that you don't have to dereference the left-hand argument of MATCHES
> either. In fact, it's safer to either not dereference it, or put quotes
> around the dereference.
>
> Petr
>
> Petr,


I see where things went wrong now.  I've taken your advice and that indeed
fixed the issue.

Tom


> On Fri, May 15, 2015 at 8:07 PM, Tom Kacvinsky <
> tom.kacvinsky at vectorcast.com> wrote:
>
>>
>>
>> On Fri, May 15, 2015 at 1:05 PM, Tom Kacvinsky <
>> tom.kacvinsky at vectorcast.com> wrote:
>>
>>> On Fri, May 15, 2015 at 12:12 PM, Domen Vrankar <domen.vrankar at gmail.com
>>> > wrote:
>>>
>>>> > if ((${CMAKE_SYSTEM_NAME} MATCHES "SunOS") or (DEFINED LINUX64))
>>>> >   message(STATUS "On Solaris or 64 bit Linux")
>>>> > endif()
>>>> > # ====================================================[
>>>> >
>>>> > I'm using cmake version 2.8.11.2 built from source on
>>>> >
>>>> > Linux localhost.localdomain 2.6.18-8.el5 #1 SMP Thu Mar 15 19:46:53
>>>> EDT 2007
>>>> > x86_64 x86_64 x86_64 GNU/Linux
>>>> >
>>>> > This doesn't work.  I get this error message is:
>>>> >
>>>> > CMake Error at CMakeLists.txt:12 (if):
>>>> >   if given arguments:
>>>> >
>>>> >     "(" "Linux" "MATCHES" "SunOS" ")" "or" "(" "DEFINED" "LINUX64" ")"
>>>> >
>>>> >   Unknown arguments specified
>>>> >
>>>> >
>>>> > What am I doing wrong?  Is this syntax not supported until the 3.x
>>>> series?
>>>>
>>>> Commands are case sensitive so OR should be upper cased.
>>>> Also I would recommand you either use "${var_name}" or var_name as the
>>>> command expects either a string or a variable.
>>>>
>>>> Regards,
>>>> Domen
>>>>
>>>
>>> Ah, that did it.  Changing to uppercase OR fixed the issue.  Many thanks.
>>>
>>>
>> Well, shoot.  I had made a typeo that fooled cmake into thinking what I
>> had done is OK.  Here is what I have now:
>>
>>  if ((${CMAKE_SYSTEM_NAME} MATCHES "SunOS") OR ${LINUX64})
>>
>> and I still get a complaint:
>>
>> CMake Error at CMakeLists.txt:164 (if):
>>   if given arguments:
>>
>>     "(" "Linux" "MATCHES" "SunOS" ")" "OR"
>>
>>
>>
>>
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
>> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/cmake
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150515/7ab6e0b6/attachment.html>


More information about the CMake mailing list