Omit targets that are not supported by compiler

We have projects that build on a variety of platforms. I’ve added some extension code that requires some C++11 features not supported by one of the platforms, but I don’t mind if the code doesn’t build on that platform.

I could add a bunch of conditional parameters from the top down, but is there an easy way to say “if you don’t know how to build this, it’s OK to skip it”?

Essentially, test whether I would get the following error:

Target “my_target” requires the language dialect “CXX11” (with compiler extensions), but CMake does not know the compile flags to use to enable it.

and in that case just omit the target

You can test if ("cxx_std_11" IN_LIST CMAKE_CXX_COMPILE_FEATURES) to test if C++11 is supported. There may be a feature for what you want as well. If that isn’t sufficient, try_compile can be used to test for it directly.

You can also test that in the code with an ifdef, maybe.