I have a small cmake-based C++11 library that could be improved by using some C++14 and some C++17 features.
To that end I want CMake to test whether cxx_std_14
and/or cxx_std_17
is in the list CMAKE_CXX_COMPILE_FEATURES, as hinted at in the related SO question How to detect C++11 support of a compiler with CMake.
I can't quite figure out how to write this test, though. What I think should work, doesn't:
list (FIND ${CMAKE_CXX_COMPILE_FEATURES} "cxx_std_14" _index)
if (${_index} GREATER -1)
message("YAY 14")
else()
message("NAY 14")
endif()
# -> CMake Error .... (list):
# list sub-command FIND requires three arguments
(Because the mimumum CMake version is 2.8.7 I have to use list(FIND ...) instead of the newer, more concise IN_LIST).
CMAKE_CXX_COMPILE_FEATURES
seems to be a semicolon-separated string, so this ugly snippet works:
if ("${CMAKE_CXX_COMPILE_FEATURES}" MATCHES "cxx_std_14")
message("YAY 14")
else()
message("NAY 14")
endif()
Surely, this isn't the proper way to do it... Any help would be appreciated.