pcl
pcl copied to clipboard
Fix OpenMP on macOS
Hi, could you explain this a bit, please? Do you know why OpenMP is currently not found on macOS? Shouldn't the FindOpenMP.cmake script handle this? Hardcoding the path /usr/local/opt/libomp/... seems like a bad idea.
By the way, PCL currently has its own FindOpenMP.cmake file, but we are planning to remove that so that CMake's file of the same name is used instead: https://github.com/PointCloudLibrary/pcl/pull/6100 I don't know if that changes anything regarding this pull request, I just wanted to mention it.
LightGBM does something similar to support the use of OpenMP via Homebrew: https://github.com/microsoft/LightGBM/blob/v4.5.0/CMakeLists.txt#L161-L183
I would suggest following their approach as it only uses Homebrew as a fallback and does not hard-code any paths.
One other suggestion would be to avoid the use of set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") in favor of link_libraries(OpenMP::OpenMP_CXX), if possible. The latter makes it easier to provide OpenMP for Clang and AppleClang via a package manager without patching or workarounds. Any non-global linker and include paths cannot be reliably provided via the compiler flags alone.
Specifically, I'm currently working towards getting a better LLVM OpenMP support to Conan and Vcpkg to fill the gap and it would be helpful in that context:
- https://github.com/conan-io/conan-center-index/pull/24584
- https://github.com/microsoft/vcpkg/pull/39389
libomp is keg-only, which means it was not symlinked into /usr/local,
because it can override GCC headers and result in broken builds.
So must specify manually.
Could we adopt the way they do it from lighthouse - ie https://github.com/microsoft/LightGBM/blob/v4.5.0/CMakeLists.txt#L161-L183.
Looks good and OpenMp is found again on CIs :+1: