How it works

Both try_compile and check_cxx_source_compiles will compile and link a source file into an executable. If those operations succeed, then the output variable, omp_task_loop_test_1 for the former and omp_task_loop_test_2 for the latter, will be set to TRUE. The way this task is achieved is slightly different between the two commands, however. The check_<lang>_source_compiles family of commands is a simplified wrapper to the try_compile command. As such, it offers a minimal interface:

  1. The code snippet to be compiled has to be passed in as a CMake variable. Most of the time this means that files have to be read in using file(READ ...), as we have done in our example. The snippet is then saved to a file in the CMakeFiles/CMakeTmp ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.