FindOpenMP sets incorrect OpenMP_<lang>_LIB_NAMES on AppleClang
At least when using clang and gnu compilers, the OpenMP_<lang>_LIB_NAMES
list contains library names like omp
or gomp
, which makes it easy to write a loop and add -l${_lib}
to LDFLAGS
for an external project. However, when using AppleClang, the list contains libomp
, which results in an error because AppleClang doesn't like -llibomp
.
An easy workaround is to strip ^lib
from library names, but I'm opening this issue to suggest changing libomp
to omp
in this line:
set("${OPENMP_LIB_NAMES_VAR}" "libomp" PARENT_SCOPE)
This would also make the content of the OpenMP_<lang>_LIB_NAMES
match between Clang and AppleClang. Here is the line in the source:
https://gitlab.kitware.com/cmake/cmake/-/blob/v3.17.3/Modules/FindOpenMP.cmake#L298
Here is an example of the error:
/Applications/Xcode_11.5.app/.../cc -Xclang -fopenmp -I/usr/local/include ... csdp.o -L/usr/local/lib -llibomp ... -o csdp
ld: library not found for -llibomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
To clarify, this is only an issue for external projects. For cmake projects simply linking with OpenMP works fine.
If this isn't preferred, feel free to close this.