看似错误的IN_LIST关键字行为

时间:2016-02-22 22:34:20

标签: macos cmake osx-yosemite

我正在尝试使用CMake 3.3中的新逻辑来检查值是否在列表中

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()

在OSX Yosemite上使用CMake 3.4.3运行此操作会产生意外结果:

$ 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

我是否遗漏了一些微不足道的内容,或者CMake中是否有错误?

1 个答案:

答案 0 :(得分:5)

试试IF ( ${e} IN_LIST l )According to the docs第二个参数是列表变量,而不是列表。