The code for this recipe is available at https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-05/recipe-08 and has a C/C++ example. The recipe is valid with CMake version 3.6 (and higher) and has been tested on GNU/Linux and macOS. The code repository also contains an example compatible with CMake 3.5.
We have so far shown how to check that a given source snippet can be compiled by the chosen compiler and how to make sure that the desired compiler and linker flags are available. This recipe will show how to check whether a code snippet can be compiled, linked, and run on the current system.