Skip to content

FindOpenMP: Complete overhaul

Christian Pfeiffer requested to merge ChrisTX/cmake:findopenmp-modernized into master

The current FindOpenMP implementation suffers from a variety of issues, which this MR seeks to address. To give an overview:

  • No libraries required for linking OpenMP programs were looked for. This makes for example, linking a static Fortran library built with OpenMP enabled in a C++ executable or vice versa impossible.
  • The Fortran implementation assumed that omp_lib is a module. The OpenMP standard says that it is implementation defined whether there is an omp_lib.h or an omp_lib module.
  • The Fortran test program never guaranteed that the flags detected actually enable OpenMP. A lot of compilers offer OpenMP stubs, and some turn them on by default (for example PGI), so that the previous implementation would have accepted no flags for PGI as enabling OpenMP, which it does not do, you need to pass -mp.
  • Because of the way OPENMP_FOUND worked, it was not possible to tell which language's compiler was not suitable for OpenMP. As a real world example, we've got an older Mac machine at work whose AppleClang compiler does not support OpenMP, but the Intel Fortran compiler installed does.
  • The module could detect the OpenMP specification date, but not map it to an OpenMP version. Using standard CMake paradigms of for example find_package(OpenMP 3.0) to ensure that at least version 3.0 was found, wasn't possible.

I'm aware that this MR is very large, but I felt it wasn't possible to break it into smaller reasonable pieces because of the amount of code it rewrites in FindOpenMP. This MR addresses all of these issues (see the documentation in the package), adds IMPORTED targets to FindOpenMP and introduces a test for the module. With the IMPORTED targets, the aforementioned linking problem can be solved in a very easy fashion by linking the Fortran library privately with OpenMP::OpenMP_<lang>.

Merge request reports