FindOpenMP does not find separate link library
With the last three versions of macOS, it is possible to build and use OpenMP with the default Clang compiler. With the new libomp formula in brew, it's now easier than ever to make OpenMP available. But, FindOpenMP does not discover the correct library to link to. (I think this is related to #17474)
The following compiler flag needs to be added if the compiler is AppleClang:
-Xpreprocessor -fopenmp
The linker phase needs -lomp
(or the full library name). This could be added to the correct variable and the OpenMP::
targets.
I'm working on a patch but it's not working yet. One oddity I've noticed is that include is done two different ways, include(${CMAKE_ROOT}/Modules/...)
and include(${CMAKE_CURRENT_LIST_DIR}/...)
; only one of those should be used. Not sure which is better (for my testing, the first is more useful).
It would be great if this could be fixed before 3.11, since that would allow any CMake project using the modern OpenMP inclusion to start working on brew (if they just link to FLAGS, obviously those can't be fixed).
See also:
- A blog post I wrote about OpenMP on macOS
- Libomp formula
- A makeshift patcher helper script (not the correct method, just shows it can be done).