CMake module for Mathematica.

Overview

FindMathematica

FindMathematica is a CMake module that tries to find a Wolfram Language installation and provides CMake functions for its C/C++ interface.

Features

  • Works with Windows, Linux and OS X versions of the Wolfram Language.
  • Supports Wolfram Language versions from 5.2 to 13.0.
  • Supports Wolfram Language implementations Wolfram Mathematica, Wolfram|One, Wolfram Engine and Wolfram gridMathematica.
  • Finds include directories and libraries for LibraryLink (version 8 or later).
  • Finds include directories and libraries for WSTP (version 10 or later).
  • Finds installation directory and JAR file of J/Link.
  • Finds include directories and libraries for MathLink.
  • Finds installation directory of Wolfram MUnit testing package.
  • Provides exact version info for the Wolfram Language, LibraryLink, WSTP, MathLink, J/Link and MUnit.
  • Allows for running Wolfram Language code during CMake configure or build time.
  • Allows for running Wolfram Language code as a pre-link, pre-build or post-build action.
  • Allows for running Wolfram Language code in CMake test targets.
  • Allows for running Wolfram Language MUnit test files and suites as CMake test targets.
  • Supports generating C code from WSTP template files using wsprp executable.
  • Supports generating C code from MathLink template files using mprep executable.
  • Supports building dynamic libraries loadable with LibraryLink.
  • Supports generating stand-alone C code from Wolfram Language code with CCodeGenerator.
  • Provides CMake interface to Wolfram Language's Encode function.
  • Supports generating Wolfram Language documentation with the DocumentationBuild package.
  • Fully leverages CMake's cross-compiling support.

Requirements

Installation

Copy the directory CMake/Mathematica to the root directory of your CMake project. In the top-level CMakeList.txt file, add the module directory to the CMake module search path:

set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/Mathematica" ${CMAKE_MODULE_PATH})

Usage

To find the newest Wolfram Language installation in a CMake list file, run the find_package command:

find_package(Mathematica)

See the FindMathematica manual for more information.

Alternatives

In October 2020, Wolfram Research have released LibraryLinkUtilities as an open source project that provides modern C++ wrappers for conveniently wrapping Wolfram LibraryLink code.

