Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake seemingly incorrect behavior of IN_LIST keyword

I am trying to use the new logic in CMake 3.3 that checks if a value is in a list

cmake_minimum_required(VERSION 3.3)
cmake_policy(SET CMP0057 NEW)

set(l A B C)
foreach( e ${l} ) 
  if( ${e} IN_LIST "${l}" )
    message( "element ${e} found in ${l}" )
  else()
    message( "element ${e} NOT found in ${l}" )
  endif()
endforeach()

Running this with CMake 3.4.3 on OSX Yosemite gives an unexpected result:

$ cmake -P cmakeBug.cmake
element A NOT found in A;B;C
element B NOT found in A;B;C
element C NOT found in A;B;C

Am I missing something trivial or is there a bug in CMake?

like image 645
user1357687 Avatar asked Feb 22 '16 22:02

user1357687


1 Answers

Try IF ( ${e} IN_LIST l ). According to the docs the second argument is a list variable, not a list.

like image 147
user3159253 Avatar answered Nov 12 '22 12:11

user3159253