├── .gitattributes ├── .gitignore ├── CMake └── Mathematica │ ├── FindMathematica.cmake │ ├── FindMathematicaDocumentationBuild.cmake.in │ ├── FindMathematicaTestDriver.cmd │ └── FindMathematicaTestDriver.sh ├── CMakeLists.txt ├── CodeGenerationExamples ├── CMakeLists.txt ├── compute.m ├── compute_main.c ├── functions.c └── functions.m ├── DocumentationExamples ├── CMakeLists.txt └── English │ ├── Guides │ └── GuidePage.nb │ ├── ReferencePages │ └── Symbols │ │ └── SymbolPage.nb │ └── Tutorials │ └── TutorialPage.nb ├── HISTORY.md ├── JLinkExamples ├── .gitignore ├── AddTwo.java ├── CMakeLists.txt ├── FormatArray.java └── FormatArrayTest.m ├── LICENSE ├── LibraryLinkExamples ├── .gitignore ├── CMakeLists.txt ├── demo_callback.m ├── demo_managed_test.m ├── demo_numericarray_test.m ├── demo_shared.m ├── demo_sparse.m ├── demo_string_test.m └── demo_test.m ├── MANUAL.md ├── MUnitExamples ├── CMakeLists.txt ├── UnitsTests.mt ├── inputtest.mt ├── test.mt └── testsuite.mt ├── MathLinkExamples ├── .gitignore ├── CMakeLists.txt ├── bitopsTest.m └── test_input.txt ├── MathematicaExamples ├── CMakeLists.txt ├── demo.m └── directories.m ├── README.md └── WSTPExamples ├── .gitignore ├── CMakeLists.txt ├── bitopsTest.m └── test_input.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sh eol=lf 2 | bootstrap eol=lf 3 | configure eol=lf 4 | *.[1-9] eol=lf 5 | 6 | *.bat eol=crlf 7 | *.cmd eol=crlf 8 | *.vbs eol=crlf 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ignore CMake build directories 2 | *build*/ 3 | .DS_Store 4 | .project 5 | .vs 6 | .vscode 7 | .idea 8 | -------------------------------------------------------------------------------- /CMake/Mathematica/FindMathematicaDocumentationBuild.cmake.in: -------------------------------------------------------------------------------- 1 | # FindMathematica @Mathematica_CMAKE_MODULE_VERSION@ documentation build script 2 | 3 | # JAVACMD is an environment variable that points to the full path to the Java runtime executable 4 | # used by the Apache Ant wrapper scripts 5 | set (ENV{JAVACMD} "@_option_JAVACMD@") 6 | 7 | set (Mathematica_KERNEL_EXECUTABLE "@Mathematica_KERNEL_EXECUTABLE@") 8 | set (Mathematica_ANT_EXECUTABLE "@Mathematica_ANT_EXECUTABLE@") 9 | set (Mathematica_JLink_PACKAGE_DIR "@Mathematica_JLink_PACKAGE_DIR@") 10 | set (Mathematica_DocumentationBuild_PACKAGE_DIR "@Mathematica_DocumentationBuild_PACKAGE_DIR@") 11 | set (Mathematica_DEBUG "@Mathematica_DEBUG@") 12 | 13 | set (DOCU_INPUT_DIRECTORY "@_option_INPUT_DIRECTORY@") 14 | set (DOCU_OUTPUT_DIRECTORY "@_option_OUTPUT_DIRECTORY@") 15 | set (DOCU_TYPE "@_option_DOCUMENTATION_TYPE@") 16 | set (DOCU_LANGUAGE "@_option_LANGUAGE@") 17 | set (DOCU_APP_NAME "@_option_APPLICATION_NAME@") 18 | set (CHECK_TIMESTAMPS "@_option_CHECK_TIMESTAMPS@") 19 | 20 | function(_to_native_path _inPath _outPathVariable) 21 | if (CYGWIN) 22 | execute_process( 23 | COMMAND cygpath "--mixed" "${_inPath}" TIMEOUT 5 24 | OUTPUT_VARIABLE ${_outPathVariable} OUTPUT_STRIP_TRAILING_WHITESPACE) 25 | elseif (CMAKE_HOST_WIN32) 26 | string (REPLACE "/" "\\" ${_outPathVariable} "${_inPath}") 27 | else() 28 | # use CMake path literally 29 | set (${_outPathVariable} "${_inPath}") 30 | endif() 31 | set (${_outPathVariable} "${${_outPathVariable}}" PARENT_SCOPE) 32 | endfunction() 33 | 34 | set (_buildDocu TRUE) 35 | # handle CHECK_TIMESTAMPS option 36 | if (CHECK_TIMESTAMPS AND EXISTS "${DOCU_OUTPUT_DIRECTORY}") 37 | if (DOCU_TYPE MATCHES "[Nn]otebook") 38 | file (GLOB_RECURSE _docuSourceNBs RELATIVE "${DOCU_INPUT_DIRECTORY}" "${DOCU_INPUT_DIRECTORY}/*.nb") 39 | file (GLOB_RECURSE _docuBinaryNBs RELATIVE "${DOCU_OUTPUT_DIRECTORY}" "${DOCU_OUTPUT_DIRECTORY}/*.nb") 40 | if (_docuBinaryNBs) 41 | set (_docuNBs ${_docuSourceNBs} ${_docuBinaryNBs}) 42 | list (REMOVE_DUPLICATES _docuNBs) 43 | set (_docuNBTrigger "") 44 | foreach (_docuNB ${_docuNBs}) 45 | if ("${DOCU_INPUT_DIRECTORY}/${_docuNB}" IS_NEWER_THAN "${DOCU_OUTPUT_DIRECTORY}/${_docuNB}") 46 | list (APPEND _docuNBTrigger "${_docuNB}") 47 | list (LENGTH _docuNBTrigger _len) 48 | if (_len GREATER 10) 49 | # stop if many out-of-date files have been found 50 | break() 51 | endif() 52 | endif() 53 | endforeach() 54 | if (_docuNBTrigger) 55 | message (STATUS "Out-of-date ${DOCU_APP_NAME} Mathematica documentation notebooks: ${_docuNBTrigger}") 56 | else() 57 | message (STATUS "Built ${DOCU_APP_NAME} Mathematica ${DOCU_TYPE} documentation is up-to-date") 58 | set (_buildDocu FALSE) 59 | endif() 60 | endif() 61 | elseif (DOCU_TYPE MATCHES "HTML") 62 | file (GLOB_RECURSE _docuSourceNBs RELATIVE "${DOCU_INPUT_DIRECTORY}" "${DOCU_INPUT_DIRECTORY}/*.nb") 63 | file (GLOB_RECURSE _docuBinaryHTMLs RELATIVE "${DOCU_OUTPUT_DIRECTORY}" "${DOCU_OUTPUT_DIRECTORY}/*.html") 64 | if (_docuBinaryHTMLs) 65 | set (_docuNBTrigger "") 66 | foreach (_docuNB ${_docuSourceNBs}) 67 | get_filename_component(_docuBaseName "${_docuNB}" NAME_WE) 68 | string (REGEX MATCHALL "[^;]+/${_docuBaseName}\\.html" _docuHTMLNames "${_docuBinaryHTMLs}") 69 | if (_docuHTMLNames) 70 | foreach (_docuHTMLName ${_docuHTMLNames}) 71 | if ("${DOCU_INPUT_DIRECTORY}/${_docuNB}" IS_NEWER_THAN "${DOCU_OUTPUT_DIRECTORY}/${_docuHTMLName}") 72 | list (APPEND _docuNBTrigger "${_docuNB}") 73 | break() 74 | endif() 75 | endforeach() 76 | else() 77 | # no corresponding HTML document 78 | list (APPEND _docuNBTrigger "${_docuNB}") 79 | endif() 80 | list (LENGTH _docuNBTrigger _len) 81 | if (_len GREATER 10) 82 | # stop if many out-of-date files have been found 83 | break() 84 | endif() 85 | endforeach() 86 | if (_docuNBTrigger) 87 | message (STATUS "Out-of-date ${DOCU_APP_NAME} Mathematica documentation notebooks: ${_docuNBTrigger}") 88 | else() 89 | message (STATUS "Built ${DOCU_APP_NAME} Mathematica ${DOCU_TYPE} documentation is up-to-date") 90 | set (_buildDocu FALSE) 91 | endif() 92 | endif() 93 | endif() 94 | endif() 95 | 96 | if (_buildDocu) 97 | # clean previously built documentation files 98 | file (REMOVE_RECURSE "${DOCU_OUTPUT_DIRECTORY}") 99 | file (MAKE_DIRECTORY "${DOCU_OUTPUT_DIRECTORY}") 100 | get_filename_component(_appPath "${Mathematica_DocumentationBuild_PACKAGE_DIR}" DIRECTORY) 101 | string (TOLOWER "${DOCU_TYPE}.xml" _buildFileName) 102 | set (_buildFile "${Mathematica_DocumentationBuild_PACKAGE_DIR}/SystemFiles/ant/Build/${_buildFileName}") 103 | _to_native_path ("${Mathematica_ANT_EXECUTABLE}" _antExecutableNative) 104 | _to_native_path ("${_buildFile}" _buildFileNative) 105 | _to_native_path ("${_appPath}" _appPathNative) 106 | _to_native_path ("${Mathematica_KERNEL_EXECUTABLE}" _kernelExecutableNative) 107 | _to_native_path ("${Mathematica_JLink_PACKAGE_DIR}" _jlinkPathNative) 108 | _to_native_path ("${DOCU_INPUT_DIRECTORY}" _inputDirNative) 109 | _to_native_path ("${DOCU_OUTPUT_DIRECTORY}" _outputDirNative) 110 | set (_cmd COMMAND "${_antExecutableNative}") 111 | list (APPEND _cmd "-buildfile" "${_buildFileNative}") 112 | list (APPEND _cmd "-DappPath=${_appPathNative}") 113 | list (APPEND _cmd "-Dapp.name=${DOCU_APP_NAME}") 114 | list (APPEND _cmd "-DmathExe=${_kernelExecutableNative}") 115 | list (APPEND _cmd "-Djlinkpath=${_jlinkPathNative}") 116 | list (APPEND _cmd "-DinputDir=${_inputDirNative}") 117 | list (APPEND _cmd "-DoutputDir=${_outputDirNative}") 118 | list (APPEND _cmd "-Dlanguage=${DOCU_LANGUAGE}") 119 | list (APPEND _cmd "-DincludeLinkTrails=False") 120 | list (APPEND _cmd "-Dlocal=True") 121 | list (APPEND _cmd "-DcompleteHTMLQ=True") 122 | if (Mathematica_DEBUG) 123 | list (APPEND _cmd "-Ddebug=True") 124 | else() 125 | list (APPEND _cmd "-Ddebug=False") 126 | endif() 127 | list (APPEND _cmd RESULT_VARIABLE _result) 128 | if (Mathematica_DEBUG) 129 | message (STATUS "execute_process: ${_cmd}") 130 | endif() 131 | execute_process(${_cmd}) 132 | message(STATUS "${DOCU_APP_NAME} ${DOCU_TYPE} generation result=${_result}") 133 | endif() 134 | -------------------------------------------------------------------------------- /CMake/Mathematica/FindMathematicaTestDriver.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem FindMathematica test driver script for Windows 3 | 4 | setlocal enabledelayedexpansion 5 | 6 | rem echo !CMDCMDLINE! 7 | rem echo !PATH! 8 | 9 | set "TEST_NAME=%~1" 10 | set "TEST_CONFIGURATION=%~2" 11 | set "TEST_INPUT_OPTION=%~3" 12 | if "!TEST_INPUT_OPTION!" == "input" ( 13 | set "TEST_INPUT=%~4" 14 | set "TEST_EXECUTABLE=%~5" 15 | shift 16 | shift 17 | shift 18 | shift 19 | shift 20 | shift 21 | ) else if "!TEST_INPUT_OPTION!" == "inputfile" ( 22 | set "TEST_INPUT_FILE=%~4" 23 | set "TEST_EXECUTABLE=%~5" 24 | shift 25 | shift 26 | shift 27 | shift 28 | shift 29 | shift 30 | ) else ( 31 | set "TEST_EXECUTABLE=%~4" 32 | shift 33 | shift 34 | shift 35 | shift 36 | shift 37 | ) 38 | 39 | if "!TEST_INPUT_OPTION!" == "input" ( 40 | echo !TEST_INPUT! | "!TEST_EXECUTABLE!" %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 41 | ) else if "!TEST_INPUT_OPTION!" == "inputfile" ( 42 | "!TEST_EXECUTABLE!" < "!TEST_INPUT_FILE!" %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 43 | ) else ( 44 | "!TEST_EXECUTABLE!" %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 45 | ) 46 | -------------------------------------------------------------------------------- /CMake/Mathematica/FindMathematicaTestDriver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # FindMathematica test driver script for UNIX systems 3 | 4 | #logger -- $# "$@" 5 | #logger -- LD_LIBRARY_PATH=$LD_LIBRARY_PATH 6 | #logger -- DYLD_FRAMEWORK_PATH=$DYLD_FRAMEWORK_PATH 7 | #logger -- DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH 8 | 9 | export TEST_NAME=$1 10 | export TEST_CONFIGURATION=$2 11 | export TEST_INPUT_OPTION=$3 12 | 13 | if [ "$TEST_INPUT_OPTION" = "input" ] 14 | then 15 | export TEST_INPUT=$4 16 | export TEST_EXECUTABLE=$5 17 | elif [ "$TEST_INPUT_OPTION" = "inputfile" ] 18 | then 19 | export TEST_INPUT_FILE=$4 20 | export TEST_EXECUTABLE=$5 21 | else 22 | export TEST_EXECUTABLE=$4 23 | fi 24 | 25 | if [ "$OSTYPE" = "cygwin" ] 26 | then 27 | # make sure that executable has the right format under Cygwin 28 | export TEST_EXECUTABLE="$(/usr/bin/cygpath --unix "$TEST_EXECUTABLE")" 29 | fi 30 | 31 | if [ "$TEST_INPUT_OPTION" = "input" ] 32 | then 33 | echo "$TEST_INPUT" | exec "$TEST_EXECUTABLE" "${@:6}" 34 | elif [ "$TEST_INPUT_OPTION" = "inputfile" ] 35 | then 36 | exec < "$TEST_INPUT_FILE" "$TEST_EXECUTABLE" "${@:6}" 37 | else 38 | exec "$TEST_EXECUTABLE" "${@:5}" 39 | fi 40 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # FindMathematica example project 2 | 3 | cmake_minimum_required(VERSION 3.10..3.31) 4 | 5 | project (Mathematica-project) 6 | 7 | set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/Mathematica") 8 | 9 | set (CMAKE_VERBOSE_MAKEFILE OFF) 10 | set (CMAKE_COLOR_MAKEFILE ON) 11 | set (CMAKE_SKIP_ASSEMBLY_SOURCE_RULES ON) 12 | set (CMAKE_SKIP_PREPROCESSED_SOURCE_RULES ON) 13 | set (CMAKE_INCLUDE_CURRENT_DIR ON) 14 | set (CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) 15 | if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) 16 | set (CMAKE_BUILD_TYPE Debug) 17 | endif() 18 | set_property(GLOBAL PROPERTY USE_FOLDERS 1) 19 | if (NOT CMAKE_VERSION VERSION_LESS "3.1") 20 | # compile all example C++ code as C++11 21 | set (CMAKE_CXX_STANDARD 11) 22 | endif() 23 | 24 | # default settings for options that affect search 25 | #set (Mathematica_USE_STATIC_LIBRARIES OFF) 26 | #set (Mathematica_USE_MINIMAL_LIBRARIES ON) 27 | #set (Mathematica_USE_LIBCXX_LIBRARIES ON) 28 | #set (Mathematica_MathLink_FIND_VERSION_MAJOR 3) 29 | #set (Mathematica_WSTP_FIND_VERSION_MAJOR 3) 30 | #set (Mathematica_DEBUG OFF) 31 | #set (Mathematica_RUN_KERNEL_ON_CONFIGURE ON) 32 | 33 | # finds newest Mathematica installation and its default components 34 | find_package(Mathematica) 35 | 36 | # finds Mathematica 10.0.2 installation and required components 37 | #find_package(Mathematica 10.0.2 EXACT REQUIRED MathLink WSTP JLink WolframLibrary) 38 | 39 | # finds Mathematica >= 11 installation and optional components 40 | #find_package(Mathematica 11 COMPONENTS MathLink JLink) 41 | 42 | # find Java and use the Java installation bundled with Mathematica 43 | if (Mathematica_JLink_JAVA_HOME AND NOT APPLE) 44 | set (JAVA_HOME "${Mathematica_JLink_JAVA_HOME}") 45 | endif() 46 | find_package(Java 1.8 COMPONENTS Development) 47 | 48 | if (Mathematica_MathLink_DEFINITIONS) 49 | add_definitions(${Mathematica_MathLink_DEFINITIONS}) 50 | endif() 51 | 52 | if (Mathematica_WSTP_DEFINITIONS) 53 | add_definitions(${Mathematica_WSTP_DEFINITIONS}) 54 | endif() 55 | 56 | enable_testing() 57 | 58 | # helper macro which adds convenience target which lets you run tests from IDE 59 | macro (add_convenience_test_target _targetName _testRegEx) 60 | if (CMAKE_CONFIGURATION_TYPES) 61 | add_custom_target("${_targetName}" 62 | COMMAND 63 | ${CMAKE_CTEST_COMMAND} -V --force-new-ctest-process 64 | --tests-regex "${_testRegEx}" 65 | --build-config "${CMAKE_CFG_INTDIR}") 66 | else() 67 | add_custom_target("${_targetName}" 68 | COMMAND 69 | ${CMAKE_CTEST_COMMAND} -V --force-new-ctest-process 70 | --tests-regex "${_testRegEx}") 71 | endif() 72 | set_target_properties("${_targetName}" PROPERTIES FOLDER "Tests") 73 | endmacro() 74 | 75 | if (${Mathematica_FOUND}) 76 | message(STATUS "Mathematica Version ${Mathematica_VERSION}") 77 | # Mathematica_SYSTEM_IDS contains the list of Mathematica platform system IDs that the 78 | # project is being compiled for. This usually contains just one entry (e.g., "Windows"). 79 | # It may contain multiple entries if we are building a universal binary under macOS 80 | # (e.g., "MacOSX-x86-64;MacOSX-ARM64"). 81 | message(STATUS "Mathematica Target System IDs ${Mathematica_SYSTEM_IDS}") 82 | # Mathematica_HOST_SYSTEM_IDS is the list of Mathematica platform system IDs that can 83 | # run on the build host. If we are executing the CMake build under a 64-bit version of 84 | # Windows this would be "Windows-x86-64;Windows". Under a 32-bit version of Windows this 85 | # would be just "Windows". 86 | message(STATUS "Mathematica Host System IDs ${Mathematica_HOST_SYSTEM_IDS}") 87 | # Mathematica_BASE_DIR is the directory for system-wide files to be loaded by Mathematica 88 | message(STATUS "Mathematica Base Directory ${Mathematica_BASE_DIR}") 89 | # Mathematica_USERBASE_DIR is the directory for user-specific files to be loaded by Mathematica 90 | message(STATUS "Mathematica User Base Directory ${Mathematica_USERBASE_DIR}") 91 | message(STATUS "Mathematica runtime library dirs: ${Mathematica_RUNTIME_LIBRARY_DIRS}") 92 | message(STATUS "Mathematica runtime library dirs debug: ${Mathematica_RUNTIME_LIBRARY_DIRS_DEBUG}") 93 | add_subdirectory(MathematicaExamples) 94 | if (${Mathematica_JLink_FOUND}) 95 | add_subdirectory(DocumentationExamples) 96 | endif() 97 | endif() 98 | 99 | if (${Mathematica_WolframLibrary_FOUND}) 100 | # copy LibraryLink example files from Mathematica installation to source directory 101 | if (EXISTS "${Mathematica_LibraryLink_PACKAGE_DIR}/LibraryResources") 102 | file (GLOB_RECURSE _LibraryLinkExamples 103 | "${Mathematica_LibraryLink_PACKAGE_DIR}/LibraryResources/*.c" 104 | "${Mathematica_LibraryLink_PACKAGE_DIR}/LibraryResources/*.cxx") 105 | file (COPY ${_LibraryLinkExamples} 106 | DESTINATION "${CMAKE_BINARY_DIR}/LibraryLinkExamples" 107 | NO_SOURCE_PERMISSIONS) 108 | add_subdirectory(LibraryLinkExamples) 109 | endif() 110 | add_subdirectory(CodeGenerationExamples) 111 | endif() 112 | 113 | if (${Mathematica_MathLink_FOUND}) 114 | # copy MathLink example files from Mathematica installation to source directory 115 | if (EXISTS "${Mathematica_MathLink_HOST_ROOT_DIR}/MathLinkExamples") 116 | file (GLOB_RECURSE _MathLinkExamples 117 | "${Mathematica_MathLink_HOST_ROOT_DIR}/MathLinkExamples/*.tm" 118 | "${Mathematica_MathLink_HOST_ROOT_DIR}/MathLinkExamples/*.c" 119 | "${Mathematica_MathLink_HOST_ROOT_DIR}/MathLinkExamples/*.cxx") 120 | file (COPY ${_MathLinkExamples} 121 | DESTINATION "${CMAKE_BINARY_DIR}/MathLinkExamples" 122 | NO_SOURCE_PERMISSIONS) 123 | add_subdirectory(MathLinkExamples) 124 | endif() 125 | endif() 126 | 127 | if (${Mathematica_WSTP_FOUND}) 128 | # copy WSTP example files from Mathematica installation to source directory 129 | if (EXISTS "${Mathematica_WSTP_HOST_ROOT_DIR}/WSTPExamples") 130 | file (GLOB_RECURSE _WSTPExamples 131 | "${Mathematica_WSTP_HOST_ROOT_DIR}/WSTPExamples/*.tm" 132 | "${Mathematica_WSTP_HOST_ROOT_DIR}/WSTPExamples/*.c" 133 | "${Mathematica_WSTP_HOST_ROOT_DIR}/WSTPExamples/*.cxx") 134 | file (COPY ${_WSTPExamples} 135 | DESTINATION "${CMAKE_BINARY_DIR}/WSTPExamples" 136 | NO_SOURCE_PERMISSIONS) 137 | add_subdirectory(WSTPExamples) 138 | endif() 139 | endif() 140 | 141 | if (Mathematica_MUnit_FOUND) 142 | add_subdirectory(MUnitExamples) 143 | endif () 144 | 145 | if (JAVA_FOUND AND Mathematica_JLink_FOUND) 146 | # copy J/Link example files from Mathematica installation to source directory 147 | if (EXISTS "${Mathematica_JLink_PACKAGE_DIR}/Examples") 148 | file (GLOB_RECURSE _JLinkLinkExamples 149 | "${Mathematica_JLink_PACKAGE_DIR}/Examples/*.java") 150 | file (COPY ${_JLinkLinkExamples} 151 | DESTINATION "${CMAKE_BINARY_DIR}/JLinkExamples" 152 | NO_SOURCE_PERMISSIONS) 153 | add_subdirectory(JLinkExamples) 154 | endif() 155 | endif() 156 | -------------------------------------------------------------------------------- /CodeGenerationExamples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # FindMathematica CodeGeneration examples 2 | 3 | include_directories(${Mathematica_INCLUDE_DIRS}) 4 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 5 | 6 | # add CMake executable target for single Mathematica function 7 | Mathematica_GENERATE_C_CODE(compute.m OUTPUT compute.c) 8 | add_executable (compute compute_main.c compute.c) 9 | set_target_properties(compute PROPERTIES FOLDER "CodeGeneration") 10 | target_link_libraries (compute ${Mathematica_WolframLibrary_LIBRARIES}) 11 | set_target_properties(compute PROPERTIES INSTALL_RPATH "${Mathematica_RUNTIME_LIBRARY_DIRS}" BUILD_WITH_INSTALL_RPATH ON) 12 | 13 | # add CMake executable target for multiple Mathematica functions 14 | Mathematica_GENERATE_C_CODE(functions.m) 15 | add_executable (functions functions.c functions.m.c) 16 | set_target_properties(functions PROPERTIES FOLDER "CodeGeneration") 17 | target_link_libraries (functions ${Mathematica_WolframLibrary_LIBRARIES}) 18 | set_target_properties(functions PROPERTIES INSTALL_RPATH "${Mathematica_RUNTIME_LIBRARY_DIRS}" BUILD_WITH_INSTALL_RPATH ON) 19 | 20 | # fix MathLink shared library references under macOS 21 | Mathematica_ABSOLUTIZE_LIBRARY_DEPENDENCIES(compute functions) 22 | 23 | if (DEFINED Mathematica_USERBASE_DIR) 24 | foreach (_systemID ${Mathematica_SYSTEM_IDS}) 25 | install(TARGETS compute functions 26 | RUNTIME DESTINATION 27 | "${Mathematica_USERBASE_DIR}/SystemFiles/Kernel/Binaries/${_systemID}" 28 | CONFIGURATIONS "Release") 29 | endforeach() 30 | endif() 31 | 32 | # define a helper function to simplify adding CodeGeneration tests 33 | function (do_mathematica_codegeneration_test _target _expectedOutputRegEx) 34 | if (NOT TARGET ${_target}) 35 | return() 36 | endif() 37 | foreach (_systemID ${Mathematica_SYSTEM_IDS}) 38 | set (_testName "CodeGeneration_${_systemID}_${_target}") 39 | list (FIND Mathematica_HOST_SYSTEM_IDS ${_systemID} _index) 40 | if (${_index} GREATER -1) 41 | Mathematica_add_test (NAME ${_testName} 42 | COMMAND "$" 43 | SYSTEM_ID "${_systemID}" ${ARGN}) 44 | Mathematica_set_tests_properties(${_testName} 45 | PROPERTIES TIMEOUT 15 46 | PASS_REGULAR_EXPRESSION "${_expectedOutputRegEx}") 47 | else() 48 | message (STATUS "Skipping test ${_testName}, cross-compiling from ${Mathematica_HOST_SYSTEM_ID}.") 49 | endif() 50 | endforeach() 51 | endfunction () 52 | 53 | # tests 54 | 55 | do_mathematica_codegeneration_test(compute "compute 417.15") 56 | do_mathematica_codegeneration_test(functions "square 416.16\ncube 8489.66") 57 | 58 | add_convenience_test_target(CodeGenerationTests "CodeGeneration") 59 | -------------------------------------------------------------------------------- /CodeGenerationExamples/compute.m: -------------------------------------------------------------------------------- 1 | (* Generate code for single function *) 2 | 3 | cFun = Compile[{{x}}, x^2 + Sin[x^2]]; 4 | 5 | (* return compiled function that shall be exported to C code *) 6 | {cFun, "compute"} -------------------------------------------------------------------------------- /CodeGenerationExamples/compute_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "WolframRTL.h" 3 | #include "compute.h" 4 | 5 | int main(int argc, char *arg[]) 6 | { 7 | double num1 = 20.4; 8 | double num2; 9 | WolframLibraryData libData = WolframLibraryData_new(WolframLibraryVersion); 10 | Initialize_compute(libData); 11 | compute(libData, num1, &num2); 12 | printf("compute %5.2f\n", num2); 13 | WolframLibraryData_free(libData); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /CodeGenerationExamples/functions.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "WolframRTL.h" 3 | #include "functions.m.h" 4 | 5 | int main(int argc, char *arg[]) 6 | { 7 | double num1 = 20.4; 8 | double num2; 9 | WolframLibraryData libData = WolframLibraryData_new(WolframLibraryVersion); 10 | Initialize_functions(libData); 11 | square(libData, num1, &num2); 12 | printf("square %5.2f\n", num2); 13 | cube(libData, num1, &num2); 14 | printf("cube %5.2f\n", num2); 15 | WolframLibraryData_free(libData); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /CodeGenerationExamples/functions.m: -------------------------------------------------------------------------------- 1 | (* Generate code for multiple functions *) 2 | 3 | square = Compile[ {{x}}, x^2]; 4 | cube = Compile[ {{x}}, x^3]; 5 | 6 | (* return compiled functions that shall be exported to C code *) 7 | {{square,cube},{"square","cube"}} -------------------------------------------------------------------------------- /DocumentationExamples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # FindMathematica documentation build examples 2 | 3 | file (GLOB_RECURSE _docuFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.nb") 4 | 5 | Mathematica_ADD_DOCUMENTATION(documentation 6 | APPLICATION_NAME "MyApp" 7 | DOCUMENTATION_TYPE "Notebook" 8 | SOURCES ${_docuFiles} 9 | CHECK_TIMESTAMPS) 10 | 11 | Mathematica_ADD_DOCUMENTATION(documentation-html 12 | APPLICATION_NAME "MyApp" 13 | DOCUMENTATION_TYPE "HTML" 14 | SOURCES ${_docuFiles} 15 | CHECK_TIMESTAMPS) 16 | 17 | set_target_properties(documentation documentation-html PROPERTIES FOLDER "Documentation" ) 18 | -------------------------------------------------------------------------------- /DocumentationExamples/English/Guides/GuidePage.nb: -------------------------------------------------------------------------------- 1 | Notebook[{ 2 | Cell[TextData[{ 3 | "New in: ", 4 | Cell["0.0", "HistoryData", CellTags -> "New"], 5 | " | Modified in: ", 6 | Cell[" ", "HistoryData", 7 | CellTags->"Modified"], 8 | " | Obsolete in: ", 9 | Cell[" ", "HistoryData", 10 | CellTags->"Obsolete"], 11 | " | Excised in: ", 12 | Cell[" ", "HistoryData", 13 | CellTags->"Excised"] 14 | }], "History", 15 | CellID->1247902091], 16 | 17 | Cell[CellGroupData[{ 18 | 19 | Cell["Categorization", "CategorizationSection", 20 | CellID->1122911449], 21 | 22 | Cell["Guide", "Categorization", 23 | CellLabel->"Entity Type", 24 | CellID->686433507], 25 | 26 | Cell["MyApp", "Categorization", CellLabel->"Paclet Name", CellID->605800465], 27 | 28 | Cell["MyApp`", "Categorization", CellLabel->"Context", CellID->468444828], 29 | 30 | Cell["MyApp/guide/GuidePage", "Categorization", CellLabel->"URI"] 31 | }, Closed]], 32 | 33 | Cell[CellGroupData[{ 34 | 35 | Cell["Keywords", "KeywordsSection", 36 | CellID->1427428552], 37 | 38 | Cell["XXXX", "Keywords", 39 | CellID->1251852827] 40 | }, Closed]], 41 | 42 | Cell[CellGroupData[{ 43 | 44 | Cell["Details", "DetailsSection", 45 | CellID->307771771], 46 | 47 | Cell["XXXX", "Details", 48 | CellLabel->"Lead", 49 | CellID->795394057], 50 | 51 | Cell["XXXX", "Details", 52 | CellLabel->"Developers", 53 | CellID->350963985], 54 | 55 | Cell["XXXX", "Details", 56 | CellLabel->"Authors", 57 | CellID->802101], 58 | 59 | Cell["XXXX", "Details", 60 | CellLabel->"Feature Name", 61 | CellID->509823116], 62 | 63 | Cell["XXXX", "Details", 64 | CellLabel->"QA", 65 | CellID->199884516], 66 | 67 | Cell["XXXX", "Details", 68 | CellLabel->"DA", 69 | CellID->463951815], 70 | 71 | Cell["XXXX", "Details", 72 | CellLabel->"Docs", 73 | CellID->8237523], 74 | 75 | Cell["XXXX", "Details", 76 | CellLabel->"Features Page Notes", 77 | CellID->813936640], 78 | 79 | Cell["XXXX", "Details", 80 | CellLabel->"Comments", 81 | CellID->240026365] 82 | }, Closed]], 83 | 84 | Cell[CellGroupData[{ 85 | 86 | Cell["GuidePage", "GuideTitle",CellID->942062912], 87 | 88 | Cell["XXXX", "GuideAbstract", 89 | CellID->2001916300] 90 | }, Open ]], 91 | 92 | Cell[CellGroupData[{ 93 | 94 | Cell["", "GuideFunctionsSection", 95 | CellID->1866139230], 96 | 97 | Cell[TextData[{ 98 | Cell[BoxData["XXXX"], "InlineGuideFunction"], 99 | " \[LongDash] XXXX" 100 | }], "GuideText", 101 | CellID->203374175], 102 | 103 | Cell[TextData[{ 104 | Cell[BoxData["XXXX"], "InlineGuideFunction"], 105 | " \[LongDash] XXXX" 106 | }], "GuideText", 107 | CellID->1463276848], 108 | 109 | Cell[CellGroupData[{ 110 | 111 | Cell["\t", "GuideDelimiter", 112 | CellID->311258892], 113 | 114 | Cell["XXXX . XXXX . ", "InlineGuideFunctionListing", 115 | CellID->58033752] 116 | }, Open ]] 117 | }, Open ]], 118 | 119 | Cell[CellGroupData[{ 120 | 121 | Cell["Tutorials", "GuideTutorialsSection", 122 | CellID->415694126], 123 | 124 | Cell["XXXX", "GuideTutorial", 125 | CellID->806871991], 126 | 127 | Cell["XXXX", "GuideTutorial", 128 | CellID->1885805579] 129 | }, Open ]], 130 | 131 | Cell[CellGroupData[{ 132 | 133 | Cell["More About", "GuideMoreAboutSection", 134 | CellID->23220180], 135 | 136 | Cell["XXXX", "GuideMoreAbout", 137 | CellID->1567025153], 138 | 139 | Cell["XXXX", "GuideMoreAbout", 140 | CellID->252299663] 141 | }, Open ]], 142 | 143 | Cell["Related Links", "GuideRelatedLinksSection", 144 | CellID->415694148] 145 | }, 146 | WindowSize->{700, 770}, 147 | WindowMargins->{{4, Automatic}, {Automatic, 0}}, 148 | StyleDefinitions->FrontEnd`FileName[{"Wolfram"}, "GuidePageStyles.nb"] 149 | ] -------------------------------------------------------------------------------- /DocumentationExamples/English/ReferencePages/Symbols/SymbolPage.nb: -------------------------------------------------------------------------------- 1 | Notebook[{ 2 | Cell[TextData[{ 3 | "New in: ", 4 | Cell["0.0", "HistoryData", CellTags -> "New"], 5 | " | Modified in: ", 6 | Cell[" ", "HistoryData", 7 | CellTags->"Modified"], 8 | " | Obsolete in: ", 9 | Cell[" ", "HistoryData", 10 | CellTags->"Obsolete"], 11 | " | Excised in: ", 12 | Cell[" ", "HistoryData", 13 | CellTags->"Excised"] 14 | }], "History", 15 | CellID->1247902091], 16 | 17 | Cell[CellGroupData[{ 18 | 19 | Cell["Categorization", "CategorizationSection", 20 | CellID->1122911449], 21 | 22 | Cell["Symbol", "Categorization", 23 | CellLabel->"Entity Type", 24 | CellID->686433507], 25 | 26 | Cell["MyApp", "Categorization", CellLabel->"Paclet Name", CellID->605800465], 27 | 28 | Cell["MyApp`", "Categorization", CellLabel->"Context", CellID->468444828], 29 | 30 | Cell["MyApp/ref/SymbolPage", "Categorization", CellLabel->"URI"] 31 | }, Closed]], 32 | 33 | Cell[CellGroupData[{ 34 | 35 | Cell["Keywords", "KeywordsSection", 36 | CellID->477174294], 37 | 38 | Cell["XXXX", "Keywords", 39 | CellID->1164421360] 40 | }, Closed]], 41 | 42 | Cell[CellGroupData[{ 43 | 44 | Cell["Syntax Templates", "TemplatesSection", 45 | CellID->1872225408], 46 | 47 | Cell[BoxData[""], "Template", 48 | CellLabel->"Additional Function Template", 49 | CellID->1562036412], 50 | 51 | Cell[BoxData[""], "Template", 52 | CellLabel->"Arguments Pattern", 53 | CellID->158391909], 54 | 55 | Cell[BoxData[""], "Template", 56 | CellLabel->"Local Variables", 57 | CellID->1360575930], 58 | 59 | Cell[BoxData[""], "Template", 60 | CellLabel->"Color Equal Signs", 61 | CellID->793782254] 62 | }, Closed]], 63 | 64 | Cell[CellGroupData[{ 65 | 66 | Cell["Details", "DetailsSection", 67 | CellID->307771771], 68 | 69 | Cell["XXXX", "Details", 70 | CellLabel->"Lead", 71 | CellID->670882175], 72 | 73 | Cell["XXXX", "Details", 74 | CellLabel->"Developers", 75 | CellID->350963985], 76 | 77 | Cell["XXXX", "Details", 78 | CellLabel->"Authors", 79 | CellID->8391405], 80 | 81 | Cell["XXXX", "Details", 82 | CellLabel->"Feature Name", 83 | CellID->3610269], 84 | 85 | Cell["XXXX", "Details", 86 | CellLabel->"QA", 87 | CellID->401364205], 88 | 89 | Cell["XXXX", "Details", 90 | CellLabel->"DA", 91 | CellID->350204745], 92 | 93 | Cell["XXXX", "Details", 94 | CellLabel->"Docs", 95 | CellID->732958810], 96 | 97 | Cell["XXXX", "Details", 98 | CellLabel->"Features Page Notes", 99 | CellID->222905350], 100 | 101 | Cell["XXXX", "Details", 102 | CellLabel->"Comments", 103 | CellID->240026365] 104 | }, Closed]], 105 | 106 | Cell[CellGroupData[{ 107 | 108 | Cell[ "SymbolPage", "ObjectName", CellID->1224892054], 109 | 110 | Cell[TextData[{ 111 | Cell[" ", "ModInfo"], 112 | Cell[BoxData[ RowBox[{"SymbolPage", "[", "]"}]], "InlineFormula"], 113 | " \[LineSeparator]SymbolPage"}], 114 | "Usage", CellID->982511436], 115 | 116 | Cell["XXXX", "Notes", 117 | CellID->1067943069] 118 | }, Open ]], 119 | 120 | Cell[CellGroupData[{ 121 | 122 | Cell["Tutorials", "TutorialsSection", 123 | CellID->250839057], 124 | 125 | Cell["XXXX", "Tutorials", 126 | CellID->341631938] 127 | }, Open ]], 128 | 129 | Cell[CellGroupData[{ 130 | 131 | Cell["Related Demonstrations", "RelatedDemonstrationsSection", 132 | CellID->1268215905], 133 | 134 | Cell["XXXX", "RelatedDemonstrations", 135 | CellID->1129518860] 136 | }, Open ]], 137 | 138 | Cell[CellGroupData[{ 139 | 140 | Cell["Related Links", "RelatedLinksSection", 141 | CellID->1584193535], 142 | 143 | Cell["XXXX", "RelatedLinks", 144 | CellID->1038487239] 145 | }, Open ]], 146 | 147 | Cell[CellGroupData[{ 148 | 149 | Cell["See Also", "SeeAlsoSection", 150 | CellID->1255426704], 151 | 152 | Cell["XXXX", "SeeAlso", 153 | CellID->929782353] 154 | }, Open ]], 155 | 156 | Cell[CellGroupData[{ 157 | 158 | Cell["More About", "MoreAboutSection", 159 | CellID->38303248], 160 | 161 | Cell["XXXX", "MoreAbout", 162 | CellID->1665078683] 163 | }, Open ]], 164 | 165 | Cell[BoxData[ 166 | InterpretationBox[GridBox[{ 167 | { 168 | StyleBox["Examples", "PrimaryExamplesSection"], 169 | ButtonBox[ 170 | RowBox[{ 171 | RowBox[{"More", " ", "Examples"}], " ", "\[RightTriangle]"}], 172 | BaseStyle->"ExtendedExamplesLink", 173 | ButtonData:>"ExtendedExamples"]} 174 | }], 175 | $Line = 0; Null]], "PrimaryExamplesSection", 176 | CellID->880084151], 177 | 178 | Cell[CellGroupData[{ 179 | 180 | Cell["More Examples", "ExtendedExamplesSection", 181 | CellTags->"ExtendedExamples", 182 | CellID->1854448968], 183 | 184 | Cell[BoxData[ 185 | InterpretationBox[Cell["Scope", "ExampleSection"], 186 | $Line = 0; Null]], "ExampleSection", 187 | CellID->1293636265], 188 | 189 | Cell[BoxData[ 190 | InterpretationBox[Cell["Generalizations & Extensions", "ExampleSection"], 191 | $Line = 0; Null]], "ExampleSection", 192 | CellID->1020263627], 193 | 194 | Cell[CellGroupData[{ 195 | 196 | Cell[BoxData[ 197 | InterpretationBox[Cell["Options", "ExampleSection"], 198 | $Line = 0; Null]], "ExampleSection", 199 | CellID->2061341341], 200 | 201 | Cell[BoxData[ 202 | InterpretationBox[Cell["XXXX", "ExampleSubsection"], 203 | $Line = 0; Null]], "ExampleSubsection", 204 | CellID->1757724783], 205 | 206 | Cell[BoxData[ 207 | InterpretationBox[Cell["XXXX", "ExampleSubsection"], 208 | $Line = 0; Null]], "ExampleSubsection", 209 | CellID->1295379749] 210 | }, Closed]], 211 | 212 | Cell[BoxData[ 213 | InterpretationBox[Cell["Applications", "ExampleSection"], 214 | $Line = 0; Null]], "ExampleSection", 215 | CellID->258228157], 216 | 217 | Cell[BoxData[ 218 | InterpretationBox[Cell["Properties & Relations", "ExampleSection"], 219 | $Line = 0; Null]], "ExampleSection", 220 | CellID->2123667759], 221 | 222 | Cell[BoxData[ 223 | InterpretationBox[Cell["Possible Issues", "ExampleSection"], 224 | $Line = 0; Null]], "ExampleSection", 225 | CellID->1305812373], 226 | 227 | Cell[BoxData[ 228 | InterpretationBox[Cell["Interactive Examples", "ExampleSection"], 229 | $Line = 0; Null]], "ExampleSection", 230 | CellID->1653164318], 231 | 232 | Cell[BoxData[ 233 | InterpretationBox[Cell["Neat Examples", "ExampleSection"], 234 | $Line = 0; Null]], "ExampleSection", 235 | CellID->589267740] 236 | }, Open ]] 237 | }, 238 | WindowSize->{700, 770}, 239 | WindowMargins->{{4, Automatic}, {Automatic, 0}}, 240 | CellContext->"Global`", 241 | StyleDefinitions->FrontEnd`FileName[{"Wolfram"}, "FunctionPageStyles.nb"] 242 | ] -------------------------------------------------------------------------------- /DocumentationExamples/English/Tutorials/TutorialPage.nb: -------------------------------------------------------------------------------- 1 | Notebook[{ 2 | Cell[TextData[{ 3 | "New in: ", 4 | Cell["0.0", "HistoryData", CellTags -> "New"], 5 | " | Modified in: ", 6 | Cell[" ", "HistoryData", 7 | CellTags->"Modified"], 8 | " | Obsolete in: ", 9 | Cell[" ", "HistoryData", 10 | CellTags->"Obsolete"], 11 | " | Excised in: ", 12 | Cell[" ", "HistoryData", 13 | CellTags->"Excised"] 14 | }], "History", 15 | CellID->1247902091], 16 | 17 | Cell[CellGroupData[{ 18 | 19 | Cell["Categorization", "CategorizationSection", 20 | CellID->1122911449], 21 | 22 | Cell["Tutorial", "Categorization", 23 | CellLabel->"Entity Type", 24 | CellID->686433507], 25 | 26 | Cell["MyApp", "Categorization", CellLabel->"Paclet Name", CellID->605800465], 27 | 28 | Cell["MyApp`", "Categorization", CellLabel->"Context", CellID->468444828], 29 | 30 | Cell["MyApp/tutorial/TutorialPage", "Categorization", CellLabel->"URI"] 31 | }, Closed]], 32 | 33 | Cell[CellGroupData[{ 34 | 35 | Cell["Keywords", "KeywordsSection", 36 | CellID->1427428552], 37 | 38 | Cell["XXXX", "Keywords", 39 | CellID->1251852827] 40 | }, Closed]], 41 | 42 | Cell[CellGroupData[{ 43 | 44 | Cell["Details", "DetailsSection", 45 | CellID->307771771], 46 | 47 | Cell["XXXX", "Details", 48 | CellLabel->"Lead", 49 | CellID->218895918], 50 | 51 | Cell["XXXX", "Details", 52 | CellLabel->"Developers", 53 | CellID->350963985], 54 | 55 | Cell["XXXX", "Details", 56 | CellLabel->"Authors", 57 | CellID->795871300], 58 | 59 | Cell["XXXX", "Details", 60 | CellLabel->"Feature Name", 61 | CellID->199739161], 62 | 63 | Cell["XXXX", "Details", 64 | CellLabel->"QA", 65 | CellID->40625308], 66 | 67 | Cell["XXXX", "Details", 68 | CellLabel->"DA", 69 | CellID->357121918], 70 | 71 | Cell["XXXX", "Details", 72 | CellLabel->"Docs", 73 | CellID->35949532], 74 | 75 | Cell["XXXX", "Details", 76 | CellLabel->"Features Page Notes", 77 | CellID->929432370], 78 | 79 | Cell["XXXX", "Details", 80 | CellLabel->"Comments", 81 | CellID->240026365] 82 | }, Closed]], 83 | 84 | Cell[CellGroupData[{ 85 | 86 | Cell["TutorialPage", "Title",CellID->509267359], 87 | 88 | Cell["XXXX", "Text", 89 | CellID->1534169418], 90 | 91 | Cell[BoxData[GridBox[{ 92 | {"XXXX", Cell["XXXX", "TableText"]}, 93 | {"XXXX", Cell["XXXX", "TableText"]}, 94 | {"XXXX", Cell["XXXX", "TableText"]} 95 | }]], "DefinitionBox", 96 | CellID->2096742444], 97 | 98 | Cell["XXXX.", "Caption", 99 | CellID->1891092685], 100 | 101 | Cell[CellGroupData[{ 102 | 103 | Cell["XXXX", "MathCaption", 104 | CellID->836781195], 105 | 106 | Cell[CellGroupData[{ 107 | 108 | Cell[BoxData["XXXX"], "Input", 109 | CellLabel->"In[1]:=", 110 | CellID->2058623809], 111 | 112 | Cell[BoxData["XXXX"], "Output", 113 | CellLabel->"Out[1]=", 114 | CellID->1181321046] 115 | }, Open ]] 116 | }, Open ]], 117 | 118 | Cell[CellGroupData[{ 119 | 120 | Cell["More About", "TutorialMoreAboutSection", 121 | CellID->23220180], 122 | 123 | Cell["XXXX", "TutorialMoreAbout", 124 | CellID->1567025153] 125 | }, Open ]], 126 | 127 | Cell[CellGroupData[{ 128 | 129 | Cell["Related Tutorials", "RelatedTutorialsSection", 130 | CellID->415694126], 131 | 132 | Cell["XXXX", "RelatedTutorials", 133 | CellID->806871991] 134 | }, Open ]], 135 | 136 | Cell[CellGroupData[{ 137 | 138 | Cell["Related Wolfram Education Group Courses", "TutorialRelatedLinksSection", 139 | CellID->415694148], 140 | 141 | Cell["XXXX", "TutorialRelatedLinks", 142 | CellID->415694149] 143 | }, Open ]] 144 | }, Open ]] 145 | }, 146 | WindowSize->{700, 770}, 147 | WindowMargins->{{4, Automatic}, {Automatic, 0}}, 148 | StyleDefinitions->FrontEnd`FileName[{"Wolfram"}, "TutorialPageStyles.nb"] 149 | ] -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | ## 4.1.0 (2025-01-25) 2 | 3 | * Wolfram App 14.2 compatibility 4 | * Wolfram App 14.1 compatibility 5 | * raise the minimum required CMake version to 3.10 6 | * remove broken macOS LaunchServices database search 7 | 8 | ## 4.0.0 (2024-01-10) 9 | 10 | * *Mathematica* 14.0 compatibility 11 | * *Mathematica* 13.3 compatibility 12 | * raise the minimum required CMake version to 3.5 13 | * manual updates 14 | 15 | ## 3.8.0 (2022-12-30) 16 | 17 | * *Mathematica* 13.2 compatibility 18 | 19 | ## 3.7.0 (2022-09-24) 20 | 21 | * *Mathematica* 13.1 compatibility 22 | 23 | ## 3.6.0 (2021-12-15) 24 | 25 | * *Mathematica* 13 compatibility 26 | * warn explicitly about common mistakes users make 27 | * fix for Mathematica installed in Windows docker container 28 | * fix broken launch services database search under OS X 29 | 30 | ## 3.5.0 (2021-05-21) 31 | 32 | * *Mathematica* 12.3 compatibility 33 | 34 | ## 3.4.0 (2020-12-19) 35 | 36 | * *Mathematica* 12.2 compatibility 37 | * add `Mathematica_RUN_KERNEL_ON_CONFIGURE` switch to control if FindMathematica is allowed to 38 | implicitly run the *Mathematica* kernel at CMake configuration time 39 | 40 | ## 3.3.0 (2020-03-25) 41 | 42 | * *Mathematica* 12.1 compatibility 43 | * remove `Mathematica_SPLICE_C_CODE` whose underlying *Mathematica* function `Splice` 44 | has been deprecated since *Mathematica* 10 and has been removed in *Mathematica* 12.1 45 | * add new variable `Mathematica_JLink_JAVA_HOME`, which contains the full path to Java SDK 46 | bundled with *Mathematica* 47 | 48 | ## 3.2.7 (2020-02-09) 49 | 50 | * fix compatibility with Wolfram Engine under OS X 51 | * fix front end detection for Wolfram Desktop 52 | * manual updates 53 | 54 | ## 3.2.6 (2020-02-07) 55 | 56 | * Wolfram Desktop compatibility 57 | * Wolfram Engine compatibility 58 | 59 | ## 3.2.5 (2019-04-28) 60 | 61 | * *Mathematica* 12.0 compatibility 62 | * add `libuuid` to list of required runtime libraries under Linux 63 | * remove 32-bit Linux from supported system IDs for *Mathematica* versions >= 11.3 64 | 65 | ## 3.2.4 (2018-03-16) 66 | 67 | * *Mathematica* 11.3 compatibility 68 | 69 | ## 3.2.3 (2017-09-15) 70 | 71 | * *Mathematica* 11.2 compatibility 72 | * *Mathematica* 11.1 compatibility 73 | * add new variables for component runtime directories (e.g., 74 | `Mathematica_MathLink_RUNTIME_LIBRARY_DIRS`) 75 | 76 | ## 3.2.2 (2016-09-28) 77 | 78 | * Xcode 8 compatibility fix 79 | * Cygwin compatibility fix 80 | 81 | ## 3.2.1 (2016-08-17) 82 | 83 | * *Mathematica* 11 compatibility 84 | * fix rpath handling for code generation examples under Linux and OS X 85 | * fix handling of `Mathematica_USE_LIBCXX_LIBRARIES` for *Mathematica* 10.4 and 11 86 | 87 | ## 3.2.0 (2016-03-20) 88 | 89 | * *Mathematica* 10.4 compatibility 90 | * add variable `Mathematica_MathLink_FIND_VERSION_MINOR` (requested MathLink revision) 91 | * add variable `Mathematica_WSTP_FIND_VERSION_MINOR` (requested WSTP revision) 92 | * rename `Mathematica_JLink_LIBRARY` to `Mathematica_JLink_RUNTIME_LIBRARY` 93 | 94 | ## 3.1.4 (2015-10-18) 95 | 96 | * *Mathematica* 10.3 compatibility 97 | * add work-around to compile LibraryLink examples with Visual Studio 2015 98 | 99 | ## 3.1.3 (2015-10-10) 100 | 101 | * add timestamp check for HTML docu generation 102 | * add `JAVACMD` option to `Mathematica_ADD_DOCUMENTATION` 103 | * use `java_home` to find Java runtime executable under OS X 104 | * remove obsolete code 105 | * documentation updates 106 | 107 | ## 3.1.2 (2015-07-25) 108 | 109 | * *Mathematica* 10.2 compatibility 110 | * fix variable dereferences in `if` commands 111 | 112 | ## 3.1.1 (2015-04-21) 113 | 114 | * fix *Mathematica* 10.1 compatibility issues 115 | * do not use broken `-script` option for *Mathematica* earlier than 10.0 116 | * add variables `Mathematica_LibraryLink_PACKAGE_FILE` and `Mathematica_LibraryLink_PACKAGE_DIR` 117 | * copy standard examples to binary directory instead of source directory 118 | * add CMake tests for new LibraryLink examples 119 | 120 | ## 3.1.0 (2015-04-06) 121 | 122 | * add compatibility with *Mathematica* 10.1 123 | * fix CMake 3.2 compatibility issues 124 | * require at least CMake 2.8.12 125 | * remove obsolete code required for CMake versions older than 2.8.12 126 | * prefer modern executable names (i.e., `wolfram.exe`) over classic ones (i.e., `math.exe`) 127 | * add parameter `LINK_MODE` to some functions (see manual) 128 | * manual updates 129 | 130 | ## 3.0.3 (2015-02-11) 131 | 132 | * work around `cmd.exe` command line length limit when running *Mathematica* code 133 | * fix `cmd.exe` command line quoting issues 134 | * fix for running MUnit tests 135 | * more robust cache cleaning of invalid WSTP related variables 136 | * print message when `DocumentationBuild` package is not installed 137 | 138 | ## 3.0.2 (2014-12-21) 139 | 140 | * fix bug with computing of *Mathematica* 10.0.2 version number 141 | * fix bug with finding correct MathLink / WSTP DeveloperKit under OS X 142 | * CMake 3.1.0 compatibility fixes 143 | * fix quoting issues 144 | 145 | ## 3.0.1 (2014-12-11) 146 | 147 | * add compatibility with *Mathematica* 10.0.2 148 | * add variables `Mathematica_MathLink_DEFINITIONS` and `Mathematica_MathLink_LINKER_FLAGS` 149 | * add variables `Mathematica_WSTP_DEFINITIONS` and `Mathematica_WSTP_LINKER_FLAGS` 150 | * use `-wstp` flag for launching WSTP executables 151 | * prevent conflicts with MSVC runtime library upon linking static MathLink or WSTP library 152 | * add MathLink or WSTP framework directory to `Mathematica_RUNTIME_LIBRARY_DIRS` under OS X 153 | * manual updates 154 | 155 | ## 3.0.0 (2014-08-19) 156 | 157 | * add support for *Mathematica* 10 158 | * CMake 3.0.0 compatibility fixes 159 | * add support for WSTP (Wolfram Symbolic Transfer Protocol) 160 | * move documentation from file `FindMathematica.cmake` to manual file of its own 161 | * preserve directory structure when using `Mathematica_ENCODE` with an output folder 162 | * add variable `Mathematica_MathLink_FIND_VERSION_MAJOR` (requested MathLink major version) 163 | * add variable `Mathematica_JLink_LIBRARY` (path to J/Link's `JLinkNativeLibrary`) 164 | * add variable `Mathematica_JLink_JAVA_EXECUTABLE` (path to the host Java runtime) 165 | * add option `LINK_PROTOCOL` to `Mathematica_MathLink_ADD_TEST` and `Mathematica_JLink_ADD_TEST` 166 | * change in `Mathematica_MathLink_MPREP_TARGET` and `Mathematica_MathLink_ADD_EXECUTABLE`: 167 | if MathLink template file extension is .tmpp, generate C++ source file from it 168 | * add variable `Mathematica_USE_LIBCXX_LIBRARIES` to prefer libc++ linked libraries to 169 | libstdc++ linked libraries (OS X only) 170 | 171 | ## 2.2.5 (2013-06-08) 172 | 173 | * handle `Mathematica_FIND_VERSION_EXACT` parameter correctly 174 | 175 | ## 2.2.4 (2013-02-10) 176 | 177 | * honor `MATHEMATICA_HOME` environment variable introduced with *Mathematica* 8.0.4 178 | 179 | ## 2.2.3 (2013-01-29) 180 | 181 | * handle `Mathematica_FIND_VERSION_EXACT` parameter correctly 182 | 183 | ## 2.2.2 (2012-12-07) 184 | 185 | * *Mathematica* 9 compatibility fixes 186 | 187 | ## 2.2.1 (2012-10-23) 188 | 189 | * Windows registry search fix for WoW64 190 | * add option `INCLUDE_NOTEBOOKS` to `Mathematica_ADD_DOCUMENTATION` 191 | * more robust cache cleaning of invalid FindMathematica related variables 192 | * add check to test if *Mathematica* has been registered properly 193 | * move option variable initialization to function of its own 194 | * quoting fixes 195 | 196 | ## 2.2.0 (2012-09-22) 197 | 198 | * add `Mathematica_JLink_ADD_TEST` to run J/Link program as a CMake test 199 | * add J/Link examples 200 | * allow for both `CODE` and `SCRIPT` parameters to be present in functions that execute 201 | *Mathematica* code 202 | * correctly handle the relative file path given as a `SCRIPT` parameter 203 | * fix Cygwin compatibility problems 204 | 205 | ## 2.1.0 (2012-09-02) 206 | 207 | * add option `CHECK_TIMESTAMPS` to `Mathematica_ADD_DOCUMENTATION` to avoid redundant re-building 208 | of the documentation when no notebook has changed 209 | * fixed bug with detection of `ant.bat` executable script under Windows 210 | * guard against missing test driver helper scripts 211 | * fixed bug with setting up the kernel command line when both `CODE` and `SCRIPT` are present 212 | * add work-around to prevent CMake commands that run the kernel from hanging when `Abort[]` is used 213 | * add more accurate detection of host processor architecture under OS X 214 | * minor documentation fixes 215 | 216 | ## 2.0.9 (2012-08-17) 217 | 218 | * prevent modification of the CMake policy stack upon CMake version check 219 | * fix target type check in `Mathematica_ABSOLUTIZE_LIBRARY_DEPENDENCIES` 220 | 221 | ## 2.0.8 (2012-08-09) 222 | 223 | * detect Wolfram Finance Platform installation 224 | * fix undefined variable dereference 225 | 226 | ## 2.0.7 (2012-06-21) 227 | 228 | * fix out of range index operation 229 | 230 | ## 2.0.6 (2012-05-10) 231 | 232 | * fix native path conversion issues 233 | * improve compiler version detection code 234 | 235 | ## 2.0.5 (2012-03-05) 236 | 237 | * fix use of uninitialized variables 238 | * fixed Wolfram Library runtime directory selection for OS X 10.7 239 | 240 | ## 2.0.4 (2012-02-26) 241 | 242 | * fix compiler version detection for Visual Studio C++ 243 | * fix LaunchServices database search bug under OS X 244 | * add `Mathematica_MathLink_HOST_INCLUDE_DIR` 245 | * quoting fixes 246 | 247 | ## 2.0.3 (2012-01-19) 248 | 249 | * fix LaunchServices database search under OS X 10.7 250 | 251 | ## 2.0.2 (2012-01-03) 252 | 253 | * under Windows search registry determined installation locations first 254 | * under OS X search LaunchServices database determined installation locations first 255 | * under OS X programmatically find path to `lsregister` executable 256 | * tested with CMake 2.8.7 257 | 258 | ## 2.0.1 (2011-12-20) 259 | 260 | * skip cleanup of CMake cache upon initial invocation 261 | * cross-compiling fixes 262 | * add work-around that allows for generating LibraryLink workable DLLs with Cygwin 263 | * add `Mathematica_CREATION_ID` variable 264 | * recompute version information if *Mathematica* is upgraded in-place (e.g., from 8.0.1 to 8.0.4) 265 | 266 | ## 2.0.0 (2011-12-05) 267 | 268 | * add support for finding J/Link 269 | * add support for finding Wolfram MUnit testing package 270 | * add MUnit wrapper functions `Mathematica_MUnit_ADD_TEST` and `Mathematica_MUnit_RESOLVE_SUITE` 271 | * add support for generating *Mathematica* documentation with the DocumentationBuild package 272 | * add new function `Mathematica_FIND_PACKAGE` 273 | * add new function `Mathematica_GET_PACKAGE_DIR` 274 | * FindMathematica module directory is now prepended to the *Mathematica* `$Path` 275 | * add `CACHE` option to function `Mathematica_EXECUTE` 276 | * add `KERNEL_OPTIONS` parameter to functions which launch the *Mathematica* kernel 277 | * function `Mathematica_TO_NATIVE_PATH` now also handles a list of CMake paths 278 | * function `Mathematica_ENCODE` now can encode multiple files at the same time 279 | * pass `TEST_NAME` and `TEST_CONFIGURATION` environment variables to *Mathematica* test scripts 280 | * use `exec` in UNIX test driver shell script upon launching test executable 281 | * add `INPUT_FILE` option to function `Mathematica_EXECUTE` 282 | * add `DEPENDS` option to function `Mathematica_ADD_CUSTOM_TARGET` 283 | * add `MAIN_DEPENDENCY` option to function `Mathematica_ADD_CUSTOM_COMMAND` 284 | * add `DEPENDS` option to function `Mathematica_GENERATE_C_CODE` 285 | * install Wolfram Library without modifying `$LibraryPath` in `Mathematica_WolframLibrary_ADD_TEST` 286 | 287 | ## 1.2.6 (2011-12-03) 288 | 289 | * fix debug output 290 | 291 | ## 1.2.5 (2011-12-02) 292 | 293 | * fix bug in launch services database search code under OS X 294 | 295 | ## 1.2.4 (2011-11-17) 296 | 297 | * preserve user defined overrides upon option initialization 298 | * don't set `RUN_SERIAL` option in `Mathematica_SET_TESTS_PROPERTIES` 299 | 300 | ## 1.2.3 (2011-11-08) 301 | 302 | * fix cache cleanup bug 303 | * use functions instead of macros to work around the Windows backslash problem 304 | * improve `Mathematica_ADD_CUSTOM_TARGET` documentation 305 | 306 | ## 1.2.2 (2011-11-07) 307 | 308 | * properly document `SYSTEM_ID` option 309 | * stricter *Mathematica* version checks 310 | * fix bug in `Mathematica_EXECUTE` with handling of `SYSTEM_ID` option 311 | 312 | ## 1.2.1 (2011-11-04) 313 | 314 | * Windows registry search fix 315 | * add work-around for Windows cmd.exe quotation problem 316 | * fix bug in function that sets up version variables 317 | * make code more robust against exceptional usage cases 318 | 319 | ## 1.2.0 (2011-10-30) 320 | 321 | * add `Mathematica_ENCODE` function 322 | * add `Mathematica_ABSOLUTIZE_LIBRARY_DEPENDENCIES` function 323 | * fixed use of `Mathematica_USERBASE_DIR` in examples 324 | * fixed RPATH issues under Linux 325 | 326 | ## 1.1.2 (2011-10-26) 327 | 328 | * option initialization fixes 329 | * tested with *Mathematica* 8.0.4 330 | 331 | ## 1.1.1 (2011-09-24) 332 | 333 | * file path conversion fixes for Cygwin and MinGW 334 | 335 | ## 1.1.0 (2011-09-17) 336 | 337 | * add `Mathematica_BASE_DIR` and `Mathematica_USERBASE_DIR` variables 338 | * fixed some character escaping issues 339 | 340 | ## 1.0.4 (2011-07-12) 341 | 342 | * tested with Wolfram Lightweight Grid Manager 8.0 343 | * fixed some uninitialized variables 344 | 345 | ## 1.0.3 (2011-07-07) 346 | 347 | * work around `Splice::splict` message in `Mathematica_SPLICE_C_CODE` 348 | * fix build failures when the build directory path contains space characters 349 | * use CMake `option` command for user overridable boolean module variables 350 | 351 | ## 1.0.2 (2011-07-02) 352 | 353 | * Fix *Mathematica* detection on PPC equipped Macs 354 | 355 | ## 1.0.1 (2011-04-03) 356 | 357 | * Changes for undefined WIN32 variable under Cygwin with CMake 2.8.4 358 | * Tested with *Mathematica* 8.0.1 359 | * Code cleanup 360 | 361 | ## 1.0.0 (2010-12-05) 362 | 363 | * First release 364 | -------------------------------------------------------------------------------- /JLinkExamples/.gitignore: -------------------------------------------------------------------------------- 1 | GraphicsApp.java 2 | GraphicsDlg.java 3 | SampleProgram.java 4 | SimpleFrontEnd.java 5 | -------------------------------------------------------------------------------- /JLinkExamples/AddTwo.java: -------------------------------------------------------------------------------- 1 | public class AddTwo { 2 | public static int addtwo(int i, int j) {return i + j;} 3 | } 4 | -------------------------------------------------------------------------------- /JLinkExamples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # FindMathematica J/Link examples 2 | 3 | include(UseJava) 4 | 5 | # add J/Link jar to Java compiler include path 6 | set (CMAKE_JAVA_INCLUDE_PATH "${Mathematica_JLink_JAR_FILE}") 7 | # force Java 8 compilation of example sources 8 | # sample source files use Windows character encoding 9 | set (CMAKE_JAVA_COMPILE_FLAGS "-source" "1.8" "-target" "1.8" "-encoding" "Cp1252") 10 | 11 | if (NOT CYGWIN) 12 | # UseJava module cannot handle Cygwin path syntax 13 | add_jar(AddTwo AddTwo.java) 14 | add_jar(FormatArray FormatArray.java) 15 | add_jar(GraphicsApp "${CMAKE_CURRENT_BINARY_DIR}/GraphicsApp.java") 16 | add_jar(GraphicsDlg "${CMAKE_CURRENT_BINARY_DIR}/GraphicsDlg.java") 17 | add_jar(SampleProgram "${CMAKE_CURRENT_BINARY_DIR}/SampleProgram.java") 18 | add_jar(SimpleFrontEnd "${CMAKE_CURRENT_BINARY_DIR}/SimpleFrontEnd.java") 19 | set_target_properties(AddTwo FormatArray GraphicsApp GraphicsDlg SampleProgram SimpleFrontEnd PROPERTIES FOLDER "JLink") 20 | endif() 21 | 22 | # define a helper function to simplify adding J/Link executable tests 23 | function (do_jlink_test _target _expectedOutputRegEx) 24 | if (NOT TARGET ${_target}) 25 | return() 26 | endif() 27 | foreach (_systemID ${Mathematica_SYSTEM_IDS}) 28 | set (_testName "JLink_${_systemID}_${_target}") 29 | list (FIND Mathematica_HOST_SYSTEM_IDS "${_systemID}" _index) 30 | if (${_index} GREATER -1) 31 | Mathematica_JLink_ADD_TEST ( 32 | NAME ${_testName} TARGET ${_target} 33 | SYSTEM_ID "${_systemID}" ${ARGN}) 34 | Mathematica_set_tests_properties (${_testName} 35 | PROPERTIES TIMEOUT 30 36 | PASS_REGULAR_EXPRESSION "${_expectedOutputRegEx}") 37 | if (COMMAND log_test_properties) 38 | log_test_properties("${_testName}") 39 | endif() 40 | else() 41 | message (STATUS "Skipping test ${_testName}, cross-compiling from ${Mathematica_HOST_SYSTEM_ID}.") 42 | endif() 43 | endforeach() 44 | endfunction () 45 | 46 | do_jlink_test(SampleProgram 47 | # Expected output regular expression 48 | "2 \\+ 2 = 4\n3 \\+ 3 = 6\n4 \\+ 4 = 8" 49 | KERNEL_OPTIONS "-noinit" 50 | ) 51 | 52 | do_jlink_test(AddTwo 53 | # Expected output regular expression 54 | "5\n7" 55 | CODE 56 | "LoadJavaClass[\"AddTwo\",AllowShortContext->True,StaticsVisible->True]" 57 | "Print[AddTwo`addtwo[2,3]]" 58 | # Sequence forces start of a new CompoundExpression 59 | "Sequence[]" 60 | "Print[addtwo[3,4]]" 61 | ) 62 | 63 | do_jlink_test(FormatArray 64 | # Expected output regular expression 65 | "{\"1.0000\", \"2.0000\", \"3.0000\", \"4.0000\", \"5.0000\", \"6.0000\", \"7.0000\", \"8.0000\", \"9.0000\", \"10.0000\"}" 66 | SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/FormatArrayTest.m" 67 | ) 68 | -------------------------------------------------------------------------------- /JLinkExamples/FormatArray.java: -------------------------------------------------------------------------------- 1 | public class FormatArray { 2 | public static String[] format(java.text.DecimalFormat fmt,double[] d) { 3 | String[] result=new String[d.length]; 4 | for (int i = 0; i < d.length; i++) 5 | result[i] = fmt.format(d[i]); 6 | return result; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /JLinkExamples/FormatArrayTest.m: -------------------------------------------------------------------------------- 1 | (* Mathematica J/Link test script for FormatArray.java *) 2 | 3 | fmt = JavaNew["java.text.DecimalFormat", "#.0000"] 4 | data = Range[10] 5 | LoadJavaClass["FormatArray"] 6 | Print[FormatArray`format[fmt, data]] 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2025 Sascha Kratky 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /LibraryLinkExamples/.gitignore: -------------------------------------------------------------------------------- 1 | *.c 2 | -------------------------------------------------------------------------------- /LibraryLinkExamples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # FindMathematica LibraryLink examples 2 | 3 | include_directories(${Mathematica_INCLUDE_DIRS}) 4 | 5 | set(_Examples 6 | arbitraryTensor.c demo.c demo_callback.c demo_eval.c demo_mathlink.c demo_LinkObject.c 7 | demo_error.c demo_numerical.c demo_shared.c demo_string.c demo_sparse.c 8 | demo_image.cxx demo_managed.cxx demo_numericarray.cxx) 9 | 10 | if (MSVC14) 11 | # demo_managed requires hash_map 12 | add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS) 13 | endif() 14 | 15 | # add a CMake shared library target for each LibraryLink example 16 | set (_Targets "") 17 | foreach (_Example ${_Examples}) 18 | if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${_Example}") 19 | file (STRINGS "${CMAKE_CURRENT_BINARY_DIR}/${_Example}" _includesMathLink REGEX ".*#include.*mathlink.h.*") 20 | file (STRINGS "${CMAKE_CURRENT_BINARY_DIR}/${_Example}" _includesWSTP REGEX ".*#include.*wstp.h.*") 21 | set (_honorExample TRUE) 22 | if (_includesMathLink AND NOT Mathematica_MathLink_FOUND) 23 | set (_honorExample FALSE) 24 | endif() 25 | if (_includesWSTP AND NOT Mathematica_WSTP_FOUND) 26 | set (_honorExample FALSE) 27 | endif() 28 | if (_honorExample) 29 | get_filename_component(_TargetName ${_Example} NAME_WE) 30 | Mathematica_ADD_LIBRARY (${_TargetName} "${CMAKE_CURRENT_BINARY_DIR}/${_Example}") 31 | if (_includesMathLink) 32 | target_link_libraries(${_TargetName} ${Mathematica_MathLink_LIBRARIES}) 33 | if (Mathematica_MathLink_LINKER_FLAGS) 34 | set_target_properties(${_TargetName} PROPERTIES LINK_FLAGS "${Mathematica_MathLink_LINKER_FLAGS}") 35 | endif() 36 | endif() 37 | if (_includesWSTP) 38 | target_link_libraries(${_TargetName} ${Mathematica_WSTP_LIBRARIES}) 39 | if (Mathematica_WSTP_LINKER_FLAGS) 40 | set_target_properties(${_TargetName} PROPERTIES LINK_FLAGS "${Mathematica_WSTP_LINKER_FLAGS}") 41 | endif() 42 | endif() 43 | if (_includesMathLink OR _includesWSTP) 44 | Mathematica_ABSOLUTIZE_LIBRARY_DEPENDENCIES(${_TargetName}) 45 | endif() 46 | set_target_properties(${_TargetName} PROPERTIES FOLDER "LibraryLink") 47 | list (APPEND _Targets ${_TargetName}) 48 | endif() 49 | endif() 50 | endforeach() 51 | 52 | # define a helper function to simplify adding LibraryLink tests 53 | function (do_mathematica_librarylink_test _target _expectedOutputRegEx) 54 | if (NOT TARGET ${_target}) 55 | return() 56 | endif() 57 | foreach (_systemID ${Mathematica_SYSTEM_IDS}) 58 | set (_testName "LibraryLink_${_systemID}_${_target}") 59 | list (FIND Mathematica_HOST_SYSTEM_IDS ${_systemID} _index) 60 | if (${_index} GREATER -1) 61 | Mathematica_WolframLibrary_ADD_TEST ( 62 | NAME ${_testName} TARGET ${_target} 63 | SYSTEM_ID "${_systemID}" ${ARGN}) 64 | Mathematica_set_tests_properties (${_testName} 65 | PROPERTIES TIMEOUT 20 66 | PASS_REGULAR_EXPRESSION "${_expectedOutputRegEx}") 67 | if (NOT CMAKE_VERSION LESS "3.0.0") 68 | set_tests_properties(${_testName} PROPERTIES REQUIRED_FILES "$") 69 | endif() 70 | else() 71 | message (STATUS "Skipping test ${_testName}, cross-compiling from ${Mathematica_HOST_SYSTEM_ID}.") 72 | endif() 73 | endforeach() 74 | endfunction () 75 | 76 | if (DEFINED Mathematica_USERBASE_DIR) 77 | foreach (_systemID ${Mathematica_SYSTEM_IDS}) 78 | install(TARGETS ${_Targets} 79 | LIBRARY DESTINATION 80 | "${Mathematica_USERBASE_DIR}/SystemFiles/LibraryResources/${_systemID}" 81 | CONFIGURATIONS "Release") 82 | endforeach() 83 | endif() 84 | 85 | # tests 86 | 87 | do_mathematica_librarylink_test(demo 88 | # Expected output regular expression 89 | "11 90 | 100. 91 | 39. 92 | 1. 93 | 2. 94 | 3. 95 | {2, 4, 6, 8, 10} 96 | 1. 97 | 11 98 | {1, 2, 3, 4, 2, 2, 4, 2, 2} 99 | False 100 | 1. - 2.*I 101 | Null" 102 | SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/demo_test.m") 103 | 104 | do_mathematica_librarylink_test(demo_string 105 | # Expected output regular expression 106 | "3 107 | \"Rfymjrfynhf\" 108 | \"acitamehtaM\"" 109 | SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/demo_string_test.m") 110 | 111 | do_mathematica_librarylink_test(demo_mathlink 112 | # Expected output regular expression 113 | "2 114 | \"acitamehtaM\"" 115 | CODE 116 | "addtwo=LibraryFunctionLoad[libPath, \"addtwo\", LinkObject, LinkObject] 117 | reverseString=LibraryFunctionLoad[libPath, \"reverseString\", LinkObject, LinkObject] 118 | Print[addtwo[1,1]] 119 | Print[reverseString[\"Mathematica\"]]" 120 | ) 121 | 122 | do_mathematica_librarylink_test(demo_LinkObject 123 | # Expected output regular expression 124 | "2 125 | \"acitamehtaM\"" 126 | CODE 127 | "addtwo=LibraryFunctionLoad[libPath, \"addtwo\", LinkObject, LinkObject] 128 | reverseString=LibraryFunctionLoad[libPath, \"reverseString\", LinkObject, LinkObject] 129 | Print[addtwo[1,1]] 130 | Print[reverseString[\"Mathematica\"]]" 131 | ) 132 | 133 | do_mathematica_librarylink_test(demo_eval 134 | # Expected output regular expression 135 | "\nMyFunction::info: Message called from within Library function. 136 | 3" 137 | CODE 138 | "fun=LibraryFunctionLoad[libPath, \"function1\", {Integer, Integer}, Integer] 139 | MyFunction::info=\"`1`\" 140 | Print[fun[1,2]]" 141 | ) 142 | 143 | do_mathematica_librarylink_test(demo_managed 144 | # Expected output regular expression 145 | "True.*True" 146 | SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/demo_managed_test.m") 147 | 148 | do_mathematica_librarylink_test(demo_callback 149 | # Expected output regular expression 150 | "True.*True" 151 | SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/demo_callback.m") 152 | 153 | do_mathematica_librarylink_test(demo_sparse 154 | # Expected output regular expression 155 | "\"ImplicitValue\" *-> *0" 156 | SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/demo_sparse.m") 157 | 158 | do_mathematica_librarylink_test(demo_shared 159 | # Expected output regular expression 160 | "10. 161 | 15. 162 | 20." 163 | SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/demo_shared.m") 164 | 165 | do_mathematica_librarylink_test(demo_numericarray 166 | # Expected output regular expression 167 | "{5, 4, 3, 2, 1} 168 | {.*} 169 | {.*} 170 | 15799" 171 | SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/demo_numericarray_test.m") 172 | 173 | add_convenience_test_target(LibraryLinkTests "LibraryLink") 174 | -------------------------------------------------------------------------------- /LibraryLinkExamples/demo_callback.m: -------------------------------------------------------------------------------- 1 | (* Mathematica LibraryLink test script for demo_callback.c *) 2 | 3 | (* Hint: libPath is initialized in test init code *) 4 | applyCallback = LibraryFunctionLoad[libPath,"apply_callback",{{Real,_}},{Real,_}]; 5 | 6 | cfSin = Compile[{{x, _Real}}, Sin[x]] 7 | 8 | ConnectLibraryCallbackFunction["demo_callback_manager", cfSin] 9 | 10 | array = RandomReal[1, 5]; applyCallback[array] 11 | 12 | applySin = LibraryFunctionLoad[libPath,"apply_sin",{{Real,_}},{Real,_}]; 13 | 14 | testdata = RandomReal[{-Pi,Pi},{1000,1000, 10}]; 15 | 16 | testsin = applySin[testdata] 17 | 18 | testcallback = applyCallback[testdata] 19 | 20 | Print@SameQ[testsin,testcallback] 21 | 22 | cfSinC= Compile[{{x,_Real}},Sin[x],CompilationTarget->"C"]; 23 | 24 | ConnectLibraryCallbackFunction["demo_callback_manager",cfSinC] 25 | 26 | testcallback = applyCallback[testdata] 27 | 28 | Print@SameQ[testsin,testcallback] 29 | -------------------------------------------------------------------------------- /LibraryLinkExamples/demo_managed_test.m: -------------------------------------------------------------------------------- 1 | (* Mathematica LibraryLink test script for demo_managed.cxx *) 2 | 3 | (* Hint: libPath is initialized in test init code *) 4 | setInstanceState = LibraryFunctionLoad[libPath,"setInstanceState",{Integer, {Integer, 1}},"Void"]; 5 | getInstanceState = LibraryFunctionLoad[libPath, "getInstanceState",{{Integer}}, {Integer, 1}]; 6 | releaseInstance = LibraryFunctionLoad[libPath, "releaseInstance", {{Integer}},"Void"]; 7 | generateFromInstance = LibraryFunctionLoad[libPath, "generateFromInstance",{Integer,{Integer, _}},{Real,_}]; 8 | getAllInstanceIDs = LibraryFunctionLoad[libPath, "getAllInstanceIDs", {},{Integer,1}]; 9 | 10 | LCGQ[e_] := ManagedLibraryExpressionQ[e,"LCG"]; 11 | 12 | instanceID[inst_] := ManagedLibraryExpressionID[inst,"LCG"]; 13 | 14 | CreateLCG[a_Integer, c_Integer, m_Integer, x_Integer] := Module[{res}, 15 | res = CreateManagedLibraryExpression["LCG", LCG]; 16 | setInstanceState[instanceID[res],{a,c,m,x}]; 17 | res 18 | ]; 19 | 20 | ListLCGs[]:=Map[LCG[#]->getInstanceState[#]&,getAllInstanceIDs[]] 21 | 22 | LCGRandom[inst_?LCGQ] := LCGRandom[inst,{}]; 23 | LCGRandom[inst_?LCGQ, len_Integer]:= LCGRandom[inst,{len}]; 24 | LCGRandom[inst_?LCGQ, dims:{(_Integer?Positive)...}]:= Module[{id = instanceID[inst]}, 25 | generateFromInstance[id, dims] 26 | ]; 27 | 28 | g = CreateLCG[1664525, 1013904223, 2^($SystemWordLength/2), 0] 29 | Print@LCGQ[g] 30 | Print@LCGRandom[g] 31 | 32 | g1 = CreateLCG[1664525, 1013904223, 2^($SystemWordLength/2), 0] 33 | Print@LCGRandom[g1, 2] 34 | Print@ListLCGs[] 35 | Print@LCGRandom[LCG[1]] 36 | 37 | g2 = CreateLCG[1664525, 1013904223, 2^($SystemWordLength/2), 0]; LCGRandom[g2, {2, 2}] 38 | releaseInstance[2]; 39 | Print@ListLCGs[] 40 | 41 | g2 =. 42 | Print@ListLCGs[] 43 | Print@LCGQ[g] 44 | -------------------------------------------------------------------------------- /LibraryLinkExamples/demo_numericarray_test.m: -------------------------------------------------------------------------------- 1 | (* Mathematica LibraryLink test script for demo_numericarray.cxx *) 2 | 3 | (* Hint: libPath is initialized in test init code *) 4 | numericArrayReverse=LibraryFunctionLoad[ 5 | libPath, "numericArrayReverse", 6 | {{LibraryDataType[NumericArray],"Constant"}}, 7 | {LibraryDataType[NumericArray]}]; 8 | numericArrayComplexConjugate=LibraryFunctionLoad[ 9 | libPath, "numericArrayComplexConjugate", 10 | {{LibraryDataType[NumericArray],"Constant"}}, 11 | {LibraryDataType[NumericArray]}]; 12 | readBytesFromFile=LibraryFunctionLoad[ 13 | libPath, "readBytesFromFile", 14 | {"UTF8String"}, 15 | {LibraryDataType[ByteArray]}]; 16 | 17 | na = NumericArray[Range[5], "Integer32"] 18 | Print@Normal@numericArrayReverse[na] 19 | 20 | na1 = NumericArray[RandomComplex[2 + 3 I, 3], "ComplexReal32"] 21 | Print@Normal@numericArrayComplexConjugate[na1] 22 | 23 | na2 = NumericArray[Range[5], "Integer32"] 24 | Print@Normal@numericArrayComplexConjugate[na2] 25 | 26 | ba = readBytesFromFile[FindFile["ExampleData/rose.gif"]] 27 | Print@Length@ba 28 | 29 | -------------------------------------------------------------------------------- /LibraryLinkExamples/demo_shared.m: -------------------------------------------------------------------------------- 1 | (* Mathematica LibraryLink test script for demo_shared.c *) 2 | 3 | (* Hint: libPath is initialized in test init code *) 4 | loadFun=LibraryFunctionLoad[libPath,"loadArray",{{Real,_,"Shared"}},Integer]; 5 | unloadFun=LibraryFunctionLoad[libPath,"unloadArray",{},Integer]; 6 | getFunVector=LibraryFunctionLoad[libPath,"getElementVector",{Integer},Real]; 7 | 8 | array = Range[1., 20]; 9 | loadFun[array] 10 | Print@getFunVector[10] 11 | Print@getFunVector[15] 12 | Print@getFunVector[20] 13 | unloadFun[ ] 14 | -------------------------------------------------------------------------------- /LibraryLinkExamples/demo_sparse.m: -------------------------------------------------------------------------------- 1 | (* Mathematica LibraryLink test script for demo_sparse.c *) 2 | 3 | (* Hint: libPath is initialized in test init code *) 4 | props=LibraryFunctionLoad[libPath,"sparse_properties",{"UTF8String",{LibraryDataType[SparseArray],"Constant"}},{_,_}]; 5 | 6 | s=SparseArray[{{1,0,0},{2,0,3}}] 7 | Print@props["ExplicitValues",s] 8 | 9 | pTable[s_] := Table[p->props[p,s],{p,{"ImplicitValue","ExplicitValues","RowPointers","ColumnIndices", "ExplicitPositions","Normal"}}] 10 | Print@pTable[s] 11 | 12 | s = SparseArray[{{1,0,0},{2 ,0,3}},Automatic,1.] 13 | Print@pTable[s] 14 | 15 | modifyValues=LibraryFunctionLoad[libPath,"sparse_modify_values",{{LibraryDataType[SparseArray,Real],"Shared"},{LibraryDataType[List,Real, 1],"Constant"}},LibraryDataType[SparseArray]] 16 | 17 | s = SparseArray[{{1,1}->1.,{2,1}->-1.,{2,2}->3.}] 18 | s1 = modifyValues[s,{-1,0,4}] 19 | Print@pTable[s] 20 | Print@pTable[s1] 21 | -------------------------------------------------------------------------------- /LibraryLinkExamples/demo_string_test.m: -------------------------------------------------------------------------------- 1 | (* Mathematica LibraryLink test script for demo_string.c *) 2 | 3 | (* Hint: libPath is initialized in test init code *) 4 | countSubstring=LibraryFunctionLoad[libPath, "countSubstring", {"UTF8String", "UTF8String"}, Integer] 5 | encodeString=LibraryFunctionLoad[libPath, "encodeString", {"UTF8String", Integer}, "UTF8String"] 6 | reverseString=LibraryFunctionLoad[libPath, "reverseString", {"UTF8String"}, "UTF8String" ] 7 | Print[countSubstring["Mathematica","a"]] 8 | Print[encodeString["Mathematica", 5]] 9 | Print[reverseString["Mathematica"]] 10 | -------------------------------------------------------------------------------- /LibraryLinkExamples/demo_test.m: -------------------------------------------------------------------------------- 1 | (* Mathematica LibraryLink test script for demo.c *) 2 | 3 | (* Hint: libPath is initialized in test init code *) 4 | demoII=LibraryFunctionLoad[libPath, "demo_I_I", {Integer}, Integer] 5 | demoRR=LibraryFunctionLoad[libPath, "demo_R_R", {Real}, Real] 6 | demoIRR=LibraryFunctionLoad[libPath, "demo_IR_R", {Integer, Real}, Real] 7 | demoTIR=LibraryFunctionLoad[libPath, "demo_TI_R", {{Real, 1}, Integer}, Real] 8 | demo1TIR=LibraryFunctionLoad[libPath, "demo1_TI_R", {{Real, 1, "Manual"}, Integer}, Real] 9 | demo2TIR=LibraryFunctionLoad[libPath, "demo2_TI_R", {{Real, 1, "Shared"}, Integer}, Real] 10 | demoIT=LibraryFunctionLoad[libPath, "demo_I_T", {Integer}, {Integer, 1}] 11 | demoTTT=LibraryFunctionLoad[libPath, "demo_TT_T", {{Real, 1}, {Integer, 1}}, {Real, _}] 12 | demoTTTT=LibraryFunctionLoad[libPath, "demo_TTT_T", {{Real, 1}, {Integer, _}, {Real, _}}, {Integer, _}] 13 | demoTT=LibraryFunctionLoad[libPath, "demo_T_T", {{_, _}}, {_, _}] 14 | demoBoolean1=LibraryFunctionLoad[libPath, "demoBoolean1", {"Boolean"}, "Boolean"] 15 | demoComplex1=LibraryFunctionLoad[libPath, "demoComplex1", {Complex}, Complex] 16 | demoVoid=LibraryFunctionLoad[libPath, "demoVoid", {}, "Void"] 17 | array = Range[1., 10] 18 | Print[demoII[10]] 19 | Print[demoRR[10.]] 20 | Print[demoIRR[3,13.]] 21 | Print[demoTIR[array,1]] 22 | Print[demo1TIR[array,2]] 23 | Print[demo2TIR[array,3]] 24 | Print[demoIT[5]] 25 | Print[demoTTT[array,{1}]] 26 | Print[demoTTTT[array,1,10.0]] 27 | Print[demoTT[{{1,2},{3,4}}]] 28 | Print[demoBoolean1[True]] 29 | Print[demoComplex1[1. + 2. I]] 30 | Print[demoVoid[]] 31 | -------------------------------------------------------------------------------- /MANUAL.md: -------------------------------------------------------------------------------- 1 | FindMathematica manual 2 | ====================== 3 | 4 | FindMathematica is a CMake module that tries to find a Wolfram Language installation and provides 5 | CMake functions for its C/C++ interface. 6 | 7 | Installation 8 | ------------ 9 | 10 | Copy the directory `CMake/Mathematica` to the root directory of your CMake project. In the 11 | top-level `CMakeList.txt` file add the module directory to the CMake module search path: 12 | 13 | set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/Mathematica" ${CMAKE_MODULE_PATH}) 14 | 15 | Optional CMake MUnit testing support requires the installation of the Wolfram MUnit package. MUnit 16 | is built into *Mathematica* 10 or later. For earlier versions of *Mathematica*, a compatible MUnit 17 | package ships with Wolfram Workbench 2.0. The JAR file `com.wolfram.eclipse.testing_2.0.126.jar` in 18 | the `plugins` subdirectory of the Workbench installation folder contains different MUnit package 19 | versions for *Mathematica* versions 5.2 to 9.0. 20 | 21 | To install MUnit, extract the MUnit package version appropriate for your installed *Mathematica* 22 | version from the JAR file to a directory on the *Mathematica* `$Path` (e.g., 23 | `$BaseDirectory/Applications` or `$UserBaseDirectory/Applications`). Alternatively you can 24 | copy the MUnit package to the FindMathematica module directory which is automatically prepended 25 | to `$Path` when the Wolfram Language kernel is launched through the FindMathematica module. 26 | 27 | If you plan on generating Wolfram Language documentation with CMake, the installation of two Wolfram 28 | documentation build packages, which also ship with Wolfram Workbench 2.0, is required. 29 | The JAR file `com.wolfram.eclipse.paclet.develop_2.0.138.jar` in the `plugins` subdirectory of the 30 | Workbench installation folder contains the package folders `DocumentationBuild` and `Transmogrify`. 31 | These must be copied to a directory on the Wolfram Language `$Path`. 32 | 33 | The `DocumentationBuild` package also requires the installation of [Apache Ant][aant]. In order for 34 | Apache Ant to be found by CMake, the environment variable `ANT_HOME` needs to point to Apache Ant's 35 | installation directory. 36 | 37 | MathLink and WSTP require the installation of [libuuid][uuid] under Linux. To install `libuuid` 38 | under Debian-based distros run: 39 | 40 | $ sudo apt install uuid-dev 41 | 42 | To install `libuuid` under RedHat-based distros run: 43 | 44 | $ sudo dnf install libuuid-devel 45 | 46 | Usage 47 | ----- 48 | 49 | If you are new to CMake, check out the [CMake tutorial][cmtut] first. 50 | 51 | To find the newest Wolfram Language installation in a CMake list file, run the `find_package` 52 | command: 53 | 54 | find_package(Mathematica) 55 | 56 | The FindMathematica module will look for a Wolfram Language installation in the default installation 57 | location of the used platform. Under Windows, it will also use installation locations from the 58 | Windows Registry. 59 | 60 | By default, FindMathematica will return the newest Wolfram Language installation it can find. 61 | To find a minimum version of Wolfram Language, run the `find_package` command with a version 62 | argument: 63 | 64 | find_package(Mathematica 10.0) 65 | 66 | To find a specific version of Wolfram Language, run the `find_package` command with a version 67 | argument and the parameter `EXACT`: 68 | 69 | find_package(Mathematica 10.0.2 EXACT) 70 | 71 | Depending on the version of Wolfram Language, the FindMathematica module will try to find the 72 | components `MathLink`, `WolframLibrary`, `WSTP`, `JLink` and `MUnit`. To explicitly specify the 73 | components to be found, use: 74 | 75 | find_package(Mathematica COMPONENTS MathLink WolframLibrary) 76 | 77 | The package ships as a fully functional CMake project that demonstrates how to use functionality 78 | provided by the FindMathematica module: 79 | 80 | * `MathematicaExamples` show how to run plain Wolfram Language code as part of the build process. 81 | * `MathLinkExamples` build all standard MathLink example files. 82 | * `WSTPExamples` build all standard WSTP example files. 83 | * `LibraryLinkExamples` build all standard LibraryLink example files. 84 | * `CodeGenerationExamples` builds binaries from Wolfram Language compiled functions exported to C. 85 | * `MUnitExamples` demonstrate how to run Wolfram Language MUnit test files as CMake tests. 86 | * `DocumentationExamples` demonstrate how to build Wolfram Language documentation. 87 | * `JLinkExamples` builds JAR archives from J/Link example source files. 88 | 89 | ### Basic Windows Usage 90 | 91 | #### Visual Studio 92 | 93 | To build the FindMathematica project with Visual Studio C++ for 64-bit Windows, open a Visual 94 | Studio command prompt, change directory to the `FindMathematica` root directory and run the 95 | following commands: 96 | 97 | D:\FindMathematica>mkdir build 98 | D:\FindMathematica>cd build 99 | D:\FindMathematica\build>cmake -G "Visual Studio 16 2019" -A x64 .. 100 | 101 | Then open the generated Visual Studio solution file with Visual Studio C++ 2019: 102 | 103 | D:\FindMathematica\build>start Mathematica-project.sln 104 | 105 | Alternatively, you can build and test the project's "Debug" configuration from the command prompt: 106 | 107 | D:\FindMathematica\build>cmake --build . --config Debug 108 | D:\FindMathematica\build>ctest --build-config Debug 109 | 110 | To build the "Release" configuration and install the built files to your user base directory, run: 111 | 112 | D:\FindMathematica\build>cmake --build . --target install --config Release 113 | 114 | To build the Wolfram Language documentation in notebook format, run: 115 | 116 | D:\FindMathematica\build>cmake --build . --config Debug --target documentation 117 | 118 | FindMathematica supports building 32-bit and 64-bit MathLink executables and LibraryLink dynamic 119 | libraries using the appropriate link libraries that ship with the Windows version. 120 | If you are using a 32-bit version of Windows, you can run the Wolfram Language kernel only in 121 | 32-bit mode, though. If you are using a 64-bit version of Windows, you can run the Wolfram Language 122 | kernel both as a 64-bit native executable or as a 32-bit executable under WoW64. 123 | 124 | #### MinGW 125 | 126 | To build the FindMathematica project with [MinGW][mingw] run the following commands from a command 127 | prompt: 128 | 129 | D:\FindMathematica\build>cmake -G "MinGW Makefiles" .. 130 | D:\FindMathematica\build>mingw32-make 131 | 132 | ### Basic Linux Usage 133 | 134 | To build the FindMathematica project with the CMake makefile generator, open a shell session 135 | in the `FindMathematica` root directory and enter the following commands: 136 | 137 | $ mkdir build 138 | $ cd build 139 | $ cmake .. 140 | $ make 141 | 142 | Optionally, you can run all tests and install the built files to your user base directory: 143 | 144 | $ make test 145 | $ make install 146 | 147 | To build the Wolfram Language documentation in notebook format, run: 148 | 149 | $ make documentation 150 | 151 | FindMathematica supports building 32-bit and 64-bit MathLink executables and LibraryLink shared 152 | libraries using the appropriate link libraries that ship with the Linux version. 153 | If you are using a 64-bit version of Linux, you can run the Wolfram Language kernel both as a 64-bit 154 | executable or as a 32-bit executable. 155 | 156 | To cross-compile to 32-bit Linux under 64-bit Linux, the packages `ia32-libs` and `libc6-dev-i386` 157 | need to be installed. To force a 32-bit build then, run: 158 | 159 | $ cmake -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32 .. 160 | 161 | ### Basic macOS Usage 162 | 163 | To build the FindMathematica project with the CMake makefile generator, open Terminal.app, 164 | change to the `FindMathematica` root directory and enter the following commands: 165 | 166 | $ mkdir build 167 | $ cd build 168 | $ cmake .. 169 | $ make 170 | 171 | Optionally, you can run all tests and install the built files to your user base directory: 172 | 173 | $ make test 174 | $ make install 175 | 176 | To build the Wolfram Language documentation in notebook format, run: 177 | 178 | $ make documentation 179 | 180 | To build the FindMathematica project with the Xcode project generator, run CMake with the 181 | following arguments: 182 | 183 | $ cmake -G "Xcode" .. 184 | 185 | Then open the generated Xcode project file `Mathematica-project.xcodeproj` with Xcode.app. 186 | 187 | FindMathematica supports building MathLink executables and LibraryLink shared libraries for any 188 | macOS architecture type supported by the installed macOS version. 189 | To select the build target architecture types, set the CMake `CMAKE_OSX_ARCHITECTURES` variable. 190 | 191 | E.g., to build a macOS universal binary use the following setting: 192 | 193 | $ cmake "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" .. 194 | 195 | Used Variables 196 | -------------- 197 | 198 | The module uses the following variables upon the invocation of `find_package`: 199 | 200 | * `Mathematica_FIND_VERSION` - full requested Wolfram Language version string 201 | * `Mathematica_FIND_VERSION_EXACT` - `TRUE` if `EXACT` option was given upon `find_package` 202 | * `Mathematica_FIND_QUIETLY` - `TRUE` if `QUIET` option was given upon `find_package` 203 | * `Mathematica_FIND_REQUIRED` - `TRUE` if `REQUIRED` option was given upon `find_package` 204 | * `Mathematica_FIND_COMPONENTS` - Set of Wolfram Language components requested upon `find_package` 205 | * `Mathematica_FIND_REQUIRED_MathLink` - `TRUE` if `REQUIRED` option was given for component MathLink 206 | * `Mathematica_FIND_REQUIRED_WSTP` - `TRUE` if `REQUIRED` option was given for component MathLink 207 | * `Mathematica_FIND_REQUIRED_WolframLibrary` - `TRUE` if `REQUIRED` option was given for component WolframLibrary 208 | * `Mathematica_FIND_REQUIRED_JLink` - `TRUE` if `REQUIRED` option was given for component JLink 209 | * `Mathematica_FIND_REQUIRED_MUnit` - `TRUE` if `REQUIRED` option was given for component MUnit 210 | * `Mathematica_USE_STATIC_LIBRARIES` - if `TRUE`, prefer static libraries to dynamic libraries (defaults to `FALSE`) 211 | * `Mathematica_USE_MINIMAL_LIBRARIES` - if `TRUE`, prefer minimal libraries to full libraries (defaults to `FALSE`) 212 | * `Mathematica_USE_LIBCXX_LIBRARIES` - if `TRUE`, prefer libc++ linked libraries to libstdc++ linked libraries (defaults to `FALSE`, only applies to macOS) 213 | * `Mathematica_MathLink_FIND_VERSION_MAJOR` - requested MathLink interface version (e.g., `"3"`) 214 | * `Mathematica_MathLink_FIND_VERSION_MINOR` - requested MathLink revision number (e.g., `"16"`) 215 | * `Mathematica_WSTP_FIND_VERSION_MAJOR` - requested WSTP interface version (e.g., `"4"`) 216 | * `Mathematica_WSTP_FIND_VERSION_MINOR` - requested WSTP revision version (e.g., `"25"`) 217 | * `Mathematica_DEBUG` - if `TRUE`, enable debugging output (defaults to `FALSE`) 218 | * `Mathematica_RUN_KERNEL_ON_CONFIGURE` - if `TRUE`, allow FindMathematica to implicitly run the *Mathematica* kernel at CMake configure time (defaults to `TRUE`) 219 | 220 | Defined Variables 221 | ----------------- 222 | 223 | The module defines the following variables: 224 | 225 | * `Mathematica_CMAKE_MODULE_DIR` - directory containing the FindMathematica module (always prepended to `$Path`) 226 | * `Mathematica_CMAKE_MODULE_VERSION` - FindMathematica module version 227 | * `Mathematica_FOUND` - True if Wolfram Language installation and all required components are found 228 | * `Mathematica_SYSTEM_ID` - default build target platform System ID (e.g., `"Windows"` or `"Linux"`) 229 | * `Mathematica_SYSTEM_IDS` - list of supported build target platform System IDs (e.g., `"MacOSX"`, `"MacOSX-x86"`, `"MacOSX-x86-64"`) 230 | * `Mathematica_HOST_SYSTEM_ID` - default host platform System ID (e.g., `"Windows-x86-64"` or `"MacOSX-x86-64"`) 231 | * `Mathematica_HOST_SYSTEM_IDS` - list of System IDs available with the host installation 232 | * `Mathematica_ROOT_DIR` - Wolfram Language installation directory valid for the build target platform 233 | * `Mathematica_HOST_ROOT_DIR` - Wolfram Language installation directory valid for the host platform (corresponds to `$InstallationDirectory`) 234 | * `Mathematica_KERNEL_EXECUTABLE` - path to host Wolfram Language kernel executable 235 | * `Mathematica_FRONTEND_EXECUTABLE` - path to host Wolfram Language frontend executable 236 | * `Mathematica_BASE_DIR` - directory for system-wide files (corresponds to `$BaseDirectory`) 237 | * `Mathematica_USERBASE_DIR` - directory for user-specific files (corresponds to `$UserBaseDirectory`) 238 | * `Mathematica_INCLUDE_DIR` - header file `mdefs.h` include directory 239 | * `Mathematica_INCLUDE_DIRS` - list of include directories for all components 240 | * `Mathematica_LIBRARIES` - list of libraries to link against for all components 241 | * `Mathematica_LIBRARY_DIRS` - list of Wolfram Language library directories for all components 242 | * `Mathematica_RUNTIME_LIBRARY_DIRS` - list of Wolfram Language library directories required at runtime 243 | * `Mathematica_RUNTIME_LIBRARY_DIRS_DEBUG` - list of debug Wolfram Language library directories required at runtime 244 | * `Mathematica_VERSION` - Wolfram Language version number given as "major.minor.patch" 245 | * `Mathematica_VERSION_MAJOR` - Wolfram Language major version number 246 | * `Mathematica_VERSION_MINOR` - Wolfram Language minor version number 247 | * `Mathematica_VERSION_PATCH` - Wolfram Language patch version number 248 | * `Mathematica_VERSION_STRING` - Wolfram Language version string given as "major.minor.patch" 249 | * `Mathematica_VERSION_COUNT` - Wolfram Language version component count (usually 3) 250 | * `Mathematica_CREATION_ID` - Wolfram Language installation creation ID number 251 | 252 | The module defines the following variables for component `WolframLibrary`: 253 | 254 | * `Mathematica_WolframLibrary_FOUND` - True if the Wolfram Language installation has WolframLibrary 255 | * `Mathematica_WolframLibrary_INCLUDE_DIR` - WolframLibrary include directory (contains header files `WolframLibrary.h` and `WolframRTL.h`) 256 | * `Mathematica_WolframLibrary_LIBRARY` - path to WolframRTL library for the default target platform (e.g., `WolframRTL_Minimal.lib`) 257 | * `Mathematica_WolframLibrary_LIBRARIES` - WolframRTL libraries for all target platforms and required system libraries 258 | * `Mathematica_WolframLibrary_VERSION` - WolframLibrary version number given as "version" 259 | * `Mathematica_WolframLibrary_VERSION_MAJOR` - WolframLibrary version number 260 | * `Mathematica_WolframLibrary_VERSION_STRING` - WolframLibrary version number given as "version" 261 | * `Mathematica_WolframLibrary_VERSION_COUNT` - WolframLibrary number of version components (usually 1) 262 | * `Mathematica_LibraryLink_PACKAGE_FILE` - LibraryLink package file 263 | * `Mathematica_LibraryLink_PACKAGE_DIR` - LibraryLink package root directory 264 | * `Mathematica_WolframLibrary_RUNTIME_LIBRARY_DIRS` - list of WolframLibrary library directories required at runtime 265 | * `Mathematica_WolframLibrary_RUNTIME_LIBRARY_DIRS_DEBUG` - list of debug WolframLibrary library directories required at runtime 266 | 267 | The module defines the following variables for component `MathLink`: 268 | 269 | * `Mathematica_MathLink_FOUND` - True if the Wolfram Language installation has MathLink SDK 270 | * `Mathematica_MathLink_ROOT_DIR` - MathLink C SDK root directory for the default target platform 271 | * `Mathematica_MathLink_HOST_ROOT_DIR` - MathLink C SDK root directory for the host platform 272 | * `Mathematica_MathLink_INCLUDE_DIR` - header file `mathlink.h` include directory for the default target platform 273 | * `Mathematica_MathLink_LIBRARY` - path to MathLink library for the default target platform 274 | * `Mathematica_MathLink_LIBRARIES` - MathLink library for all target platforms and required system libraries 275 | * `Mathematica_MathLink_MPREP_EXECUTABLE` - path to host `mprep` executable (MathLink template file preprocessor) 276 | * `Mathematica_MathLink_HOST_INCLUDE_DIR` - header file `mathlink.h` include directory for the host platform 277 | * `Mathematica_MathLink_DEFINITIONS` - MathLink compile definitions, e.g., `-DMLINTERFACE=3` 278 | * `Mathematica_MathLink_LINKER_FLAGS` - MathLink linker flags 279 | * `Mathematica_MathLink_VERSION` - MathLink version number given as "interface.revision" 280 | * `Mathematica_MathLink_VERSION_MAJOR` - MathLink interface number 281 | * `Mathematica_MathLink_VERSION_MINOR` - MathLink revision number 282 | * `Mathematica_MathLink_VERSION_STRING` - MathLink version string given as "interface.revision" 283 | * `Mathematica_MathLink_VERSION_COUNT` - MathLink version component count (usually 2) 284 | * `Mathematica_MathLink_RUNTIME_LIBRARY_DIRS` - list of MathLink library directories required at runtime 285 | * `Mathematica_MathLink_RUNTIME_LIBRARY_DIRS_DEBUG` - list of debug MathLink library directories required at runtime 286 | 287 | The module defines the following variables for component `WSTP`: 288 | 289 | * `Mathematica_WSTP_FOUND` - True if the Wolfram Language installation has WSTP SDK 290 | * `Mathematica_WSTP_ROOT_DIR` - WSTP C SDK root directory for the default target platform 291 | * `Mathematica_WSTP_HOST_ROOT_DIR` - WSTP C SDK root directory for the host platform 292 | * `Mathematica_WSTP_INCLUDE_DIR` - header file `wstp.h` include directory for the default target platform 293 | * `Mathematica_WSTP_LIBRARY` - path to WSTP library for the default target platform 294 | * `Mathematica_WSTP_LIBRARIES` - WSTP library for all target platforms and required system libraries 295 | * `Mathematica_WSTP_WSPREP_EXECUTABLE` - path to host `wsprep` executable (WSTP template file preprocessor) 296 | * `Mathematica_WSTP_HOST_INCLUDE_DIR` - header file wstp.h include directory for the host platform 297 | * `Mathematica_WSTP_DEFINITIONS` - WSTP compile definitions, e.g., `-DWSINTERFACE=4` 298 | * `Mathematica_WSTP_LINKER_FLAGS` - WSTP linker flags 299 | * `Mathematica_WSTP_VERSION` - WSTP version number given as "interface.revision" 300 | * `Mathematica_WSTP_VERSION_MAJOR` - WSTP interface number 301 | * `Mathematica_WSTP_VERSION_MINOR` - WSTP revision number 302 | * `Mathematica_WSTP_VERSION_STRING` - WSTP version string given as "interface.revision" 303 | * `Mathematica_WSTP_VERSION_COUNT` - WSTP version component count (usually 2) 304 | * `Mathematica_WSTP_RUNTIME_LIBRARY_DIRS` - list of WSTP library directories required at runtime 305 | * `Mathematica_WSTP_RUNTIME_LIBRARY_DIRS_DEBUG` - list of debug WSTP library directories required at runtime 306 | 307 | The module defines the following variables for component `JLink`: 308 | 309 | * `Mathematica_JLink_FOUND` - True if the Wolfram Language installation has J/Link SDK 310 | * `Mathematica_JLink_PACKAGE_DIR` - J/Link package root directory 311 | * `Mathematica_JLink_JAR_FILE` - Full path to J/Link JAR file 312 | * `Mathematica_JLink_JAVA_HOME` - Full path to Java SDK bundled with *Mathematica* 313 | * `Mathematica_JLink_JAVA_EXECUTABLE` - path to the host Java runtime executable used by J/Link 314 | * `Mathematica_JLink_RUNTIME_LIBRARY` - Full path to JLinkNativeLibrary 315 | * `Mathematica_JLink_VERSION` - J/Link version number given as "major.minor.patch" 316 | * `Mathematica_JLink_VERSION_MAJOR` - J/Link major version number 317 | * `Mathematica_JLink_VERSION_MINOR` - J/Link minor version number 318 | * `Mathematica_JLink_VERSION_PATCH` - J/Link patch version number 319 | * `Mathematica_JLink_VERSION_STRING` - J/Link version string given as "major.minor.patch" 320 | * `Mathematica_JLink_VERSION_COUNT` - JLink version component count (usually 3) 321 | 322 | The module defines the following variables for component `MUnit`: 323 | 324 | * `Mathematica_MUnit_FOUND` - True if the Wolfram Language installation has the Wolfram MUnit package 325 | * `Mathematica_MUnit_PACKAGE_FILE` - MUnit package file 326 | * `Mathematica_MUnit_PACKAGE_DIR` - MUnit package root directory 327 | * `Mathematica_MUnit_VERSION` - MUnit version number given as "major.minor.patch" 328 | * `Mathematica_MUnit_VERSION_MAJOR` - MUnit major version number 329 | * `Mathematica_MUnit_VERSION_MINOR` - MUnit minor version number 330 | * `Mathematica_MUnit_VERSION_PATCH` - MUnit patch version number 331 | * `Mathematica_MUnit_VERSION_STRING` - MUnit version string given as "major.minor.patch" 332 | * `Mathematica_MUnit_VERSION_COUNT` - MUnit version component count (usually 3) 333 | 334 | Defined Functions 335 | ----------------- 336 | 337 | Depending on the Wolfram Language version and components found, the module defines the following functions: 338 | 339 | Mathematica_TO_NATIVE_STRING(string result) 340 | 341 | Converts a CMake string to a Wolfram Language `InputForm` string usable verbatim in Wolfram Language code. 342 | 343 | Mathematica_TO_NATIVE_LIST(result [element ...]) 344 | 345 | Converts a CMake list to a Wolfram Language `InputForm` list usable verbatim in Wolfram Language code. 346 | 347 | Mathematica_TO_NATIVE_PATH(path result) 348 | 349 | Converts a CMake file path to a Wolfram Language `InputForm` file path for the native platform usable 350 | verbatim in Wolfram Language code. The input can be a single CMake path or a CMake path list. 351 | If multiple consecutive paths in the CMake path list share the same directory portion, the 352 | function produces a compact Wolfram Language code representation using `Map` and `ToFileName`. 353 | 354 | Mathematica_EXECUTE( 355 | [ CODE [ stmnt ...] ] 356 | [ SCRIPT