Issues
  • Support for Wolfram Engine

    Support for Wolfram Engine

    Dear Sascha Kratky,

    I'm wondering whether FindMathematica could also support the "Free Wolfram Engine"?

    Personally, for license reason I can currently not use Mathematica and so I'm stuck to the "Free Wolfram Engine".

    Interestingly, the "Free Wolfram Engine" provides

    • a math kernel
    • the mcc compiler
    • MathLink
    • LibraryLink

    and many more. However, it does not provide the classic Mathematica notebook executable.

    Anyway, I guess a support for "Free Wolfram Engine" would in principle be possible and I guess also very useful in general. :)

    Best regards Alexander Voigt

    opened by Expander 2
  • Linking failue when libuuid is installed in a non-default directory

    Linking failue when libuuid is installed in a non-default directory

    Dear Sascha Kratky,

    a student reported an issue to me when building a LibraryLink library with FindMathematica.cmake. He uses the following configuration:

    Distributor ID: Ubuntu
    Description: Ubuntu 16.04.5 LTS
    Release: 16.04
    Codename: xenial
    Mathematica version: 10.3
    

    When building a LibraryLink library (Himalaya_LibraryLink.so), FindMathematica.cmake links libuuid to the shared library like so:

    /usr/bin/c++ -fPIC -O3 -DNDEBUG  -shared  -o Himalaya_LibraryLink.so CMakeFiles/Himalaya_LibraryLink.dir/source/LibraryLink/Himalaya_LibraryLink.cpp.o -Wl,-rpath,/home/thomas/Promotion/Himalaya/Himalaya-master/build:/home/thomas/Dokumente/Mathematica10.3/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions libHimalaya.so /home/thomas/Dokumente/Mathematica10.3/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/libML64i4.so -lstdc++ -lm -lpthread -lrt -ldl -luuid libDSZ.so
    /usr/bin/ld: cannot find -luuid
    collect2: error: ld returned 1 exit status
    

    This linking command fails and I believe it is because on this Ubuntu version libuuid is installed in the non-standard directories

    /lib/x86_64-linux-gnu/libuuid.so.1
    /lib/x86_64-linux-gnu/libuuid.so.1.3.0
    /lib/i386-linux-gnu/libuuid.so.1
    /lib/i386-linux-gnu/libuuid.so.1.3.0
    

    This issue can be fixed by creating a symlink in /usr/lib/:

    cd /usr/lib/
    sudo ln -s /lib/x86_64-linux-gnu/libuuid.so.1.3.0 libuuid.so
    

    But I believe a better solution would be to let FindMathematica.cmake search for libuuid and add its proper path to the linking command.

    With best regards, Alexander Voigt

    opened by Expander 2
  • Link failure of MathLink executable on Fedora when libuuid is not installed

    Link failure of MathLink executable on Fedora when libuuid is not installed

    Dear Sascha Kratky,

    we are using your FindMathematica module in to build a MathLink executable for GM2Calc. This works very nicely for all platforms, except Fedora: On Fedora we get a linker error when the MathLink executable (gm2calc.mx) is created and libuuid is not installed:

    /usr/bin/c++  -O2 -DNDEBUG  -rdynamic CMakeFiles/gm2calc.mx.dir/gm2calc.tm.c.o  -o ../bin/gm2calc.mx -Wl,-rpath,/usr/local/Wolfram/Mathematica/11.1/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions /usr/local/Wolfram/Mathematica/11.1/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/libML64i4.so -lstdc++ -lm -lpthread -lrt -ldl -luuid ../lib/libgm2calc.a
    /usr/bin/ld: cannot find -luuid
    

    It seems, that FindMathematica does not check that libuuid is installed on the system, although it links libuuid to the MathLInk executable.

    Probably this can be fixed within FindMathematica by requiring that libuuid is installed on the system.

    Best regards, Alexander Voigt

    opened by Expander 2
  • Wrong mathlink library selection in Mathematica 10.3

    Wrong mathlink library selection in Mathematica 10.3

    When using ${Mathematica_MathLink_LIBRARIES} cmake selects the following mathlink library /Applications/Mathematica.app/Contents/SystemFiles/Links/MathLink/DeveloperKit/MacOSX-x86-64/CompilerAdditions/AlternativeLibraries/mathlink.framework/mathlink in Mathematica 10.3. Unfortunately this library is linked against a non existing library /Volumes/Jenkins/workspace/MathLink.MacOSX-x86-64.release/scratch/CMake.build/lib/mathlink-libc++.framework/Versions/4.25/mathlink-libc++, which subsequently leads to a error when using the compiled executable. A solution could be to use the library under /Applications/Mathematica.app//Contents/Frameworks/mathlink.framework/mathlink.

    opened by kthr 2
  • Linking to libMLi3.a versus libMLi4.a on Mac OS X.

    Linking to libMLi3.a versus libMLi4.a on Mac OS X.

    On Mac OS X with Mathematica 10 I'd like to statically link my code to libMLi3.a instead of libMLi4.a because libMLi4.a requires also linking to CoreFoundation and seems to introduce a weird performance penalty on startup and shutdown. Setting Mathematica_USE_STATIC_LIBRARIES to TRUE seems to always find libMLi4.a. Is there a way to specifically select libMLi3.a instead?

    opened by rljacobson 2
  • Error with Mathematica 12.3.1 Apple ARM version

    Error with Mathematica 12.3.1 Apple ARM version

    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.

    opened by RobR16 2
  • Unknown CMake command

    Unknown CMake command "Mathematica_ADD_LIBRARY" on Raspberry Pi 3

    Dear @sakra ,

    I've found an issue with FindMathematica 3.3.0 on my Raspberry Pi 3 (Raspbian, based on Debian buster, 32-bit): CMake complains:

    Unknown CMake command "Mathematica_ADD_LIBRARY"
    

    I've setup the test repository which shows the setup and the error output here: https://github.com/Expander/test-FindMathematica If needed, I can paste more configuration files etc. to trace the issue.

    Best regards, Alexander Voigt

    opened by Expander 0
  • Variable Mathematica_uuid_LIBRARY is not checked

    Variable Mathematica_uuid_LIBRARY is not checked

    Dear @sakra ,

    a colleague of mine stumbled upon the issue with missing libuuid again.

    He has an Ubuntu machine with Mathematica 12. On this machine the package uuid-dev is not installed, so libuuid is not installed on the system.

    When he calls find_package(Mathematica COMPONENTS MathLink), he gets an error message of the form:

    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
    
    Please set them or make sure they are set and tested correctly in the CMake files:
    Mathematica_uuid_LIBRARY (ADVANCED)
        linked by target "gm2calc.mx" in directory /home/pathron/software/GM2Calc/src 
    

    If I interpret the error message correctly, it seems that the command

    find_library (Mathematica_uuid_LIBRARY uuid)
    

    inside FindMathematica.cmake fails to find libuuid on his system. In this case the variable Mathematica_uuid_LIBRARY is set to NOTFOUND. However, the script just continues without checking if libuuid has been found.

    If my interpretation is correct, then a possible fix would be to raise an error if libuuid has not been found.

    Many thanks in advance and best regards, Alexander Voigt

    P.S.: This issue has been found when running cmake in https://github.com/GM2Calc/GM2Calc

    opened by Expander 0
