[CMake] Checking for empty list

Michael Wild themiwi at gmail.com
Fri Nov 25 09:32:29 EST 2011


Yes. If you RTFM about the IF() command you see that you can either use
the variable name MYLIST or the variable value ${MYLIST}. AFAIK for this
kind of test you would need to put the latter in quotes, however.

Michael

On 11/25/2011 03:29 PM, Daniel Dekkers wrote:
> Thanks, so...
> 
> IF( MYLIST )
> 	MESSAGE( STATUS "List is not empty" )
> ENDIF()
> 
> Without the ${...} surrounding MYLIST, which confuses me, but probably makes
> sense if you (better than I do) know what you're doing ;-)
> 
> -----Oorspronkelijk bericht-----
> Van: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] Namens Michael
> Wild
> Verzonden: vrijdag 25 november 2011 15:15
> Aan: cmake at cmake.org
> Onderwerp: Re: [CMake] Checking for empty list
> 
> On 11/25/2011 02:52 PM, Daniel Dekkers wrote:
>> Hi,
>>
>>  
>>
>> I know it should be out there somewhere in the documentation, but 
>> can't find it.
>>
>> How do I check for an empty list?
>>
>> I can use LIST(LENGTH MYLIST LISTCOUNT) with an extra variable 
>> LISTCOUNT but isn't there a single command?
>>
>>  
>>
>> Thanks,
>>
>> Daniel
>>
> 
> 
> An empty list is an empty variable, and evaluates to FALSE. So you can use
> 
> if(NOT MYLIST)
>   message("Either MYLIST is empty or otherwise FALSE")
> endif()
> 
> Michael
> --
> 
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
> 
> --
> 
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list