How can I check in CMake whether a list contains a specific entry?

With CMake 3.3 or later, the if command supports an IN_LIST operator, e.g.:

if ("bar" IN_LIST _list)
 ...
endif()

For older versions of CMake, you can use the built-in list(FIND) function:

list (FIND _list "bar" _index)
if (${_index} GREATER -1)
  ...
endif()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)