Releases(3.6.0)
  • 3.6.0(Dec 15, 2021)

    • Mathematica 13 compatibility
    • warn explicitly about common mistakes users make
    • fix for Mathematica installed in Windows docker container
    • fix broken launch services database search under OS X
    Source code(tar.gz)
    Source code(zip)
  • 3.5.0(May 21, 2021)

  • 3.4.0(Dec 19, 2020)

    • Mathematica 12.2 compatibility
    • add Mathematica_RUN_KERNEL_ON_CONFIGURE switch to control if FindMathematica is allowed to implicitly run the Mathematica kernel at CMake configuration time
    Source code(tar.gz)
    Source code(zip)
  • 3.3.0(Mar 25, 2020)

    • Mathematica 12.1 compatibility
    • remove Mathematica_SPLICE_C_CODE whose underlying Mathematica function Splice has been deprecated since Mathematica 10 and has been removed in Mathematica 12.1
    • add new variable Mathematica_JLink_JAVA_HOME, which contains the full path to Java SDK bundled with Mathematica
    Source code(tar.gz)
    Source code(zip)
  • 3.2.7(Feb 9, 2020)

  • 3.2.6(Feb 7, 2020)

  • 3.2.5(Apr 28, 2019)

    • Mathematica 12.0 compatibility
    • add libuuid to list of required runtime libraries under Linux
    • remove 32-bit Linux from supported system IDs for Mathematica versions >= 11.3
    Source code(tar.gz)
    Source code(zip)
  • 3.2.4(Mar 16, 2018)

  • 3.2.3(Sep 15, 2017)

    • Mathematica 11.2 compatibility
    • Mathematica 11.1 compatibility
    • add new variables for component runtime directories (e.g., Mathematica_MathLink_RUNTIME_LIBRARY_DIRS)
    Source code(tar.gz)
    Source code(zip)
  • 3.2.2(Sep 28, 2016)

  • 3.2.1(Aug 17, 2016)

    • Mathematica 11 compatibility
    • fix rpath handling for code generation examples under Linux and OS X
    • fix handling of Mathematica_USE_LIBCXX_LIBRARIES for Mathematica 10.4 and 11
    Source code(tar.gz)
    Source code(zip)
  • 3.2.0(Mar 20, 2016)

    • Mathematica 10.4 compatibility
    • add variable Mathematica_MathLink_FIND_VERSION_MINOR (requested MathLink revision)
    • add variable Mathematica_WSTP_FIND_VERSION_MINOR (requested WSTP revision)
    • rename Mathematica_JLink_LIBRARY to Mathematica_JLink_RUNTIME_LIBRARY
    Source code(tar.gz)
    Source code(zip)
  • 3.1.4(Oct 18, 2015)

  • 3.1.3(Oct 10, 2015)

    • add timestamp check for HTML docu generation
    • add JAVACMD option to Mathematica_ADD_DOCUMENTATION
    • use java_home to find Java runtime executable under OS X
    • remove obsolete code
    • documentation updates
    Source code(tar.gz)
    Source code(zip)
  • 3.1.2(Jul 25, 2015)

  • 3.1.1(Apr 21, 2015)

    • fix Mathematica 10.1 compatibility issues
    • do not use broken -script option for Mathematica earlier than 10.0
    • add variables Mathematica_LibraryLink_PACKAGE_FILE and Mathematica_LibraryLink_PACKAGE_DIR
    • copy standard examples to binary directory instead of source directory
    • add CMake tests for new LibraryLink examples
    Source code(tar.gz)
    Source code(zip)
  • 3.1.0(Apr 6, 2015)

    • add compatibility with Mathematica 10.1
    • fix CMake 3.2 compatibility issues
    • require at least CMake 2.8.12
    • remove obsolete code required for CMake versions older than 2.8.12
    • prefer modern executable names (i.e., wolfram.exe) over classic ones (i.e., math.exe)
    • add parameter LINK_MODE to some functions (see manual)
    • manual updates
    Source code(tar.gz)
    Source code(zip)
  • 3.0.3(Feb 11, 2015)

    • work around cmd.exe command line length limit when running Mathematica code
    • fix cmd.exe command line quoting issues
    • fix for running MUnit tests
    • more robust cache cleaning of invalid WSTP related variables
    • print message when DocumentationBuild package is not installed
    Source code(tar.gz)
    Source code(zip)
