-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindMathematica.cmake
More file actions
4471 lines (4327 loc) · 174 KB
/
FindMathematica.cmake
File metadata and controls
4471 lines (4327 loc) · 174 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# - Try to find Mathematica installation and provide CMake functions for its C/C++ interface
#
# See the FindMathematica manual for usage hints.
#
#=============================================================================
# Copyright 2010-2016 Sascha Kratky
#
# Permission is hereby granted, free of charge, to any person)
# obtaining a copy of this software and associated documentation)
# files (the "Software"), to deal in the Software without)
# restriction, including without limitation the rights to use,)
# copy, modify, merge, publish, distribute, sublicense, and/or sell)
# copies of the Software, and to permit persons to whom the)
# Software is furnished to do so, subject to the following)
# conditions:)
#
# The above copyright notice and this permission notice shall be)
# included in all copies or substantial portions of the Software.)
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,)
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES)
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND)
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT)
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,)
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING)
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR)
# OTHER DEALINGS IN THE SOFTWARE.)
#=============================================================================
# we need the CMakeParseArguments module
# call cmake_minimum_required, but prevent modification of the CMake policy stack
cmake_policy(PUSH)
cmake_minimum_required(VERSION 2.8.12)
cmake_policy(POP)
set (Mathematica_CMAKE_MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}")
set (Mathematica_CMAKE_MODULE_VERSION "3.2.2")
# activate select policies
if (POLICY CMP0025)
# Compiler id for Apple Clang is now AppleClang
cmake_policy(SET CMP0025 NEW)
endif()
if (POLICY CMP0026)
# disallow use of the LOCATION target property
if (CYGWIN OR MSYS)
# Cygwin and MSYS do not produce workable Mathematica paths using
# the $<TARGET_FILE:...> notation
cmake_policy(SET CMP0026 OLD)
else()
cmake_policy(SET CMP0026 NEW)
endif()
endif()
if (POLICY CMP0038)
# targets may not link directly to themselves
cmake_policy(SET CMP0038 NEW)
endif()
if (POLICY CMP0039)
# utility targets may not have link dependencies
cmake_policy(SET CMP0039 NEW)
endif()
if (POLICY CMP0040)
# target in the TARGET signature of add_custom_command() must exist
cmake_policy(SET CMP0040 NEW)
endif()
if (POLICY CMP0045)
# error on non-existent target in get_target_property
cmake_policy(SET CMP0045 NEW)
endif()
if (POLICY CMP0046)
# error on non-existent dependency in add_dependencies
cmake_policy(SET CMP0046 NEW)
endif()
if (POLICY CMP0049)
# do not expand variables in target source entries
cmake_policy(SET CMP0049 NEW)
endif()
if (POLICY CMP0050)
# disallow add_custom_command SOURCE signatures
cmake_policy(SET CMP0050 NEW)
endif()
if (POLICY CMP0051)
# include TARGET_OBJECTS expressions in a target's SOURCES property
cmake_policy(SET CMP0051 NEW)
endif()
if (POLICY CMP0053)
# simplify variable reference and escape sequence evaluation
cmake_policy(SET CMP0053 NEW)
endif()
if (POLICY CMP0054)
# only interpret if() arguments as variables or keywords when unquoted
cmake_policy(SET CMP0054 NEW)
endif()
include(TestBigEndian)
include(CMakeParseArguments)
include(FindPackageHandleStandardArgs)
include(CMakeFindFrameworks)
# internal function to convert Windows path to Cygwin workable CMake path
# E.g., "C:\Program Files" is converted to "/cygdrive/c/Program Files"
# file(TO_CMAKE_PATH "C:\Program Files" ...) would result in unworkable "C;/Program Files"
function (_to_cmake_path _inPath _outPathVariable)
if (CYGWIN)
find_program(Mathematica_CYGPATH_EXECUTABLE "cygpath")
mark_as_advanced(Mathematica_CYGPATH_EXECUTABLE)
execute_process(
COMMAND "${Mathematica_CYGPATH_EXECUTABLE}" "--unix" "${_inPath}" TIMEOUT 5
OUTPUT_VARIABLE ${_outPathVariable} OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
file(TO_CMAKE_PATH "${_inPath}" ${_outPathVariable})
endif()
set (${_outPathVariable} "${${_outPathVariable}}" PARENT_SCOPE)
endfunction()
# internal function to convert CMake path to "pure" native path without escapes
function (_to_native_path _inPath _outPathVariable)
# do not use the built-in function file (TO_NATIVE_PATH ...),
# which does too much or the wrong thing:
# it converts a CMake path to a native path but then also escapes all blanks
# and special characters
# under MinGW it produces unworkable paths with forward slashes
if (CYGWIN)
find_program(Mathematica_CYGPATH_EXECUTABLE "cygpath")
mark_as_advanced(Mathematica_CYGPATH_EXECUTABLE)
execute_process(
COMMAND "${Mathematica_CYGPATH_EXECUTABLE}" "--mixed" "${_inPath}" TIMEOUT 5
OUTPUT_VARIABLE ${_outPathVariable} OUTPUT_STRIP_TRAILING_WHITESPACE)
elseif (CMAKE_HOST_UNIX)
# use CMake path literally under UNIX
set (${_outPathVariable} "${_inPath}")
elseif (CMAKE_HOST_WIN32)
string (REPLACE "/" "\\" ${_outPathVariable} "${_inPath}")
else()
message (FATAL_ERROR "Unsupported host platform ${CMAKE_HOST_SYSTEM_NAME}")
endif()
set (${_outPathVariable} "${${_outPathVariable}}" PARENT_SCOPE)
endfunction()
# internal macro to set a file's executable bit under UNIX
macro (_make_file_executable _inPath)
if (CMAKE_HOST_UNIX)
_to_native_path ("${_inPath}" _nativePath)
execute_process(
COMMAND chmod "-f" "+x" "${_nativePath}" TIMEOUT 5)
endif()
endmacro()
# internal macro to convert list to command string with quoting
macro (_list_to_cmd_str _outCmd)
set (_str "")
foreach (_arg ${ARGN})
if ("${_arg}" MATCHES " ")
set (_arg "\"${_arg}\"")
endif()
if (_str)
set (_str "${_str} ${_arg}")
else()
set (_str "${_arg}")
endif()
endforeach()
set (${_outCmd} "${_str}")
endmacro()
# internal macro to compute kernel paths (relative to installation directory)
macro (_get_host_kernel_names _outKernelNames)
if (Mathematica_FIND_VERSION AND Mathematica_FIND_VERSION_EXACT)
if (Mathematica_FIND_VERSION VERSION_LESS "10.0.0")
if (CMAKE_HOST_WIN32 OR CYGWIN)
set (${_outKernelNames} "math.exe")
elseif (CMAKE_HOST_APPLE)
set (${_outKernelNames} "Contents/MacOS/MathKernel")
elseif (CMAKE_HOST_UNIX)
set (${_outKernelNames} "Executables/MathKernel" "Executables/math")
endif()
else()
if (CMAKE_HOST_WIN32 OR CYGWIN)
set (${_outKernelNames} "wolfram.exe")
elseif (CMAKE_HOST_APPLE)
set (${_outKernelNames} "Contents/MacOS/WolframKernel")
elseif (CMAKE_HOST_UNIX)
set (${_outKernelNames} "Executables/WolframKernel")
endif()
endif()
else()
if (CMAKE_HOST_WIN32 OR CYGWIN)
set (${_outKernelNames} "wolfram.exe" "math.exe")
elseif (CMAKE_HOST_APPLE)
set (${_outKernelNames} "Contents/MacOS/WolframKernel" "Contents/MacOS/MathKernel")
elseif (CMAKE_HOST_UNIX)
set (${_outKernelNames} "Executables/WolframKernel" "Executables/MathKernel" "Executables/math")
endif()
endif()
endmacro()
# internal macro to to compute front end paths (relative to installation directory)
macro (_get_host_frontend_names _outFrontEndNames)
if (CMAKE_HOST_WIN32 OR CYGWIN)
set (${_outFrontEndNames} "Mathematica.exe")
elseif (CMAKE_HOST_APPLE)
set (${_outFrontEndNames} "Contents/MacOS/Mathematica")
elseif (CMAKE_HOST_UNIX)
set (${_outFrontEndNames}
"Executables/mathematica" "Executables/Mathematica")
endif()
endmacro()
# internal macro to compute program name from product name and version
# E.g., "Mathematica" and "7.0" gives "Mathematica 7.0.app" for Mac OS X
macro (_append_program_names _product _version _outProgramNames)
string (REPLACE " " "" _productWithoutBlanks "${_product}")
if (CMAKE_HOST_APPLE)
if (${_version})
# under Mac OS X the application name may contain the version number as a suffix
list (APPEND ${_outProgramNames} "${_product} ${_version}.app")
list (APPEND ${_outProgramNames} "${_productWithoutBlanks} ${_version}.app")
else()
list (APPEND ${_outProgramNames} "${_product}.app")
list (APPEND ${_outProgramNames} "${_productWithoutBlanks}.app")
endif()
else()
if (${_version})
# other platforms have a sub-directory named after the version number
list (APPEND ${_outProgramNames} "${_product}/${_version}")
list (APPEND ${_outProgramNames} "${_productWithoutBlanks}/${_version}")
endif()
endif()
endmacro()
# internal macro to determine search order for different versions of Mathematica
macro (_get_program_names _outProgramNames)
set (${_outProgramNames} "")
# Mathematica products in order of preference
set (_MathematicaApps "Mathematica" "gridMathematica Server")
# Mathematica product versions in order of preference
set (_MathematicaVersions "11.0" "10.4" "10.3" "10.2" "10.1" "10.0" "9.0" "8.0" "7.0" "6.0" "5.2")
# search for explicitly requested application version first
if (Mathematica_FIND_VERSION AND Mathematica_FIND_VERSION_EXACT)
foreach (_product IN LISTS _MathematicaApps)
_append_program_names("${_product}"
"${Mathematica_FIND_VERSION_MAJOR}.${Mathematica_FIND_VERSION_MINOR}"
${_outProgramNames})
endforeach()
endif()
# then try all qualified application names
foreach (_product IN LISTS _MathematicaApps)
foreach (_version IN LISTS _MathematicaVersions)
_append_program_names("${_product}" "${_version}" ${_outProgramNames})
endforeach()
endforeach()
# then try unqualified application names
foreach (_product IN LISTS _MathematicaApps)
_append_program_names("${_product}" "" ${_outProgramNames})
endforeach()
list (REMOVE_DUPLICATES ${_outProgramNames})
endmacro()
# internal function to get Mathematica Windows installation directory for a registry entry
function (_add_registry_search_path _registryKey _outSearchPaths)
set (_ProductNamePatterns "Wolfram Mathematica [0-9]+" "Wolfram Finance Platform")
get_filename_component (
_productName "[${_registryKey};ProductName]" NAME)
get_filename_component (
_productVersion "[${_registryKey};ProductVersion]" NAME)
get_filename_component (
_productPath "[${_registryKey};ExecutablePath]" PATH)
if (Mathematica_DEBUG)
message (STATUS "[${_registryKey};ProductName]=${_productName}")
message (STATUS "[${_registryKey};ProductVersion]=${_productVersion}")
message (STATUS "[${_registryKey};ExecutablePath]=${_productPath}")
endif()
set (_qualified False)
foreach (_Pattern IN LISTS _ProductNamePatterns)
if ("${_productName}" MATCHES "${_Pattern}")
set (_qualified True)
break()
endif()
endforeach()
if (_qualified)
if (EXISTS "${_productPath}")
_to_cmake_path("${_productPath}" _path)
if (Mathematica_FIND_VERSION AND Mathematica_FIND_VERSION_EXACT)
if ("${_productVersion}" MATCHES "${Mathematica_FIND_VERSION}")
# prepend if version matches requested one
list (INSERT ${_outSearchPaths} 0 "${_path}")
else()
list (APPEND ${_outSearchPaths} "${_path}")
endif()
else()
list (APPEND ${_outSearchPaths} "${_path}")
endif()
endif()
endif()
set (${_outSearchPaths} ${${_outSearchPaths}} PARENT_SCOPE)
endfunction()
# internal function to determine Mathematica installation paths from Windows registry
function (_add_registry_search_paths _outSearchPaths)
if (CMAKE_HOST_WIN32)
foreach (_registryKey IN ITEMS ${ARGN})
set (_regExe "reg.exe")
if (DEFINED ENV{windir})
# use 64-bit reg.exe under WoW64 to make sure we search all keys
if (EXISTS "$ENV{windir}/sysnative/reg.exe")
set (_regExe "$ENV{windir}/sysnative/reg.exe")
endif()
endif()
execute_process(
COMMAND "${_regExe}" query "${_registryKey}" "/s"
COMMAND findstr "${_registryKey}"
TIMEOUT 5 OUTPUT_VARIABLE _queryResult ERROR_QUIET)
string (REGEX MATCHALL "[0-9]+" _installIDs "${_queryResult}")
if (_installIDs)
# _installIDs sorted from oldest to newest version
list (REVERSE _installIDs)
set (_paths "")
foreach (_installID IN LISTS _installIDs)
_add_registry_search_path("${_registryKey}\\${_installID}" _paths)
endforeach()
list (APPEND ${_outSearchPaths} ${_paths})
endif()
endforeach()
set (${_outSearchPaths} ${${_outSearchPaths}} PARENT_SCOPE)
endif()
endfunction()
# internal function to determine Mathematica installation paths from Mac OS X LaunchServices database
function (_add_launch_services_search_paths _outSearchPaths)
if (CMAKE_HOST_APPLE)
# the lsregister executable is needed to search the LaunchServices database
# the executable usually resides in the LaunchServices framework Support directory
# The LaunchServices framework is a sub-framework of the CoreServices umbrella framework
cmake_find_frameworks(CoreServices)
find_program (Mathematica_LSRegister_EXECUTABLE NAMES "lsregister" PATH_SUFFIXES "Support"
HINTS "${CoreServices_FRAMEWORKS}/Frameworks/LaunchServices.framework")
mark_as_advanced(
Mathematica_CoreServices_DIR
Mathematica_LaunchServices_DIR
Mathematica_LSRegister_EXECUTABLE)
if (NOT Mathematica_LSRegister_EXECUTABLE)
message (STATUS "Skipping search of the LaunchServices database, because the lsregister executable could not be found.")
return()
endif()
foreach (_bundleID IN ITEMS ${ARGN})
execute_process(
COMMAND "${Mathematica_LSRegister_EXECUTABLE}" "-dump"
COMMAND "grep" "--before-context=5" "--after-context=5" " ${_bundleID} "
COMMAND "grep" "--only-matching" "/.*\\.app"
TIMEOUT 10 OUTPUT_VARIABLE _queryResult ERROR_QUIET)
string (REPLACE ";" "\\;" _queryResult "${_queryResult}")
string (REPLACE "\n" ";" _appPaths "${_queryResult}")
if (_appPaths)
# put paths into canonical order
list (SORT _appPaths)
list (REVERSE _appPaths)
endif()
if (Mathematica_DEBUG)
message (STATUS "Mac OS X LaunchServices database registered apps=${_appPaths}")
endif()
if (_appPaths)
set (_paths "")
set (_insertIndex 0)
foreach (_appPath IN LISTS _appPaths)
# ignore paths that no longer exist
if (EXISTS "${_appPath}")
_to_cmake_path("${_appPath}" _appPath)
if (Mathematica_FIND_VERSION AND Mathematica_FIND_VERSION_EXACT)
if ("${_appPath}" MATCHES "${Mathematica_FIND_VERSION_MAJOR}.${Mathematica_FIND_VERSION_MINOR}")
# insert in front of other versions if version matches requested one
list (LENGTH _paths _len)
if (_len EQUAL _insertIndex)
list (APPEND _paths "${_appPath}")
else()
list (INSERT _paths ${_insertIndex} "${_appPath}")
endif()
math(EXPR _insertIndex "${_insertIndex} + 1")
else()
list (APPEND _paths "${_appPath}")
endif()
else()
list (APPEND _paths "${_appPath}")
endif()
endif()
endforeach()
list (APPEND ${_outSearchPaths} ${_paths})
endif()
endforeach()
set (${_outSearchPaths} ${${_outSearchPaths}} PARENT_SCOPE)
endif()
endfunction()
# internal macro to determine default Mathematica installation (the one which is on the system search path)
macro (_add_default_search_path _outSearchPaths)
set (_searchPaths "")
if (DEFINED ENV{PATH})
file (TO_CMAKE_PATH "$ENV{PATH}" _searchPaths)
endif()
_get_host_kernel_names(_kernelNames)
foreach (_searchPath IN LISTS _searchPaths)
if (CMAKE_HOST_WIN32 OR CYGWIN)
set (_executable "${_searchPath}/math.exe")
else()
set (_executable "${_searchPath}/math")
endif()
if (EXISTS "${_executable}")
# resolve symlinks
get_filename_component (_executable "${_executable}" REALPATH)
foreach (_kernelName IN LISTS _kernelNames)
string (REPLACE "${_kernelName}" "" _executableDir "${_executable}")
if (NOT "${_executable}" STREQUAL "${_executableDir}" AND
IS_DIRECTORY ${_executableDir})
if (Mathematica_FIND_VERSION)
list (APPEND ${_outSearchPaths} "${_executableDir}")
else()
# prefer default installation if not searching for version explicitly
list (INSERT ${_outSearchPaths} 0 "${_executableDir}")
endif()
endif()
endforeach()
endif()
endforeach()
endmacro()
# internal macro to determine platform specific Mathematica installation search paths
macro (_get_search_paths _outSearchPaths)
set (${_outSearchPaths} "")
if (CMAKE_HOST_WIN32 OR CYGWIN)
# add non-standard installation paths from Windows registry
_add_registry_search_paths(${_outSearchPaths}
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Wolfram Research\\Installations"
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Wolfram Research\\Installations")
# environment variable locations where Mathematica may be installed
set (_WindowsProgramFilesEnvVars to "ProgramW6432" "ProgramFiles(x86)" "ProgramFiles" )
if (CYGWIN)
# Cygwin may be configured to convert all environment variables to all-uppercase
list (APPEND _WindowsProgramFilesEnvVars "PROGRAMW6432" "PROGRAMFILES(X86)" "PROGRAMFILES")
endif()
# add standard Mathematica Windows installation paths
foreach (_envVar IN LISTS _WindowsProgramFilesEnvVars)
if (DEFINED ENV{${_envVar})
_to_cmake_path("$ENV{${_envVar}}" _unixPath)
list (APPEND ${_outSearchPaths} "${_unixPath}/Wolfram Research" )
endif()
endforeach()
elseif (CMAKE_HOST_APPLE)
# add standard Mathematica Mac OS X installation paths
list (APPEND ${_outSearchPaths} "~/Applications;/Applications")
if (CMAKE_SYSTEM_APPBUNDLE_PATH)
list (APPEND ${_outSearchPaths} ${CMAKE_SYSTEM_APPBUNDLE_PATH})
endif()
# add non-standard installation paths from Mac OS X LaunchServices database
_add_launch_services_search_paths(${_outSearchPaths} "com.wolfram.Mathematica")
elseif (CMAKE_HOST_UNIX)
# add standard Mathematica Unix installation paths
list (APPEND ${_outSearchPaths} "/usr/local/Wolfram" "/opt/Wolfram")
endif()
_add_default_search_path(${_outSearchPaths})
if (${_outSearchPaths})
list (REMOVE_DUPLICATES ${_outSearchPaths})
endif()
endmacro()
# internal macro to compute Mathematica SystemIDs from system name
macro (_systemNameToSystemID _systemName _systemProcessor _outSystemIDs)
if ("${_systemName}" STREQUAL "Windows")
if ("${_systemProcessor}" STREQUAL "AMD64")
set (${_outSystemIDs} "Windows-x86-64")
else()
# default to 32-bit Windows
set (${_outSystemIDs} "Windows")
endif()
elseif ("${_systemName}" STREQUAL "CYGWIN")
if ("${_systemProcessor}" STREQUAL "x86_64")
set (${_outSystemIDs} "Windows-x86-64")
else()
# default to 32-bit Windows
set (${_outSystemIDs} "Windows")
endif()
elseif ("${_systemName}" STREQUAL "Darwin")
if ("${_systemProcessor}" STREQUAL "i386")
set (${_outSystemIDs} "MacOSX-x86")
elseif ("${_systemProcessor}" STREQUAL "x86_64")
set (${_outSystemIDs} "MacOSX-x86-64")
elseif ("${_systemProcessor}" MATCHES "ppc64|powerpc64")
set (${_outSystemIDs} "Darwin-PowerPC64")
elseif ("${_systemProcessor}" MATCHES "ppc|powerpc")
if (Mathematica_VERSION)
# Mathematica versions before 6 used "Darwin" as system ID for ppc32
if (NOT "${Mathematica_VERSION}" VERSION_LESS "6.0")
set (${_outSystemIDs} "MacOSX")
else()
set (${_outSystemIDs} "Darwin")
endif()
else ()
set (${_outSystemIDs} "MacOSX" "Darwin")
endif()
endif()
elseif ("${_systemName}" STREQUAL "Linux")
if ("${_systemProcessor}" MATCHES "^i.86$")
set (${_outSystemIDs} "Linux")
elseif ("${_systemProcessor}" MATCHES "x86_64|amd64")
set (${_outSystemIDs} "Linux-x86-64")
elseif ("${_systemProcessor}" STREQUAL "ia64")
set (${_outSystemIDs} "Linux-IA64")
elseif ("${_systemProcessor}" MATCHES "^arm")
set (${_outSystemIDs} "Linux-ARM")
endif()
elseif ("${_systemName}" STREQUAL "SunOS")
if ("${_systemProcessor}" MATCHES "^sparc")
if (Mathematica_VERSION)
# Mathematica versions before 6 used "UltraSPARC" as system ID for Solaris
if (NOT "${Mathematica_VERSION}" VERSION_LESS "6.0")
set (${_outSystemIDs} "Solaris-SPARC")
else()
set (${_outSystemIDs} "UltraSPARC")
endif()
else ()
set (${_outSystemIDs} "Solaris-SPARC" "UltraSPARC")
endif()
elseif ("${_systemProcessor}" STREQUAL "x86_64")
set (${_outSystemIDs} "Solaris-x86-64")
endif()
elseif ("${_systemName}" STREQUAL "AIX")
set (${_outSystemIDs} "AIX-Power64")
elseif ("${_systemName}" STREQUAL "HP-UX")
set (${_outSystemIDs} "HPUX-PA64")
elseif ("${_systemName}" STREQUAL "IRIX")
set (${_outSystemIDs} "IRIX-MIPS64")
endif()
endmacro(_systemNameToSystemID)
# internal macro to compute target Mathematica SystemIDs
macro (_get_system_IDs _outSystemIDs)
if (WIN32 OR CYGWIN)
# pointer size check is more reliable than CMAKE_SYSTEM_PROCESSOR
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set (${_outSystemIDs} "Windows-x86-64")
else()
set (${_outSystemIDs} "Windows")
endif()
elseif (APPLE)
set (${_outSystemIDs} "")
if (CMAKE_OSX_ARCHITECTURES)
# determine System ID from specified architectures
foreach (_arch ${CMAKE_OSX_ARCHITECTURES})
set (_systemID "")
_systemNameToSystemID("${CMAKE_SYSTEM_NAME}" "${_arch}" _systemID)
if (_systemID)
list (APPEND ${_outSystemIDs} ${_systemID})
else()
message (FATAL_ERROR "Unsupported Mac OS X architecture ${_arch}")
endif()
endforeach()
else()
# determine System ID by checking endianness and pointer size
TEST_BIG_ENDIAN(_isBigEndian)
if (_isBigEndian)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set (${_outSystemIDs} "Darwin-PowerPC64")
else()
if (Mathematica_VERSION)
# Mathematica versions before 6 used "Darwin" as system ID for ppc32
if (NOT "${Mathematica_VERSION}" VERSION_LESS "6.0")
set (${_outSystemIDs} "MacOSX")
else()
set (${_outSystemIDs} "Darwin")
endif()
else ()
set (${_outSystemIDs} "MacOSX" "Darwin")
endif()
endif()
else()
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set (${_outSystemIDs} "MacOSX-x86-64")
else()
set (${_outSystemIDs} "MacOSX-x86")
endif()
endif()
endif()
elseif (UNIX)
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
# pointer size check is more reliable than CMAKE_SYSTEM_PROCESSOR
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set (${_outSystemIDs} "Linux-x86-64")
else()
set (${_outSystemIDs} "Linux")
endif()
else()
_systemNameToSystemID("${CMAKE_SYSTEM_NAME}" "${CMAKE_SYSTEM_PROCESSOR}" ${_outSystemIDs})
endif()
else()
set (${_outSystemIDs} "Generic")
endif()
list (REMOVE_DUPLICATES ${_outSystemIDs})
endmacro(_get_system_IDs)
# internal macro to compute host Mathematica SystemIDs
macro (_get_host_system_IDs _outSystemIDs)
if (CMAKE_HOST_WIN32)
set (${_outSystemIDs} "Windows")
if (DEFINED ENV{PROCESSOR_ARCHITEW6432})
if ("$ENV{PROCESSOR_ARCHITEW6432}" STREQUAL "AMD64")
# running of WoW64, host is native 64-bit Windows
set (${_outSystemIDs} "Windows-x86-64")
endif()
elseif (DEFINED ENV{PROCESSOR_ARCHITECTURE})
if ("$ENV{PROCESSOR_ARCHITECTURE}" STREQUAL "AMD64")
# host is native 64-bit Windows
set (${_outSystemIDs} "Windows-x86-64")
endif()
endif()
else()
# always determine host system ID from
# CMAKE_HOST_SYSTEM_NAME and CMAKE_HOST_SYSTEM_PROCESSOR
if (_CMAKE_OSX_MACHINE)
# work-around for Mac OS X, where CMAKE_HOST_SYSTEM_PROCESSOR is not always accurate
set (_hostSystemProcessor "${_CMAKE_OSX_MACHINE}")
else()
set (_hostSystemProcessor "${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
_systemNameToSystemID(
"${CMAKE_HOST_SYSTEM_NAME}" "${_hostSystemProcessor}"
_hostSystemID)
if (NOT DEFINED _hostSystemID)
message (FATAL_ERROR "Unsupported host platform ${CMAKE_HOST_SYSTEM_NAME}")
endif()
_get_compatible_system_IDs(${_hostSystemID} ${_outSystemIDs})
endif()
endmacro()
macro (_get_supported_systemIDs _version _outSystemIDs)
if (NOT "${_version}" VERSION_LESS "10.0")
set (${_outSystemIDs}
"Windows" "Windows-x86-64"
"Linux" "Linux-x86-64" "Linux-ARM"
"MacOSX-x86-64")
elseif (NOT "${_version}" VERSION_LESS "9.0")
set (${_outSystemIDs}
"Windows" "Windows-x86-64"
"Linux" "Linux-x86-64"
"MacOSX-x86-64")
elseif (NOT "${_version}" VERSION_LESS "8.0")
set (${_outSystemIDs}
"Windows" "Windows-x86-64"
"Linux" "Linux-x86-64"
"MacOSX-x86" "MacOSX-x86-64")
elseif (NOT "${_version}" VERSION_LESS "7.0")
set (${_outSystemIDs}
"Windows" "Windows-x86-64"
"Linux" "Linux-x86-64"
"MacOSX-x86" "MacOSX-x86-64" "MacOSX"
"Solaris-SPARC" "Solaris-x86-64")
elseif (NOT "${_version}" VERSION_LESS "6.0")
set (${_outSystemIDs}
"Windows" "Windows-x86-64"
"Linux" "Linux-x86-64" "Linux-IA64"
"MacOSX-x86" "MacOSX-x86-64" "MacOSX"
"Solaris-SPARC" "Solaris-x86-64"
"AIX-Power64")
elseif (NOT "${_version}" VERSION_LESS "5.2")
set (${_outSystemIDs}
"Windows" "Windows-x86-64"
"Linux" "Linux-x86-64" "Linux-IA64"
"MacOSX-x86" "Darwin-PowerPC64" "Darwin"
"UltraSPARC" "Solaris-x86-64"
"AIX-Power64" "DEC-AXP" "HPUX-PA64" "IRIX-MIPS64")
else()
# platforms probably supported before 5.2?
set (${_outSystemIDs}
"Windows"
"Linux" "Linux-x86-64" "Linux-IA64" "Linux-PPC"
"Darwin"
"Solaris" "SGI"
"IBM-RISC" "DEC-AXP" "HP-RISC" "IRIX-MIPS32" "IRIX-MIPS64")
endif()
endmacro()
macro (_get_compatible_system_IDs _systemID _outSystemIDs)
set (${_outSystemIDs} "")
if ("${_systemID}" STREQUAL "Windows-x86-64")
if (Mathematica_VERSION)
if (NOT "${Mathematica_VERSION}" VERSION_LESS "5.2")
# Mathematica 5.2 added support for Windows-x86-64
list (APPEND ${_outSystemIDs} "Windows-x86-64")
endif()
else()
list (APPEND ${_outSystemIDs} "Windows-x86-64")
endif()
# Windows x64 can run x86 through WoW64
list (APPEND ${_outSystemIDs} "Windows")
elseif ("${_systemID}" MATCHES "MacOSX|Darwin")
if ("${_systemID}" MATCHES "MacOSX-x86")
if (Mathematica_VERSION)
# Mathematica 6 added support for MacOSX-x86-64
if (NOT "${Mathematica_VERSION}" VERSION_LESS "6.0")
list (APPEND ${_outSystemIDs} "MacOSX-x86-64")
endif()
# Mathematica 5.2 added support for MacOSX-x86
# Mathematica 9.0 dropped support for MacOSX-x86
if (NOT "${Mathematica_VERSION}" VERSION_LESS "5.2" AND
"${Mathematica_VERSION}" VERSION_LESS "9.0")
list (APPEND ${_outSystemIDs} "MacOSX-x86")
endif()
else()
list (APPEND ${_outSystemIDs} "MacOSX-x86-64" "MacOSX-x86")
endif()
elseif ("${_systemID}" STREQUAL "Darwin-PowerPC64")
if (Mathematica_VERSION)
if (NOT "${Mathematica_VERSION}" VERSION_LESS "5.2" AND
"${Mathematica_VERSION}" VERSION_LESS "6.0")
# Only Mathematica 5.2 supports Darwin-PowerPC64
list (APPEND ${_outSystemIDs} "Darwin-PowerPC64")
endif()
else()
list (APPEND ${_outSystemIDs} "Darwin-PowerPC64")
endif()
endif()
# handle ppc32 (Darwin or MacOSX)
# Mac OS X versions before Lion support ppc32 natively or through Rosetta
# (Mac OS X 10.7.0 is Darwin 11.0.0)
if ("${CMAKE_HOST_SYSTEM_VERSION}" VERSION_LESS "11.0.0")
if (Mathematica_VERSION)
if ("${Mathematica_VERSION}" VERSION_LESS "6.0")
# Mathematica versions before 6 used "Darwin" as system ID for ppc32
list (APPEND ${_outSystemIDs} "Darwin")
elseif ("${Mathematica_VERSION}" VERSION_LESS "8.0")
# Mathematica 8 dropped support for ppc32
list (APPEND ${_outSystemIDs} "MacOSX")
endif()
else()
list (APPEND ${_outSystemIDs} "MacOSX" "Darwin")
endif()
endif()
elseif ("${_systemID}" MATCHES "Linux-x86-64|Linux-IA64")
if (Mathematica_VERSION)
if (NOT "${Mathematica_VERSION}" VERSION_LESS "5.2")
# Mathematica 5.2 added support for 64-bit
list (APPEND ${_outSystemIDs} ${_systemID})
endif()
else()
list (APPEND ${_outSystemIDs} ${_systemID})
endif()
# Linux 64-bit can run x86 through ia32-libs package
list (APPEND ${_outSystemIDs} "Linux")
else()
list (APPEND ${_outSystemIDs} ${_systemID})
endif()
list (REMOVE_DUPLICATES ${_outSystemIDs})
endmacro()
# internal macro to compute target MathLink / WSTP DeveloperKit system ID
macro(_get_developer_kit_system_IDs _outSystemIDs)
if (APPLE)
if (Mathematica_VERSION)
if ("${Mathematica_VERSION}" VERSION_LESS "9.0")
# Mathematica versions before 9 did not have a system ID subdirectory
set (${_outSystemIDs} "")
else()
# Mathematica versions after 9 have a system ID subdirectory
set (${_outSystemIDs} "MacOSX-x86-64")
endif()
else()
_get_system_IDs(${_outSystemIDs})
endif()
else()
_get_system_IDs(${_outSystemIDs})
endif()
endmacro()
# internal macro to compute host MathLink / WSTP DeveloperKit system ID
macro(_get_host_developer_kit_system_IDs _outSystemIDs)
if (CMAKE_HOST_APPLE)
if (Mathematica_VERSION)
# Mathematica versions before 9 did not have a system ID subdirectory
if ("${Mathematica_VERSION}" VERSION_LESS "9.0")
set (${_outSystemIDs} "")
else()
# The MacOSX-x86-64 DeveloperKit is a universal binary with architectures i386 and x86_64
set (${_outSystemIDs} "MacOSX-x86-64")
endif()
else()
_get_host_system_IDs(${_outSystemIDs})
endif()
else()
_get_host_system_IDs(${_outSystemIDs})
endif()
endmacro()
# internal macro to compute target development flavor
macro (_get_target_flavor _outFlavor)
if (CYGWIN)
set (${_outFlavor} "cygwin")
elseif (WIN32)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set (${_outFlavor} "mldev64")
else()
set (${_outFlavor} "mldev32")
endif()
elseif (APPLE)
set (${_outFlavor} "")
if (Mathematica_VERSION)
if (Mathematica_USE_LIBCXX_LIBRARIES AND
NOT "${Mathematica_VERSION}" VERSION_LESS "10.0" AND
"${Mathematica_VERSION}" VERSION_LESS "10.4")
# Mathematica 10 added LLVM libc++ compiled version in AlternativeLibraries directory
# Mathematica 10.4 and later only ship with LLVM libc++ compiled version
set (${_outFlavor} "AlternativeLibraries")
endif()
endif()
else()
# no flavors on non-Windows platforms
set (${_outFlavor} "")
endif()
endmacro()
# internal macro to compute host development flavor
macro (_get_host_flavor _outFlavor)
if (CYGWIN)
set (${_outFlavor} "cygwin")
elseif (CMAKE_HOST_WIN32)
set (${_outFlavor} "mldev32")
if (DEFINED ENV{PROCESSOR_ARCHITEW6432})
if ("$ENV{PROCESSOR_ARCHITEW6432}" STREQUAL "AMD64")
# running of WoW64, host is native 64-bit Windows
set (${_outFlavor} "mldev64")
endif()
elseif (DEFINED ENV{PROCESSOR_ARCHITECTURE})
if ("$ENV{PROCESSOR_ARCHITECTURE}" STREQUAL "AMD64")
# host is native 64-bit Windows
set (${_outFlavor} "mldev64")
endif()
endif()
elseif (CMAKE_HOST_APPLE)
set (${_outFlavor} "")
if (Mathematica_VERSION)
if (Mathematica_USE_LIBCXX_LIBRARIES AND
NOT "${Mathematica_VERSION}" VERSION_LESS "10.0" AND
"${Mathematica_VERSION}" VERSION_LESS "10.4")
# Mathematica 10 added LLVM libc++ compiled version in AlternativeLibraries directory
# Mathematica 10.4 and later only ship with LLVM libc++ compiled version
set (${_outFlavor} "AlternativeLibraries")
endif()
endif()
else()
# no flavors on non-Windows platforms
set (${_outFlavor} "")
endif()
endmacro()
# internal macro to compute WolframRTL library names
macro (_get_wolfram_runtime_library_names _outLibraryNames)
if (Mathematica_USE_STATIC_LIBRARIES)
set (${_outLibraryNames} "WolframRTL_Static_Minimal" )
else()
if (Mathematica_USE_MINIMAL_LIBRARIES)
set (${_outLibraryNames} "WolframRTL_Minimal" )
else()
set (${_outLibraryNames} "WolframRTL" )
endif()
endif()
endmacro()
# internal macro to compute MathLink library names
macro (_get_mathlink_library_names _outLibraryNames)
if (CYGWIN)
if (DEFINED Mathematica_MathLink_FIND_VERSION_MAJOR)
set (${_outLibraryNames} "ML32i${Mathematica_MathLink_FIND_VERSION_MAJOR}")
else()
set (${_outLibraryNames} "ML32i4" "ML32i3" "ML32i2" "ML32i1")
endif()
elseif (WIN32)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
if (BORLAND)
set (${_outLibraryNames} "ml64i3b" "ml64i2b")
elseif (WATCOM)
set (${_outLibraryNames} "ml64i3w" "ml64i2w")
endif()
# always add default Microsoft 64-bit PE libraries
if (DEFINED Mathematica_MathLink_FIND_VERSION_MAJOR)
if (Mathematica_USE_STATIC_LIBRARIES)
list (APPEND ${_outLibraryNames} "ml64i${Mathematica_MathLink_FIND_VERSION_MAJOR}s")
else()
list (APPEND ${_outLibraryNames} "ml64i${Mathematica_MathLink_FIND_VERSION_MAJOR}m")
endif()
else()
if (Mathematica_USE_STATIC_LIBRARIES)
list (APPEND ${_outLibraryNames} "ml64i4s" "ml64i3s")
else()
list (APPEND ${_outLibraryNames} "ml64i4m" "ml64i3m" "ml64i2m")
endif()
endif()
else()
if (BORLAND)
set (${_outLibraryNames} "ml32i3b" "ml32i2b" "ml32i1b")
elseif (WATCOM)
set (${_outLibraryNames} "ml32i3w" "ml32i2w" "ml32i1w")
endif()
# always add default Microsoft 32-bit PE libraries
if (DEFINED Mathematica_MathLink_FIND_VERSION_MAJOR)
if (Mathematica_USE_STATIC_LIBRARIES)
list (APPEND ${_outLibraryNames} "ml32i${Mathematica_MathLink_FIND_VERSION_MAJOR}s")
else()
list (APPEND ${_outLibraryNames} "ml32i${Mathematica_MathLink_FIND_VERSION_MAJOR}m")
endif()
else()
if (Mathematica_USE_STATIC_LIBRARIES)
list (APPEND ${_outLibraryNames} "ml32i4s" "ml32i3s")
else()
list (APPEND ${_outLibraryNames} "ml32i4m" "ml32i3m" "ml32i2m" "ml32i1m")
endif()
endif()
endif()
elseif (APPLE)
if (Mathematica_USE_STATIC_LIBRARIES)
if (DEFINED Mathematica_MathLink_FIND_VERSION_MAJOR AND DEFINED Mathematica_MathLink_FIND_VERSION_MINOR)
set (${_outLibraryNames} "libMLi${Mathematica_MathLink_FIND_VERSION_MAJOR}.${Mathematica_MathLink_FIND_VERSION_MINOR}.a")
elseif (DEFINED Mathematica_MathLink_FIND_VERSION_MAJOR)
set (${_outLibraryNames} "libMLi${Mathematica_MathLink_FIND_VERSION_MAJOR}.a")
else()
set (${_outLibraryNames} "libMLi4.a" "libMLi3.a" "libML.a")
endif()
else()
# search for mathlink.framework
set (${_outLibraryNames} "mathlink" "ML")
endif()
elseif (UNIX)
if (Mathematica_USE_STATIC_LIBRARIES)
set (_ext ".a")
else()
set (_ext ".so")
endif()
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set (_arch "64")
else()
set (_arch "32")
endif()
if (DEFINED Mathematica_MathLink_FIND_VERSION_MAJOR)
set (${_outLibraryNames} "libML${_arch}i${Mathematica_MathLink_FIND_VERSION_MAJOR}${_ext}")
else()
set (${_outLibraryNames} "libML${_arch}i4${_ext}" "libML${_arch}i3${_ext}" "libML${_ext}")
endif()
endif()
endmacro(_get_mathlink_library_names)
function (_get_mprep_output_file _templateFile _outfile)
get_filename_component(_templateFile_name ${_templateFile} NAME)
get_filename_component(_templateFile_ext "${_templateFile}" EXT)
if (_templateFile_ext STREQUAL ".tmpp")
set (${_outfile} "${_templateFile_name}.cpp" PARENT_SCOPE)
elseif (_templateFile_ext STREQUAL ".tm++")
set (${_outfile} "${_templateFile_name}.c++" PARENT_SCOPE)
elseif (_templateFile_ext STREQUAL ".tmxx")
set (${_outfile} "${_templateFile_name}.cxx" PARENT_SCOPE)
else()
set (${_outfile} "${_templateFile_name}.c" PARENT_SCOPE)
endif()
endfunction()
# internal macro to compute WSTP library names
macro (_get_WSTP_library_names _outLibraryNames)
if (CYGWIN)
if (DEFINED Mathematica_WSTP_FIND_VERSION_MAJOR)
set (${_outLibraryNames} "WSTP32i${Mathematica_WSTP_FIND_VERSION_MAJOR}")
else()
set (${_outLibraryNames} "WSTP32i4" "WSTP32i3" "WSTP32i2" "WSTP32i1")
endif()
elseif (WIN32)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set (_arch "64")
else()
set (_arch "32")
endif()
if (DEFINED Mathematica_WSTP_FIND_VERSION_MAJOR)
if (Mathematica_USE_STATIC_LIBRARIES)
list (APPEND ${_outLibraryNames} "wstp${_arch}i${Mathematica_WSTP_FIND_VERSION_MAJOR}s")
else()
list (APPEND ${_outLibraryNames} "wstp${_arch}i${Mathematica_WSTP_FIND_VERSION_MAJOR}m")
endif()
else()
if (Mathematica_USE_STATIC_LIBRARIES)
list (APPEND ${_outLibraryNames} "wstp${_arch}i4s" "wstp${_arch}i3s")
else()
list (APPEND ${_outLibraryNames} "wstp${_arch}i4m" "wstp${_arch}i3m" "wstp${_arch}i2m" "wstp${_arch}i1m")
endif()
endif()
elseif (APPLE)
if (Mathematica_USE_STATIC_LIBRARIES)
if (DEFINED Mathematica_WSTP_FIND_VERSION_MAJOR AND DEFINED Mathematica_WSTP_FIND_VERSION_MINOR)
set (${_outLibraryNames} "libWSTPi${Mathematica_WSTP_FIND_VERSION_MAJOR}.${Mathematica_WSTP_FIND_VERSION_MINOR}.a")