pcl icon indicating copy to clipboard operation
pcl copied to clipboard

Fix OpenMP on macOS

Open cybaol opened this issue 1 year ago • 5 comments

cybaol avatar Aug 24 '24 09:08 cybaol

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.

mvieth avatar Aug 25 '24 08:08 mvieth

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

valgur avatar Aug 25 '24 20:08 valgur

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.

cybaol avatar Sep 20 '24 08:09 cybaol

Could we adopt the way they do it from lighthouse - ie https://github.com/microsoft/LightGBM/blob/v4.5.0/CMakeLists.txt#L161-L183.

larshg avatar Oct 19 '24 19:10 larshg

Looks good and OpenMp is found again on CIs :+1:

larshg avatar Oct 20 '24 05:10 larshg