sakra / FindMathematica

CMake module for Mathematica.
MIT License
59 stars 14 forks source link

Error with Mathematica 12.3.1 Apple ARM version #8

Open RobR16 opened 3 years ago

RobR16 commented 3 years ago

Hello, I think 12.3.1 was the first macOS Mathematica version with native ARM/Silicon support, and after upgrading to it I get the following error in a program that uses FindMathematica in its cmake-list:

"could NOT find Mathematica_WolframLibrary (missing: Mathematica_WolframLibrary_LIBRARY) (found version "6") -- Could NOT find Mathematica (missing: Mathematica_WolframLibrary_LIBRARY) (found version "12.3.1")"

After looking in the cmakeCACHE file, I found that it did not find the Wolfram Runtime Library (correct path: "/Applications/Mathematica.app/Contents/SystemFiles/Libraries/MacOSX-ARM64/libWolframRTL.dylib" ),

and the cache file contains the entry //Last value of Mathematica_SYSTEM_IDS. Mathematica_SYSTEM_IDS_LAST:INTERNAL=MacOSX-x86-64

which I guess could be problematic. It seems like in most other relevant paths it correctly replaced MacOSX-x86-64 by /MacOSX-ARM64. I will try to fix it by myself, but if you could make FindMathematica compatible with the 12.3.1 version in a clean way, I guess it would be greatly appreciated by many.

windfolgen commented 2 years ago

Hello, I have exactly the same problem with you and I don't know how to solve it. Is it OK to replace the wrong KEYs manually? Have you found a clean way to solve it? I really appreciate it if you or someone else could help.

windfolgen commented 2 years ago

I think I may find how to resolve this problem. The solution is simple: just add below syntax in the CMakeList.txt before compiling it set(CMAKE_OSX_ARCHITECTURE arm64) The reason may be that default value for CMAKE_OSX_ARCHITECTURE is null, so you should set it first. In the FindMathematica.cmake you can find the following macro macro (_get_system_IDs _outSystemIDs) if (WIN32 OR CYGWIN) ... elseif (APPLE) set (${_outSystemIDs} "") if (CMAKE_OSX_ARCHITECTURES) # determine System ID from specified architectures ... else() # determine System ID by checking endianness and pointer size TEST_BIG_ENDIAN(_isBigEndian) if (_isBigEndian) ... else () if (CMAKE_SIZEOF_VOID_P EQUAL 8) set (${_outSystemIDs} "MacOSX-x86-64") else () set (${_outSystemIDs} "MacOSX-x86") endif() endif() endif() elseif (UNIX) ... else() ... endmacro(_get_system_IDs) If you don't set CMAKE_OSX_ARCHITECTURES, then it will determine by checking endianness and pointer size. Since apple M1 is little endian, it will check CMAKE_SIZEOF_VOID_P and further determine the result. However, it only provide two choices "MacOSX-x86-64" and "MacOSX-x86". So this will give you a wrong value on a MacOSX-ARM64 machine. If CMAKE_OSX_ARCHITECTURES is set, this problem won't appear. I hope this can help explain why it may go wrong on apple ARM machine.