-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Support.cmake
4310 lines (3898 loc) · 206 KB
/
Support.cmake
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
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#
# This file is a "template" file used by various FindPython modules.
#
#
# Initial configuration
#
cmake_policy(PUSH)
# list supports empty elements
cmake_policy (SET CMP0007 NEW)
# numbers and boolean constants
cmake_policy (SET CMP0012 NEW)
# IN_LIST operator
cmake_policy (SET CMP0057 NEW)
# foreach loop variable scope
cmake_policy (SET CMP0124 NEW)
# registry view behavior
cmake_policy (SET CMP0134 NEW)
# file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
cmake_policy(SET CMP0159 NEW)
if (NOT DEFINED _PYTHON_PREFIX)
message (FATAL_ERROR "FindPython: INTERNAL ERROR")
endif()
if (NOT DEFINED _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
message (FATAL_ERROR "FindPython: INTERNAL ERROR")
endif()
if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "3")
set(_${_PYTHON_PREFIX}_VERSIONS 3.13 3.12 3.11 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
elseif (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "2")
set(_${_PYTHON_PREFIX}_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
else()
message (FATAL_ERROR "FindPython: INTERNAL ERROR")
endif()
get_property(_${_PYTHON_PREFIX}_CMAKE_ROLE GLOBAL PROPERTY CMAKE_ROLE)
include (${CMAKE_CURRENT_LIST_DIR}/../FindPackageHandleStandardArgs.cmake)
#
# helper commands
#
macro (_PYTHON_DISPLAY_FAILURE _PYTHON_MSG)
if (${_PYTHON_PREFIX}_FIND_REQUIRED)
message (FATAL_ERROR "${_PYTHON_MSG}")
else()
if (NOT ${_PYTHON_PREFIX}_FIND_QUIETLY)
message(STATUS "${_PYTHON_MSG}")
endif ()
endif()
set (${_PYTHON_PREFIX}_FOUND FALSE)
string (TOUPPER "${_PYTHON_PREFIX}" _${_PYTHON_PREFIX}_UPPER_PREFIX)
set (${_PYTHON_UPPER_PREFIX}_FOUND FALSE)
endmacro()
function (_PYTHON_ADD_REASON_FAILURE module message)
if (_${_PYTHON_PREFIX}_${module}_REASON_FAILURE)
string (LENGTH "${_${_PYTHON_PREFIX}_${module}_REASON_FAILURE}" length)
math (EXPR length "${length} + 10")
string (REPEAT " " ${length} shift)
set_property (CACHE _${_PYTHON_PREFIX}_${module}_REASON_FAILURE PROPERTY VALUE "${_${_PYTHON_PREFIX}_${module}_REASON_FAILURE}\n${shift}${message}")
else()
set_property (CACHE _${_PYTHON_PREFIX}_${module}_REASON_FAILURE PROPERTY VALUE "${message}")
endif()
endfunction()
function (_PYTHON_MARK_AS_INTERNAL)
foreach (var IN LISTS ARGV)
if (DEFINED CACHE{${var}})
set_property (CACHE ${var} PROPERTY TYPE INTERNAL)
endif()
endforeach()
endfunction()
macro (_PYTHON_SELECT_LIBRARY_CONFIGURATIONS _PYTHON_BASENAME)
if(NOT DEFINED ${_PYTHON_BASENAME}_LIBRARY_RELEASE)
set(${_PYTHON_BASENAME}_LIBRARY_RELEASE "${_PYTHON_BASENAME}_LIBRARY_RELEASE-NOTFOUND")
endif()
if(NOT DEFINED ${_PYTHON_BASENAME}_LIBRARY_DEBUG)
set(${_PYTHON_BASENAME}_LIBRARY_DEBUG "${_PYTHON_BASENAME}_LIBRARY_DEBUG-NOTFOUND")
endif()
get_property(_PYTHON_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (${_PYTHON_BASENAME}_LIBRARY_DEBUG AND ${_PYTHON_BASENAME}_LIBRARY_RELEASE AND
NOT ${_PYTHON_BASENAME}_LIBRARY_DEBUG STREQUAL ${_PYTHON_BASENAME}_LIBRARY_RELEASE AND
(_PYTHON_isMultiConfig OR CMAKE_BUILD_TYPE))
# if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
# single-config generators, set optimized and debug libraries
set (${_PYTHON_BASENAME}_LIBRARIES "")
foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_RELEASE)
list( APPEND ${_PYTHON_BASENAME}_LIBRARIES optimized "${_PYTHON_libname}")
endforeach()
foreach (_PYTHON_libname IN LISTS ${_PYTHON_BASENAME}_LIBRARY_DEBUG)
list( APPEND ${_PYTHON_BASENAME}_LIBRARIES debug "${_PYTHON_libname}")
endforeach()
elseif (${_PYTHON_BASENAME}_LIBRARY_RELEASE)
set (${_PYTHON_BASENAME}_LIBRARIES "${${_PYTHON_BASENAME}_LIBRARY_RELEASE}")
elseif (${_PYTHON_BASENAME}_LIBRARY_DEBUG)
set (${_PYTHON_BASENAME}_LIBRARIES "${${_PYTHON_BASENAME}_LIBRARY_DEBUG}")
else()
set (${_PYTHON_BASENAME}_LIBRARIES "${_PYTHON_BASENAME}_LIBRARY-NOTFOUND")
endif()
endmacro()
macro (_PYTHON_FIND_FRAMEWORKS)
if (CMAKE_HOST_APPLE OR APPLE)
file(TO_CMAKE_PATH "$ENV{CMAKE_FRAMEWORK_PATH}" _pff_CMAKE_FRAMEWORK_PATH)
set (_pff_frameworks ${CMAKE_FRAMEWORK_PATH}
${_pff_CMAKE_FRAMEWORK_PATH}
~/Library/Frameworks
/usr/local/Frameworks
/opt/homebrew/Frameworks
${CMAKE_SYSTEM_FRAMEWORK_PATH})
list (REMOVE_DUPLICATES _pff_frameworks)
foreach (_pff_implementation IN LISTS _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS)
unset (_${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS)
if (_pff_implementation STREQUAL "CPython")
foreach (_pff_framework IN LISTS _pff_frameworks)
if (EXISTS ${_pff_framework}/Python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}.framework)
list (APPEND _${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS ${_pff_framework}/Python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}.framework)
endif()
if (EXISTS ${_pff_framework}/Python.framework)
list (APPEND _${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS ${_pff_framework}/Python.framework)
endif()
endforeach()
elseif (_pff_implementation STREQUAL "IronPython")
foreach (_pff_framework IN LISTS _pff_frameworks)
if (EXISTS ${_pff_framework}/IronPython.framework)
list (APPEND _${_PYTHON_PREFIX}_${_pff_implementation}_FRAMEWORKS ${_pff_framework}/IronPython.framework)
endif()
endforeach()
endif()
endforeach()
unset (_pff_implementation)
unset (_pff_frameworks)
unset (_pff_framework)
endif()
endmacro()
function (_PYTHON_GET_FRAMEWORKS _PYTHON_PGF_FRAMEWORK_PATHS)
cmake_parse_arguments (PARSE_ARGV 1 _PGF "" "" "IMPLEMENTATIONS;VERSION")
if (NOT _PGF_IMPLEMENTATIONS)
set (_PGF_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS})
endif()
set (framework_paths)
foreach (implementation IN LISTS _PGF_IMPLEMENTATIONS)
if (implementation STREQUAL "CPython")
foreach (version IN LISTS _PGF_VERSION)
foreach (framework IN LISTS _${_PYTHON_PREFIX}_${implementation}_FRAMEWORKS)
if (EXISTS "${framework}/Versions/${version}")
list (APPEND framework_paths "${framework}/Versions/${version}")
endif()
endforeach()
endforeach()
elseif (implementation STREQUAL "IronPython")
foreach (version IN LISTS _PGF_VERSION)
foreach (framework IN LISTS _${_PYTHON_PREFIX}_${implementation}_FRAMEWORKS)
# pick-up all available versions
file (GLOB versions LIST_DIRECTORIES true RELATIVE "${framework}/Versions/"
"${framework}/Versions/${version}*")
list (SORT versions ORDER DESCENDING)
list (TRANSFORM versions PREPEND "${framework}/Versions/")
list (APPEND framework_paths ${versions})
endforeach()
endforeach()
endif()
endforeach()
set (${_PYTHON_PGF_FRAMEWORK_PATHS} ${framework_paths} PARENT_SCOPE)
endfunction()
function (_PYTHON_GET_REGISTRIES _PYTHON_PGR_REGISTRY_PATHS)
cmake_parse_arguments (PARSE_ARGV 1 _PGR "" "" "IMPLEMENTATIONS;VERSION")
if (NOT _PGR_IMPLEMENTATIONS)
set (_PGR_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS})
endif()
set (registries)
foreach (implementation IN LISTS _PGR_IMPLEMENTATIONS)
if (implementation STREQUAL "CPython")
foreach (version IN LISTS _PGR_VERSION)
string (REPLACE "." "" version_no_dots ${version})
list (TRANSFORM _${_PYTHON_PREFIX}_ARCH REPLACE "^(.+)$" "[HKEY_CURRENT_USER/SOFTWARE/Python/PythonCore/${version}-\\1/InstallPath]" OUTPUT_VARIABLE reg_paths)
list (APPEND registries ${reg_paths})
if (version VERSION_GREATER_EQUAL "3.5")
# cmake_host_system_information is not usable in bootstrap
get_filename_component (arch "[HKEY_CURRENT_USER\\Software\\Python\\PythonCore\\${version};SysArchitecture]" NAME)
string (REPLACE "bit" "" arch "${arch}")
if (arch IN_LIST _${_PYTHON_PREFIX}_ARCH)
list (APPEND registries [HKEY_CURRENT_USER/SOFTWARE/Python/PythonCore/${version}/InstallPath])
endif()
else()
list (APPEND registries [HKEY_CURRENT_USER/SOFTWARE/Python/PythonCore/${version}/InstallPath])
endif()
list (TRANSFORM _${_PYTHON_PREFIX}_ARCH REPLACE "^(.+)$" "[HKEY_CURRENT_USER/SOFTWARE/Python/ContinuumAnalytics/Anaconda${version_no_dots}-\\1/InstallPath]" OUTPUT_VARIABLE reg_paths)
list (APPEND registries ${reg_paths})
list (TRANSFORM _${_PYTHON_PREFIX}_ARCH REPLACE "^(.+)$" "[HKEY_CURRENT_USER/SOFTWARE/Python/PythonCore/${version}-\\1/InstallPath]" OUTPUT_VARIABLE reg_paths)
list (APPEND registries ${reg_paths})
list (APPEND registries [HKEY_LOCAL_MACHINE/SOFTWARE/Python/PythonCore/${version}/InstallPath])
list (TRANSFORM _${_PYTHON_PREFIX}_ARCH REPLACE "^(.+)$" "[HKEY_LOCAL_MACHINE/SOFTWARE/Python/ContinuumAnalytics/Anaconda${version_no_dots}-\\1/InstallPath]" OUTPUT_VARIABLE reg_paths)
list (APPEND registries ${reg_paths})
endforeach()
elseif (implementation STREQUAL "IronPython")
foreach (version IN LISTS _PGR_VERSION)
list (APPEND registries [HKEY_LOCAL_MACHINE/SOFTWARE/IronPython/${version}/InstallPath])
endforeach()
endif()
endforeach()
set (${_PYTHON_PGR_REGISTRY_PATHS} "${registries}" PARENT_SCOPE)
endfunction()
function (_PYTHON_GET_ABIFLAGS _PGA_FIND_ABI _PGABIFLAGS)
set (abiflags "<none>")
list (GET _PGA_FIND_ABI 0 pydebug)
list (GET _PGA_FIND_ABI 1 pymalloc)
list (GET _PGA_FIND_ABI 2 unicode)
list (LENGTH _PGA_FIND_ABI find_abi_length)
if (find_abi_length GREATER 3)
list (GET _PGA_FIND_ABI 3 gil)
else()
set (gil "OFF")
endif()
if (pymalloc STREQUAL "ANY" AND unicode STREQUAL "ANY")
set (abiflags "mu" "m" "u" "<none>")
elseif (pymalloc STREQUAL "ANY" AND unicode STREQUAL "ON")
set (abiflags "mu" "u")
elseif (pymalloc STREQUAL "ANY" AND unicode STREQUAL "OFF")
set (abiflags "m" "<none>")
elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "ANY")
set (abiflags "mu" "m")
elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "ON")
set (abiflags "mu")
elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "OFF")
set (abiflags "m")
elseif (pymalloc STREQUAL "ON" AND unicode STREQUAL "ANY")
set (abiflags "u" "<none>")
elseif (pymalloc STREQUAL "OFF" AND unicode STREQUAL "ON")
set (abiflags "u")
endif()
if (pydebug STREQUAL "ON")
if (abiflags)
list (TRANSFORM abiflags PREPEND "d")
else()
set (abiflags "d")
endif()
elseif (pydebug STREQUAL "ANY")
if (abiflags)
set (flags "${abiflags}")
list (TRANSFORM flags PREPEND "d")
list (APPEND abiflags "${flags}")
else()
set (abiflags "<none>" "d")
endif()
endif()
if (gil STREQUAL "ON")
if (abiflags)
list (TRANSFORM abiflags PREPEND "t")
else()
set (abiflags "t")
endif()
elseif (gil STREQUAL "ANY")
if (abiflags)
set (flags "${abiflags}")
list (TRANSFORM flags PREPEND "t")
list (APPEND abiflags "${flags}")
else()
set (abiflags "<none>" "t")
endif()
endif()
list (TRANSFORM abiflags REPLACE "^(.+)<none>$" "\\1")
set (${_PGABIFLAGS} "${abiflags}" PARENT_SCOPE)
endfunction()
function (_PYTHON_GET_PATH_SUFFIXES _PYTHON_PGPS_PATH_SUFFIXES)
cmake_parse_arguments (PARSE_ARGV 1 _PGPS "INTERPRETER;COMPILER;LIBRARY;INCLUDE" "" "IMPLEMENTATIONS;VERSION")
if (NOT _PGPS_IMPLEMENTATIONS)
set (_PGPS_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS})
endif()
set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}")
list (TRANSFORM abi REPLACE "^<none>$" "")
set (path_suffixes)
foreach (implementation IN LISTS _PGPS_IMPLEMENTATIONS)
if (implementation STREQUAL "CPython")
if (_PGPS_INTERPRETER)
list (APPEND path_suffixes bin Scripts)
else()
foreach (version IN LISTS _PGPS_VERSION)
if (_PGPS_LIBRARY)
if (CMAKE_LIBRARY_ARCHITECTURE)
list (APPEND path_suffixes lib/${CMAKE_LIBRARY_ARCHITECTURE})
endif()
list (APPEND path_suffixes lib libs)
if (CMAKE_LIBRARY_ARCHITECTURE)
set (suffixes "${abi}")
if (suffixes)
list (TRANSFORM suffixes PREPEND "lib/python${version}/config-${version}")
list (TRANSFORM suffixes APPEND "-${CMAKE_LIBRARY_ARCHITECTURE}")
else()
set (suffixes "lib/python${version}/config-${version}-${CMAKE_LIBRARY_ARCHITECTURE}")
endif()
list (APPEND path_suffixes ${suffixes})
endif()
set (suffixes "${abi}")
if (suffixes)
list (TRANSFORM suffixes PREPEND "lib/python${version}/config-${version}")
else()
set (suffixes "lib/python${version}/config-${version}")
endif()
list (APPEND path_suffixes ${suffixes})
elseif (_PGPS_INCLUDE)
set (suffixes "${abi}")
if (suffixes)
list (TRANSFORM suffixes PREPEND "include/python${version}")
else()
set (suffixes "include/python${version}")
endif()
list (APPEND path_suffixes ${suffixes} include)
endif()
endforeach()
endif()
elseif (implementation STREQUAL "IronPython")
if (_PGPS_INTERPRETER OR _PGPS_COMPILER)
foreach (version IN LISTS _PGPS_VERSION)
list (APPEND path_suffixes "share/ironpython${version}")
endforeach()
list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_IRON_PYTHON_PATH_SUFFIXES})
endif()
elseif (implementation STREQUAL "PyPy")
if (_PGPS_INTERPRETER)
list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_PYPY_EXECUTABLE_PATH_SUFFIXES})
elseif (_PGPS_LIBRARY)
list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_PYPY_LIBRARY_PATH_SUFFIXES})
elseif (_PGPS_INCLUDE)
foreach (version IN LISTS _PGPS_VERSION)
list (APPEND path_suffixes lib/pypy${version}/include pypy${version}/include)
endforeach()
list (APPEND path_suffixes ${_${_PYTHON_PREFIX}_PYPY_INCLUDE_PATH_SUFFIXES})
endif()
endif()
endforeach()
list (REMOVE_DUPLICATES path_suffixes)
set (${_PYTHON_PGPS_PATH_SUFFIXES} ${path_suffixes} PARENT_SCOPE)
endfunction()
function (_PYTHON_GET_NAMES _PYTHON_PGN_NAMES)
cmake_parse_arguments (PARSE_ARGV 1 _PGN "POSIX;INTERPRETER;COMPILER;CONFIG;LIBRARY;WIN32;DEBUG" "" "IMPLEMENTATIONS;VERSION")
if (NOT _PGN_IMPLEMENTATIONS)
set (_PGN_IMPLEMENTATIONS ${_${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS})
endif()
set (names)
foreach (implementation IN LISTS _PGN_IMPLEMENTATIONS)
if (implementation STREQUAL "CPython")
if (_PGN_INTERPRETER AND _${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES STREQUAL "FIRST")
if (_PGN_DEBUG)
list (APPEND names python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}_d python_d)
else()
list (APPEND names python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python)
endif()
endif()
foreach (version IN LISTS _PGN_VERSION)
if (_PGN_WIN32)
if (_PGN_INTERPRETER)
set (name_version ${version})
else()
string (REPLACE "." "" name_version ${version})
endif()
set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}")
list (TRANSFORM abi REPLACE "^<none>$" "")
if (abi)
set (abinames "${abi}")
list (TRANSFORM abinames PREPEND "python${name_version}")
else()
set (abinames "python${name_version}")
endif()
if (_PGN_DEBUG)
list (TRANSFORM abinames APPEND "_d")
endif()
list (APPEND names ${abinames})
endif()
if (_PGN_POSIX)
set (abi "${_${_PYTHON_PREFIX}_ABIFLAGS}")
list (TRANSFORM abi REPLACE "^<none>$" "")
if (abi)
if (_PGN_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE)
set (abinames "${abi}")
list (TRANSFORM abinames PREPEND "${CMAKE_LIBRARY_ARCHITECTURE}-python${version}")
list (TRANSFORM abinames APPEND "-config")
list (APPEND names ${abinames})
endif()
set (abinames "${abi}")
list (TRANSFORM abinames PREPEND "python${version}")
if (_PGN_CONFIG)
list (TRANSFORM abinames APPEND "-config")
endif()
list (APPEND names ${abinames})
else()
unset (abinames)
if (_PGN_CONFIG AND DEFINED CMAKE_LIBRARY_ARCHITECTURE)
set (abinames "${CMAKE_LIBRARY_ARCHITECTURE}-python${version}")
endif()
list (APPEND abinames "python${version}")
if (_PGN_CONFIG)
list (TRANSFORM abinames APPEND "-config")
endif()
list (APPEND names ${abinames})
endif()
endif()
endforeach()
if (_PGN_INTERPRETER AND _${_PYTHON_PREFIX}_FIND_UNVERSIONED_NAMES STREQUAL "LAST")
if (_PGN_DEBUG)
list (APPEND names python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}_d python_d)
else()
list (APPEND names python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR} python)
endif()
endif()
elseif (implementation STREQUAL "IronPython")
if (_PGN_INTERPRETER)
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
# Do not use wrapper script on Linux because it is buggy: -c interpreter option cannot be used
foreach (version IN LISTS _PGN_VERSION)
list (APPEND names "ipy${version}")
endforeach()
endif()
list (APPEND names ${_${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES})
elseif (_PGN_COMPILER)
list (APPEND names ${_${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES})
endif()
elseif (implementation STREQUAL "PyPy")
if (_PGN_INTERPRETER)
list (APPEND names ${_${_PYTHON_PREFIX}_PYPY_NAMES})
elseif (_PGN_LIBRARY)
if (_PGN_WIN32)
foreach (version IN LISTS _PGN_VERSION)
string (REPLACE "." "" version_no_dots ${version})
set (name "python${version_no_dots}")
if (_PGN_DEBUG)
string (APPEND name "_d")
endif()
list (APPEND names "${name}")
endforeach()
endif()
if (_PGN_POSIX)
foreach(version IN LISTS _PGN_VERSION)
list (APPEND names "pypy${version}-c")
endforeach()
endif()
list (APPEND names ${_${_PYTHON_PREFIX}_PYPY_LIB_NAMES})
endif()
endif()
endforeach()
set (${_PYTHON_PGN_NAMES} ${names} PARENT_SCOPE)
endfunction()
function (_PYTHON_GET_CONFIG_VAR _PYTHON_PGCV_VALUE NAME)
unset (${_PYTHON_PGCV_VALUE} PARENT_SCOPE)
if (NOT NAME MATCHES "^(PREFIX|ABIFLAGS|CONFIGDIR|INCLUDES|LIBS|SOABI|SOSABI|POSTFIX)$")
return()
endif()
if (NAME STREQUAL "SOSABI")
# assume some default
if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME MATCHES "MSYS|CYGWIN")
set (_values "")
else()
set (_values "abi${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}")
endif()
elseif (_${_PYTHON_PREFIX}_CONFIG)
if (NAME STREQUAL "SOABI")
set (config_flag "--extension-suffix")
else()
set (config_flag "--${NAME}")
endif()
string (TOLOWER "${config_flag}" config_flag)
execute_process (COMMAND ${_${_PYTHON_PREFIX}_CONFIG_LAUNCHER} ${config_flag}
RESULT_VARIABLE _result
OUTPUT_VARIABLE _values
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_result)
unset (_values)
else()
if (NAME STREQUAL "INCLUDES")
# do some clean-up
string (REGEX MATCHALL "(-I|-iwithsysroot)[ ]*[^ ]+" _values "${_values}")
string (REGEX REPLACE "(-I|-iwithsysroot)[ ]*" "" _values "${_values}")
list (REMOVE_DUPLICATES _values)
elseif (NAME STREQUAL "SOABI")
# clean-up: remove prefix character and suffix
if (_values MATCHES "^(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.so|\\.pyd)$")
set(_values "")
else()
string (REGEX REPLACE "^([.-]|_d\\.)(.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\2" _values "${_values}")
endif()
endif()
endif()
if (NAME STREQUAL "ABIFLAGS" AND NOT _values)
set (_values "<none>")
endif()
endif()
if (_${_PYTHON_PREFIX}_EXECUTABLE AND NOT CMAKE_CROSSCOMPILING)
if (NAME STREQUAL "PREFIX")
execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys\ntry:\n import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_config_var('base') or '', sysconfig.get_config_var('installed_base') or '']))\nexcept Exception:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.PREFIX,sysconfig.EXEC_PREFIX,sysconfig.BASE_EXEC_PREFIX]))"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _values
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_result)
unset (_values)
else()
list (REMOVE_DUPLICATES _values)
endif()
elseif (NAME STREQUAL "INCLUDES")
if (WIN32)
set (_scheme "nt")
else()
set (_scheme "posix_prefix")
endif()
execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys\ntry:\n import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_path('platinclude'),sysconfig.get_path('platinclude','${_scheme}'),sysconfig.get_path('include'),sysconfig.get_path('include','${_scheme}')]))\nexcept Exception:\n from distutils import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_python_inc(plat_specific=True),sysconfig.get_python_inc(plat_specific=False)]))"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _values
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_result)
unset (_values)
else()
list (REMOVE_DUPLICATES _values)
endif()
elseif (NAME STREQUAL "SOABI")
# first step: compute SOABI form EXT_SUFFIX config variable
execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys\ntry:\n import sysconfig\n sys.stdout.write(sysconfig.get_config_var('EXT_SUFFIX') or '')\nexcept Exception:\n from distutils import sysconfig;sys.stdout.write(sysconfig.get_config_var('EXT_SUFFIX') or '')"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _values
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_result)
unset (_values)
else()
if (_values)
# clean-up: remove prefix character and suffix
if (_values MATCHES "^(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.so|\\.pyd)$")
set(_values "")
else()
string (REGEX REPLACE "^([.-]|_d\\.)(.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\2" _values "${_values}")
endif()
endif()
endif()
# second step: use SOABI or SO config variables as fallback
if (NOT _values)
execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys\ntry:\n import sysconfig\n sys.stdout.write(';'.join([sysconfig.get_config_var('SOABI') or '',sysconfig.get_config_var('SO') or '']))\nexcept Exception:\n from distutils import sysconfig;sys.stdout.write(';'.join([sysconfig.get_config_var('SOABI') or '',sysconfig.get_config_var('SO') or '']))"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _soabi
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_result)
unset (_values)
else()
foreach (_item IN LISTS _soabi)
if (_item)
set (_values "${_item}")
break()
endif()
endforeach()
if (_values)
# clean-up: remove prefix character and suffix
if (_values MATCHES "^(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.so|\\.pyd)$")
set(_values "")
else()
string (REGEX REPLACE "^([.-]|_d\\.)(.+)(${CMAKE_SHARED_LIBRARY_SUFFIX}|\\.(so|pyd))$" "\\1" _values "${_values}")
endif()
endif()
endif()
endif()
elseif (NAME STREQUAL "SOSABI")
execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c "import sys\nimport re\nimport importlib.machinery\nsys.stdout.write(next(filter(lambda x: re.search('^\\.abi', x), importlib.machinery.EXTENSION_SUFFIXES)))"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _values
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_result)
unset (_values)
else()
string (REGEX REPLACE "^\\.(.+)\\.[^.]+$" "\\1" _values "${_values}")
endif()
elseif (NAME STREQUAL "POSTFIX")
if (WIN32 AND _${_PYTHON_PREFIX}_LIBRARY_DEBUG MATCHES "_d${CMAKE_IMPORT_LIBRARY_SUFFIX}$")
set (_values "_d")
endif()
elseif (NAME STREQUAL "ABIFLAGS" AND WIN32)
# config var ABIFLAGS does not exist, check GIL specific variable
execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys; import sysconfig; sys.stdout.write(str(sysconfig.get_config_var('Py_GIL_DISABLED')))"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _values
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (result OR NOT _values EQUAL "1")
# assume ABI is not supported or GIL is set
set (_values "<none>")
else()
set (_values "t")
endif()
else()
set (config_flag "${NAME}")
if (NAME STREQUAL "CONFIGDIR")
set (config_flag "LIBPL")
endif()
execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys\ntry:\n import sysconfig\n sys.stdout.write(sysconfig.get_config_var('${config_flag}'))\nexcept Exception:\n from distutils import sysconfig\n sys.stdout.write(sysconfig.get_config_var('${config_flag}'))"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _values
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_result)
unset (_values)
endif()
if (NAME STREQUAL "ABIFLAGS" AND NOT _values)
set (_values "<none>")
endif()
endif()
endif()
if (NAME STREQUAL "ABIFLAGS" OR NAME STREQUAL "SOABI" OR NAME STREQUAL "SOSABI" OR NAME STREQUAL "POSTFIX")
set (${_PYTHON_PGCV_VALUE} "${_values}" PARENT_SCOPE)
return()
endif()
if (NOT _values OR _values STREQUAL "None")
return()
endif()
if (NAME STREQUAL "LIBS")
# do some clean-up
string (REGEX MATCHALL "-(l|framework)[ ]*[^ ]+" _values "${_values}")
# remove elements relative to python library itself
list (FILTER _values EXCLUDE REGEX "-lpython")
list (REMOVE_DUPLICATES _values)
endif()
if (WIN32 AND NAME MATCHES "^(PREFIX|CONFIGDIR|INCLUDES)$")
file (TO_CMAKE_PATH "${_values}" _values)
endif()
set (${_PYTHON_PGCV_VALUE} "${_values}" PARENT_SCOPE)
endfunction()
function (_PYTHON_GET_VERSION)
cmake_parse_arguments (PARSE_ARGV 0 _PGV "LIBRARY;SABI_LIBRARY;INCLUDE" "PREFIX" "")
unset (${_PGV_PREFIX}VERSION PARENT_SCOPE)
unset (${_PGV_PREFIX}VERSION_MAJOR PARENT_SCOPE)
unset (${_PGV_PREFIX}VERSION_MINOR PARENT_SCOPE)
unset (${_PGV_PREFIX}VERSION_PATCH PARENT_SCOPE)
unset (${_PGV_PREFIX}ABI PARENT_SCOPE)
unset (abi)
if (_PGV_LIBRARY)
# retrieve version and abi from library name
if (_${_PYTHON_PREFIX}_LIBRARY_RELEASE)
get_filename_component (library_name "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" NAME)
# extract version from library name
if (library_name MATCHES "python([23])([0-9]+)([tdmu]*)")
set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE)
set (abi "${CMAKE_MATCH_3}")
elseif (library_name MATCHES "python([23])\\.([0-9]+)([tdmu]*)")
set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE)
set (abi "${CMAKE_MATCH_3}")
elseif (library_name MATCHES "pypy([23])\\.([0-9]+)-c")
set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE)
elseif (library_name MATCHES "pypy(3)?-c")
set (version "${CMAKE_MATCH_1}")
# try to pick-up a more precise version from the path
get_filename_component (library_dir "${_${_PYTHON_PREFIX}_LIBRARY_RELEASE}" DIRECTORY)
if (library_dir MATCHES "/pypy([23])\\.([0-9]+)/")
set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}" PARENT_SCOPE)
elseif (version EQUAL "3")
set (${_PGV_PREFIX}VERSION_MAJOR "3" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION "3" PARENT_SCOPE)
else()
set (${_PGV_PREFIX}VERSION_MAJOR "2" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION "2" PARENT_SCOPE)
endif()
endif()
endif()
elseif (_PGV_SABI_LIBRARY)
# retrieve version and abi from library name
if (_${_PYTHON_PREFIX}_SABI_LIBRARY_RELEASE)
get_filename_component (library_name "${_${_PYTHON_PREFIX}_SABI_LIBRARY_RELEASE}" NAME)
# extract version from library name
if (library_name MATCHES "python([23])([tdmu]*)")
set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}" PARENT_SCOPE)
set (abi "${CMAKE_MATCH_2}")
elseif (library_name MATCHES "pypy([23])-c")
set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}" PARENT_SCOPE)
elseif (library_name MATCHES "pypy-c")
# try to pick-up a more precise version from the path
get_filename_component (library_dir "${_${_PYTHON_PREFIX}_SABI_LIBRARY_RELEASE}" DIRECTORY)
if (library_dir MATCHES "/pypy([23])\\.([0-9]+)/")
set (${_PGV_PREFIX}VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION "${CMAKE_MATCH_1}" PARENT_SCOPE)
endif()
endif()
endif()
else()
if (_${_PYTHON_PREFIX}_INCLUDE_DIR)
# retrieve version from header file
file (STRINGS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}/patchlevel.h" version
REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"")
string (REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
version "${version}")
string (REGEX MATCHALL "[0-9]+" versions "${version}")
list (GET versions 0 version_major)
list (GET versions 1 version_minor)
list (GET versions 2 version_patch)
set (${_PGV_PREFIX}VERSION "${version_major}.${version_minor}.${version_patch}" PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION_MAJOR ${version_major} PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION_MINOR ${version_minor} PARENT_SCOPE)
set (${_PGV_PREFIX}VERSION_PATCH ${version_patch} PARENT_SCOPE)
# compute ABI flags
if (version_major VERSION_GREATER "2")
set (config_flags "Py_GIL_DISABLED|Py_DEBUG|Py_UNICODE_SIZE|MS_WIN32")
if ("${version_major}.${version_minor}" VERSION_LESS "3.8")
# pymalloc is not the default. Must be part of the name signature
string (APPEND config_flags "|WITH_PYMALLOC")
endif()
file (STRINGS "${_${_PYTHON_PREFIX}_INCLUDE_DIR}/pyconfig.h" config REGEX "(${config_flags})")
if (config MATCHES "(^|;)[ ]*#[ ]*define[ ]+MS_WIN32")
# same header is used regardless abi, so set is as <none>
set (abi "<none>")
else()
if (NOT config)
# pyconfig.h can be a wrapper to a platform specific pyconfig.h
# In this case, try to identify ABI from include directory
if (_${_PYTHON_PREFIX}_INCLUDE_DIR MATCHES "python${version_major}\\.${version_minor}+([tdmu]*)")
set (abi "${CMAKE_MATCH_1}")
endif()
else()
if (config MATCHES "(^|;)[ ]*#[ ]*define[ ]+Py_GIL_DISABLED[ ]+1")
string (APPEND abi "t")
endif()
if (config MATCHES "(^|;)[ ]*#[ ]*define[ ]+Py_DEBUG[ ]+1")
string (APPEND abi "d")
endif()
if (config MATCHES "(^|;)[ ]*#[ ]*define[ ]+WITH_PYMALLOC[ ]+1")
string (APPEND abi "m")
endif()
if (config MATCHES "(^|;)[ ]*#[ ]*define[ ]+Py_UNICODE_SIZE[ ]+4")
string (APPEND abi "u")
endif()
endif()
endif()
endif()
endif()
endif()
if (NOT abi)
set (abi "<none>")
endif()
set (${_PGV_PREFIX}ABI "${abi}" PARENT_SCOPE)
endfunction()
function (_PYTHON_GET_LAUNCHER _PYTHON_PGL_NAME)
cmake_parse_arguments (PARSE_ARGV 1 _PGL "INTERPRETER;COMPILER" "CONFIG" "")
unset (${_PYTHON_PGL_NAME} PARENT_SCOPE)
if ((_PGL_INTERPRETER AND NOT _${_PYTHON_PREFIX}_EXECUTABLE)
OR (_PGL_COMPILER AND NOT _${_PYTHON_PREFIX}_COMPILER)
OR (_PGL_CONFIG AND NOT _${_PYTHON_PREFIX}_CONFIG))
return()
endif()
if (_PGL_CONFIG)
# default config script can be launched directly
set (${_PYTHON_PGL_NAME} "${_${_PYTHON_PREFIX}_CONFIG}" PARENT_SCOPE)
if (NOT MINGW)
return()
endif()
# on MINGW environment, python-config script may require bash to be launched
execute_process (COMMAND cygpath.exe -u "${_${_PYTHON_PREFIX}_CONFIG}"
RESULT_VARIABLE _result
OUTPUT_VARIABLE _config
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_result)
# impossible to convert path, keep default config
return()
endif()
execute_process (COMMAND bash.exe "${_config}" --prefix
RESULT_VARIABLE _result
OUTPUT_QUIET
ERROR_QUIET)
if (_result)
# fail to execute through bash, keep default config
return()
endif()
set(${_PYTHON_PGL_NAME} bash.exe "${_config}" PARENT_SCOPE)
return()
endif()
if ("IronPython" IN_LIST _${_PYTHON_PREFIX}_FIND_IMPLEMENTATIONS
AND NOT SYSTEM_NAME MATCHES "Windows|Linux")
if (_PGL_INTERPRETER)
get_filename_component (name "${_${_PYTHON_PREFIX}_EXECUTABLE}" NAME)
get_filename_component (ext "${_${_PYTHON_PREFIX}_EXECUTABLE}" LAST_EXT)
if (name IN_LIST _${_PYTHON_PREFIX}_IRON_PYTHON_INTERPRETER_NAMES
AND ext STREQUAL ".exe")
set (${_PYTHON_PGL_NAME} "${${_PYTHON_PREFIX}_DOTNET_LAUNCHER}" PARENT_SCOPE)
endif()
elseif (_PGL_COMPILER)
get_filename_component (name "${_${_PYTHON_PREFIX}_COMPILER}" NAME)
get_filename_component (ext "${_${_PYTHON_PREFIX}_COMPILER}" LAST_EXT)
if (name IN_LIST _${_PYTHON_PREFIX}_IRON_PYTHON_COMPILER_NAMES
AND ext STREQUAL ".exe")
set (${_PYTHON_PGL_NAME} "${${_PYTHON_PREFIX}_DOTNET_LAUNCHER}" PARENT_SCOPE)
endif()
endif()
endif()
endfunction()
function (_PYTHON_VALIDATE_INTERPRETER)
if (NOT _${_PYTHON_PREFIX}_EXECUTABLE)
unset (_${_PYTHON_PREFIX}_EXECUTABLE_DEBUG CACHE)
return()
endif()
cmake_parse_arguments (PARSE_ARGV 0 _PVI "IN_RANGE;EXACT;CHECK_EXISTS" "VERSION" "")
if (_PVI_CHECK_EXISTS AND NOT EXISTS "${_${_PYTHON_PREFIX}_EXECUTABLE}")
# interpreter does not exist anymore
set_property (CACHE _${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE PROPERTY VALUE "Cannot find the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"")
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
if (WIN32 AND DEFINED CACHE{_${_PYTHON_PREFIX}_EXECUTABLE_DEBUG})
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE_DEBUG PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE_DEBUG-NOTFOUND")
endif()
return()
endif()
_python_get_launcher (_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER INTERPRETER)
# validate ABI compatibility
if (DEFINED _${_PYTHON_PREFIX}_FIND_ABI)
_python_get_config_var (abi ABIFLAGS)
if (NOT abi IN_LIST _${_PYTHON_PREFIX}_ABIFLAGS)
# incompatible ABI
set_property (CACHE _${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE PROPERTY VALUE "Wrong ABI for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"")
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
return()
endif()
endif()
if (_PVI_IN_RANGE OR _PVI_VERSION)
# retrieve full version
execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys; sys.stdout.write('.'.join([str(x) for x in sys.version_info[:3]]))"
RESULT_VARIABLE result
OUTPUT_VARIABLE version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (result)
# interpreter is not usable
set_property (CACHE _${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE PROPERTY VALUE "Cannot use the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"")
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
if (WIN32 AND DEFINED CACHE{_${_PYTHON_PREFIX}_EXECUTABLE_DEBUG})
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE_DEBUG PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE_DEBUG-NOTFOUND")
endif()
return()
endif()
if (_PVI_VERSION)
# check against specified version
## compute number of components for version
string (REGEX REPLACE "[^.]" "" dots "${_PVI_VERSION}")
## add one dot because there is one dot less than there are components
string (LENGTH "${dots}." count)
if (count GREATER 3)
set (count 3)
endif()
set (version_regex "^[0-9]+")
if (count EQUAL 3)
string (APPEND version_regex "\\.[0-9]+\\.[0-9]+")
elseif (count EQUAL 2)
string (APPEND version_regex "\\.[0-9]+")
endif()
# extract needed range
string (REGEX MATCH "${version_regex}" version "${version}")
if (_PVI_EXACT AND NOT version VERSION_EQUAL _PVI_VERSION)
# interpreter has wrong version
set_property (CACHE _${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE PROPERTY VALUE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"")
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
if (WIN32 AND DEFINED CACHE{_${_PYTHON_PREFIX}_EXECUTABLE_DEBUG})
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE_DEBUG PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE_DEBUG-NOTFOUND")
endif()
return()
else()
# check that version is OK
string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" major_version "${version}")
string(REGEX REPLACE "^([0-9]+)\\.?.*$" "\\1" expected_major_version "${_PVI_VERSION}")
if (NOT major_version VERSION_EQUAL expected_major_version
OR NOT version VERSION_GREATER_EQUAL _PVI_VERSION)
set_property (CACHE _${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE PROPERTY VALUE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"")
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
if (WIN32 AND DEFINED CACHE{_${_PYTHON_PREFIX}_EXECUTABLE_DEBUG})
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE_DEBUG PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE_DEBUG-NOTFOUND")
endif()
return()
endif()
endif()
endif()
if (_PVI_IN_RANGE)
# check if version is in the requested range
find_package_check_version ("${version}" in_range HANDLE_VERSION_RANGE)
if (NOT in_range)
# interpreter has invalid version
set_property (CACHE _${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE PROPERTY VALUE "Wrong version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"")
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
if (WIN32 AND DEFINED CACHE{_${_PYTHON_PREFIX}_EXECUTABLE_DEBUG})
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE_DEBUG PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE_DEBUG-NOTFOUND")
endif()
return()
endif()
endif()
else()
get_filename_component (python_name "${_${_PYTHON_PREFIX}_EXECUTABLE}" NAME)
if (NOT python_name STREQUAL "python${_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR}${CMAKE_EXECUTABLE_SUFFIX}")
# executable found do not have version in name
# ensure major version is OK
execute_process (COMMAND ${_${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys; sys.stdout.write(str(sys.version_info[0]))"
RESULT_VARIABLE result
OUTPUT_VARIABLE version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (result OR NOT version EQUAL _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
# interpreter not usable or has wrong major version
if (result)
set_property (CACHE _${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE PROPERTY VALUE "Cannot use the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"")
else()
set_property (CACHE _${_PYTHON_PREFIX}_Interpreter_REASON_FAILURE PROPERTY VALUE "Wrong major version for the interpreter \"${_${_PYTHON_PREFIX}_EXECUTABLE}\"")
endif()
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE-NOTFOUND")
if (WIN32 AND DEFINED CACHE{_${_PYTHON_PREFIX}_EXECUTABLE_DEBUG})
set_property (CACHE _${_PYTHON_PREFIX}_EXECUTABLE_DEBUG PROPERTY VALUE "${_PYTHON_PREFIX}_EXECUTABLE_DEBUG-NOTFOUND")
endif()
return()