How it works

The preprocessor definitions are defined at configure time by CMake in CMakeLists.txt and are passed on to the preprocessor. The Fortran example contains a very compact expression where we use the CMAKE_Fortran_COMPILER_ID variable to construct the preprocessor definition using target_compile_definitions. To accommodate this, we had to change the case of "Intel" from IS_INTEL_CXX_COMPILER to IS_Intel_FORTRAN_COMPILER. We could achieve the same for C or C++ by using the corresponding CMAKE_C_COMPILER_ID and CMAKE_CXX_COMPILER_ID variables. Please do note, however, that CMAKE_<LANG>_COMPILER_ID is not guaranteed to be defined for all compilers or languages.

Use the .F90 suffix for Fortran code that is supposed to be preprocessed ...

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.