Page MenuHome

OpenMP support for macOS
ClosedPublic

Authored by Arto Kitula (akitula) on Jan 25 2019, 10:43 PM.

Details

Summary

Use SVN openmp library on macOS. Force openmp flags as CMake below 3.12 doesn't know about AppleClang on FindOpenMP and even that doesn't work well if openmp is on custom directory location.

This ofcoz needs that openmp library is uploaded to svn...

Diff Detail

Repository
rB Blender

Event Timeline

Added needed build_environment changes and using mkdir + cp instead of ditto.

Looks fine, I'll commit this with two changes:

  • Fix indentation to use tabs.
  • Move platform specific code into platform_apple.cmake.
This revision is now accepted and ready to land.Jan 26 2019, 3:47 PM
This revision was automatically updated to reflect the committed changes.

Is it just me or did this break builds with Xcode? Builds using make work fine for me, but when using Xcode projects, datatoc can't launch because it can't find libomp.dylib.

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    DYLD, [0x1] Library missing

Application Specific Information:
dyld: launch, loading dependent libraries

Dyld Error Message:
  Library not loaded: @executable_path/../Resources/lib/libomp.dylib
  Referenced from: /Users/USER/*/datatoc
  Reason: image not found

Is it just me or did this break builds with Xcode? Builds using make work fine for me, but when using Xcode projects, datatoc can't launch because it can't find libomp.dylib.

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    DYLD, [0x1] Library missing

Application Specific Information:
dyld: launch, loading dependent libraries

Dyld Error Message:
  Library not loaded: @executable_path/../Resources/lib/libomp.dylib
  Referenced from: /Users/USER/*/datatoc
  Reason: image not found

Shouldn't break. See line 397 on platform_apple.cmake.

edit: or.. was it on xcodebuild that it has one directory deeper.. Release / Debug... then there is reason.

Yes, projects created with cmake -G Xcode create the datatoc and other binaries in a subdirectory named after the current inside bin.

I suggest the following change to platform_apple.cmake, this makes both Xcode and make builds work for me:

diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake
index 2515867d442..207499fd188 100644
--- a/build_files/cmake/platform/platform_apple.cmake
+++ b/build_files/cmake/platform/platform_apple.cmake
@@ -394,9 +394,14 @@ if(WITH_OPENMP)
                set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${LIBDIR}/openmp/lib -lomp")
 
                # Copy libomp.dylib to allow executables like datatoc to work.
+               if(${CMAKE_GENERATOR} MATCHES "Xcode")
+                       set(LIBOMP_DEST ${CMAKE_BINARY_DIR}/bin/Resources/lib)
+               else()
+                       set(LIBOMP_DEST ${CMAKE_BINARY_DIR}/Resources/lib)
+               endif()
                execute_process(
-                       COMMAND mkdir -p ${CMAKE_BINARY_DIR}/Resources/lib
-                       COMMAND cp -p ${LIBDIR}/openmp/lib/libomp.dylib ${CMAKE_BINARY_DIR}/Resources/lib/libomp.dylib
+                       COMMAND mkdir -p ${LIBOMP_DEST}
+                       COMMAND cp -p ${LIBDIR}/openmp/lib/libomp.dylib ${LIBOMP_DEST}/libomp.dylib
                )
        endif()
 endif()