Owner
Sascha Kratky
[](){}();
Sascha Kratky
unmaintained - CMake module to activate certain C++ standard, feature checks and appropriate automated workarounds - basically an improved version of cmake-compile-features

Compatibility This library provides an advanced target_compile_features() and write_compiler_detection_header(). The problem with those is that they a

Jonathan Müller 72 Apr 14, 2022
[CMake] [BSD-2] CMake module to find ICU

FindICU.cmake A CMake module to find International Components for Unicode (ICU) Library Note that CMake, since its version 3.7.0, includes a FindICU m

julp 29 Apr 26, 2022
📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Setup-free CMake dependency management CPM.cmake is a CMake script that adds dependency management capabilities to CMake. It's built as a thin wrapper

CPM.cmake 1.2k Jun 27, 2022
CMake checks cache helper modules – for fast CI CMake builds!

cmake-checks-cache Cross platform CMake projects do platform introspection by the means of "Check" macros. Have a look at CMake's How To Write Platfor

Cristian Adam 58 May 22, 2022
CMake scripts for painless usage of SuiteSparse+METIS from Visual Studio and the rest of Windows/Linux/OSX IDEs supported by CMake

CMake scripts for painless usage of Tim Davis' SuiteSparse (CHOLMOD,UMFPACK,AMD,LDL,SPQR,...) and METIS from Visual Studio and the rest of Windows/Lin

Jose Luis Blanco-Claraco 379 Jun 23, 2022
cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-font-lock - Advanced, type aware, highlight support for CMake

Anders Lindgren 37 Dec 30, 2021
cmake-avr - a cmake toolchain for AVR projects

cmake-avr - a cmake toolchain for AVR projects Testing the example provided The toolchain was created and tested within the following environment: Lin

Matthias Kleemann 156 Jun 20, 2022
Make CMake less painful when trying to write Modern Flexible CMake

Izzy's eXtension Modules IXM is a CMake library for writing Modern flexible CMake. This means: Reducing the amount of CMake written Selecting reasonab

IXM 99 Feb 14, 2022
curl cmake module libcurl build with msvc x86

curl-msvc Infomation curl cmake module libcurl build with MSVC10.0 arch (x86 | i386) source from https://github.com/curl/curl tags: curl-7_79_1 Usage

Jason Payne 0 May 16, 2022
CMake module for downloading an external project's source at configure time

DownloadProject Platform Build status Linux Mac OSX Windows (VS2015) This repository contains a generalized implementation for downloading an external

Crascit Pty Ltd 423 May 5, 2022
CMake module to speed up builds.

cotire Cotire (compile time reducer) is a CMake module that speeds up the build process of CMake based build systems by fully automating techniques as

Sascha Kratky 1.3k Jun 15, 2022
CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp

FindIDL CMake module for building IDL files with MIDL and generating CLR DLL using Tlbimp. Introduction Requirements Usage find_package() add_idl() ad

Apriorit Inc. 14 Dec 21, 2021
CMake module for building Windows Installer packages with WiX toolset

FindWiX CMake module for building Windows Installer packages with WiX toolset Introduction Requirements Usage find_package() wix_add_project() WiX com

Apriorit Inc. 10 Dec 20, 2021
CMake find module for Intel Threading Building Blocks

FindTBB Module FindTBB is a CMake find package module for Intel® Threading Building Blocks (TBB). Usage The signature of the TBB find module in CMake

Justus Calvin 80 Sep 22, 2021
CMake project for BL602 RISC-V processor

bl602_cmake_base CMake project for BL602 RISC-V processor How to build NOTE : This project uses a pre-compiled version of the Buffalo SDK (bl_iot_sdk)

null 9 Jan 6, 2022
A CMake toolchain file for iOS, macOS, watchOS & tvOS C/C++/Obj-C++ development

A CMake toolchain file for iOS, macOS, watchOS & tvOS C/C++/Obj-C++ development

Alexander Widerberg 1.3k Jun 29, 2022
NeoWorld is a resampler using the CMake build system

NeoWorld is a resampler using the CMake build system. It's designed for utsu, OpenUTAU, and UTAU.

null 4 Jun 24, 2022
A CMake addon that avoids you writing boilerplate code for resource management.

SHader INJ(I)ector SHINJI (originally SHader INJector) is a CMake addon that avoids you writing boilerplate code for resource management and exposes s

Lorenzo Rutayisire 6 Mar 21, 2022
A CMake starter template using CPM

Cmake Starter About A lightweight Cmake project meant for a binary application (not a shared library), tests with catch2 are configured, CPM is the pa

Matt Williams 1 Mar 24, 2022