-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
688 lines (633 loc) · 22.3 KB
/
CMakeLists.txt
File metadata and controls
688 lines (633 loc) · 22.3 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
add_definitions(-DPy_BUILD_CORE)
add_definitions(-DPy_BUILD_CORE_BUILTIN)
add_definitions(-DNDEBUG)
set(MODULE_SOURCES # Equivalent to MODULE_OBJS in Makefile.pre
${PROJECT_BINARY_DIR}/CMakeFiles/config.c
${SRC_DIR}/Modules/gcmodule.c
${SRC_DIR}/Modules/main.c
)
if(UNIX)
list(APPEND MODULE_SOURCES
${SRC_DIR}/Modules/getpath.c
)
set(PYTHONPATH "${EXTRA_PYTHONPATH}:lib-dynload:plat-${PY_PLATFORM}")
if(ENABLE_TKINTER)
set(PYTHONPATH "${PYTHONPATH}:lib-tk")
endif()
set_property(
SOURCE ${SRC_DIR}/Modules/getpath.c
PROPERTY COMPILE_DEFINITIONS
PREFIX="${CMAKE_INSTALL_PREFIX}"
EXEC_PREFIX="${CMAKE_INSTALL_PREFIX}"
VERSION="${PY_VERSION_MAJOR}.${PY_VERSION_MINOR}"
VPATH="."
PYTHONPATH="${PYTHONPATH}"
)
elseif(WIN32)
list(APPEND MODULE_SOURCES
${SRC_DIR}/PC/getpathp.c
)
# HACK To workaround limitation in escaping logic of CMake, the pythonpath
# separator is conditionally set depending of the version of Visual Studio.
# See http://cmake.org/Bug/view.php?id=14073
if( ("${MSVC_VERSION}" VERSION_GREATER "1599") AND ("${CMAKE_GENERATOR}" MATCHES "^Visual Studio") )
set(PATHSEP "%3B")
elseif( (${MSVC}) AND ("${CMAKE_GENERATOR}" MATCHES "^Ninja") )
set(PATHSEP "\;")
elseif( (${MSVC}) AND ("${CMAKE_GENERATOR}" MATCHES "^NMake") )
set(PATHSEP "\;")
elseif(MINGW)
set(PATHSEP "\;")
else()
set(PATHSEP ";")
endif()
string(REPLACE "/" "\\\\" PYTHONHOME_ESCAPED ${PYTHONHOME})
string(REPLACE "/" "\\\\" EXTENSION_INSTALL_DIR_ESCAPED ${EXTENSION_INSTALL_DIR})
set(PYTHONPATH "${EXTRA_PYTHONPATH}")
set(PYTHONPATH "${PYTHONPATH}${PATHSEP}.\\\\${PYTHONHOME_ESCAPED}")
set(PYTHONPATH "${PYTHONPATH}${PATHSEP}.\\\\${EXTENSION_INSTALL_DIR_ESCAPED}")
set(PYTHONPATH "${PYTHONPATH}${PATHSEP}.\\\\${EXTENSION_INSTALL_DIR_ESCAPED}\\\\${CMAKE_CFG_INTDIR}")
set(PYTHONPATH "${PYTHONPATH}${PATHSEP}.\\\\${PYTHONHOME_ESCAPED}\\\\plat-${PY_PLATFORM}")
if(ENABLE_TKINTER)
set(PYTHONPATH "${PYTHONPATH}${PATHSEP}.\\\\${PYTHONHOME_ESCAPED}\\\\lib-tk")
endif()
set(_wide_char_modifier)
if(IS_PY3)
set(_wide_char_modifier "L")
endif()
set_property(
SOURCE ${SRC_DIR}/PC/getpathp.c
PROPERTY COMPILE_DEFINITIONS
"LANDMARK=${_wide_char_modifier}\"${PYTHONHOME_ESCAPED}\\\\os.py\""
"PYTHONPATH=${_wide_char_modifier}\"${PYTHONPATH}\""
"PY3_DLLNAME=\"python3$<$<CONFIG:Debug>:_d>\""
)
endif()
set(PARSER_COMMON_SOURCES # Equivalent to POBJS in Makefile.pre
${SRC_DIR}/Parser/acceler.c
${SRC_DIR}/Parser/grammar1.c
${SRC_DIR}/Parser/listnode.c
${SRC_DIR}/Parser/node.c
${SRC_DIR}/Parser/parser.c
)
if(PY_VERSION VERSION_GREATER_EQUAL "3.9")
list(APPEND PARSER_COMMON_SOURCES
${SRC_DIR}/Parser/pegen/pegen.c
${SRC_DIR}/Parser/pegen/parse.c
${SRC_DIR}/Parser/pegen/parse_string.c
${SRC_DIR}/Parser/pegen/peg_api.c
)
endif()
if(PY_VERSION VERSION_GREATER_EQUAL "3.8")
list(APPEND PARSER_COMMON_SOURCES
${SRC_DIR}/Parser/myreadline.c
${SRC_DIR}/Parser/parsetok.c
${SRC_DIR}/Parser/token.c
${SRC_DIR}/Parser/tokenizer.c
)
else()
list(APPEND PARSER_COMMON_SOURCES
${SRC_DIR}/Parser/bitset.c
${SRC_DIR}/Parser/firstsets.c
${SRC_DIR}/Parser/grammar.c
${SRC_DIR}/Parser/metagrammar.c
${SRC_DIR}/Parser/pgen.c
)
endif()
set(OBJECT2_SOURCES
${SRC_DIR}/Objects/bufferobject.c
${SRC_DIR}/Objects/cobject.c
${SRC_DIR}/Objects/intobject.c
${SRC_DIR}/Objects/stringobject.c
)
if(MSVC)
if(EXISTS ${SRC_DIR}/PC/invalid_parameter_handler.c)
list(APPEND OBJECT2_SOURCES
${SRC_DIR}/PC/invalid_parameter_handler.c
)
endif()
endif()
set(OBJECT3_SOURCES
${SRC_DIR}/Objects/accu.c
${SRC_DIR}/Objects/bytesobject.c
${SRC_DIR}/Objects/namespaceobject.c
${SRC_DIR}/Objects/odictobject.c
)
if(MSVC)
list(APPEND OBJECT3_SOURCES
${SRC_DIR}/PC/invalid_parameter_handler.c
)
endif()
if(PY_VERSION VERSION_GREATER_EQUAL "3.7")
list(APPEND OBJECT3_SOURCES
${SRC_DIR}/Objects/call.c
)
endif()
set(OBJECT_COMMON_SOURCES # Equivalent to OBJECT_OBJS in Makefile.pre
${OBJECT${PY_VERSION_MAJOR}_SOURCES}
${SRC_DIR}/Objects/abstract.c
${SRC_DIR}/Objects/boolobject.c
${SRC_DIR}/Objects/bytearrayobject.c
${SRC_DIR}/Objects/bytes_methods.c
${SRC_DIR}/Objects/capsule.c
${SRC_DIR}/Objects/cellobject.c
${SRC_DIR}/Objects/classobject.c
${SRC_DIR}/Objects/codeobject.c
${SRC_DIR}/Objects/complexobject.c
${SRC_DIR}/Objects/descrobject.c
${SRC_DIR}/Objects/dictobject.c
${SRC_DIR}/Objects/enumobject.c
${SRC_DIR}/Objects/exceptions.c
${SRC_DIR}/Objects/fileobject.c
${SRC_DIR}/Objects/floatobject.c
${SRC_DIR}/Objects/frameobject.c
${SRC_DIR}/Objects/funcobject.c
${SRC_DIR}/Objects/genobject.c
${SRC_DIR}/Objects/iterobject.c
${SRC_DIR}/Objects/listobject.c
${SRC_DIR}/Objects/longobject.c
${SRC_DIR}/Objects/memoryobject.c
${SRC_DIR}/Objects/methodobject.c
${SRC_DIR}/Objects/moduleobject.c
${SRC_DIR}/Objects/object.c
${SRC_DIR}/Objects/obmalloc.c
${SRC_DIR}/Objects/rangeobject.c
${SRC_DIR}/Objects/setobject.c
${SRC_DIR}/Objects/sliceobject.c
${SRC_DIR}/Objects/structseq.c
${SRC_DIR}/Objects/tupleobject.c
${SRC_DIR}/Objects/typeobject.c
${SRC_DIR}/Objects/unicodectype.c
${SRC_DIR}/Objects/unicodeobject.c
${SRC_DIR}/Objects/weakrefobject.c
)
if(PY_VERSION VERSION_GREATER_EQUAL "3.8")
list(APPEND OBJECT_COMMON_SOURCES
${SRC_DIR}/Objects/interpreteridobject.c
${SRC_DIR}/Objects/picklebufobject.c
)
endif()
if(PY_VERSION VERSION_GREATER_EQUAL "3.9")
list(APPEND OBJECT_COMMON_SOURCES
${SRC_DIR}/Objects/genericaliasobject.c
)
endif()
if(CMAKE_C_COMPILER_ID MATCHES GNU)
foreach(filename class complex float int method string type unicode weakref)
set_property(SOURCE ${SRC_DIR}/Objects/${filename}object.c PROPERTY COMPILE_FLAGS -Wno-unused-value)
endforeach()
endif()
set(DYNLOAD_SOURCES
)
if(UNIX AND HAVE_DLOPEN)
list(APPEND DYNLOAD_SOURCES
${SRC_DIR}/Python/dynload_shlib.c
)
if(IS_PY3)
set_property(
SOURCE ${SRC_DIR}/Python/dynload_shlib.c
PROPERTY COMPILE_DEFINITIONS
SOABI="${SOABI}"
)
endif()
elseif(WIN32)
list(APPEND DYNLOAD_SOURCES
${SRC_DIR}/PC/dl_nt.c
${SRC_DIR}/Python/dynload_win.c
)
set(ms_dll_id "${PY_VERSION_MAJOR}.${PY_VERSION_MINOR}")
if(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
set(ms_dll_id "${ms_dll_id}-32")
endif()
set_property(
SOURCE ${SRC_DIR}/PC/dl_nt.c
PROPERTY COMPILE_DEFINITIONS
Py_ENABLE_SHARED
MS_DLL_ID="${ms_dll_id}"
)
endif()
set(THREAD_SOURCES )
if(WITH_THREAD OR PY_VERSION VERSION_GREATER_EQUAL "3.7")
list(APPEND THREAD_SOURCES
${SRC_DIR}/Python/thread.c
)
endif()
set(PYTHON2_COMMON_SOURCES
${SRC_DIR}/Python/formatter_string.c
${SRC_DIR}/Python/pystrtod.c
)
if(WIN32)
list(APPEND PYTHON2_COMMON_SOURCES
${SRC_DIR}/PC/import_nt.c
)
endif()
set(PYTHON3_COMMON_SOURCES
${SRC_DIR}/Python/dynamic_annotations.c
${SRC_DIR}/Python/fileutils.c
${SRC_DIR}/Python/pyhash.c
${SRC_DIR}/Python/pylifecycle.c
${SRC_DIR}/Python/pystrhex.c
${SRC_DIR}/Python/pystrtod.c
${SRC_DIR}/Python/pytime.c
)
set(PYTHON_COMMON_SOURCES
${DYNLOAD_SOURCES}
${PYTHON${PY_VERSION_MAJOR}_COMMON_SOURCES}
${THREAD_SOURCES}
${SRC_DIR}/Python/asdl.c
${SRC_DIR}/Python/ast.c
${SRC_DIR}/Python/bltinmodule.c
${SRC_DIR}/Python/ceval.c
${SRC_DIR}/Python/codecs.c
${SRC_DIR}/Python/compile.c
${SRC_DIR}/Python/dtoa.c
${SRC_DIR}/Python/errors.c
${SRC_DIR}/Python/formatter_unicode.c
${SRC_DIR}/Python/future.c
${SRC_DIR}/Python/getargs.c
${SRC_DIR}/Python/getcompiler.c
${SRC_DIR}/Python/getcopyright.c
${SRC_DIR}/Python/getopt.c
${SRC_DIR}/Python/getplatform.c
${SRC_DIR}/Python/getversion.c
${SRC_DIR}/Python/graminit.c
${SRC_DIR}/Python/import.c
${SRC_DIR}/Python/importdl.c
${SRC_DIR}/Python/marshal.c
${SRC_DIR}/Python/modsupport.c
${SRC_DIR}/Python/mysnprintf.c
${SRC_DIR}/Python/mystrtoul.c
${SRC_DIR}/Python/peephole.c
${SRC_DIR}/Python/pyarena.c
${SRC_DIR}/Python/pyctype.c
${SRC_DIR}/Python/pyfpe.c
${SRC_DIR}/Python/pymath.c
${SRC_DIR}/Python/pystate.c
${SRC_DIR}/Python/pystrcmp.c
${SRC_DIR}/Python/Python-ast.c
${SRC_DIR}/Python/pythonrun.c
${SRC_DIR}/Python/structmember.c
${SRC_DIR}/Python/symtable.c
${SRC_DIR}/Python/sysmodule.c
${SRC_DIR}/Python/traceback.c
${SRC_DIR}/Python/_warnings.c
)
if(PY_VERSION VERSION_GREATER_EQUAL "3.7")
list(APPEND PYTHON_COMMON_SOURCES
${SRC_DIR}/Python/ast_opt.c
${SRC_DIR}/Python/ast_unparse.c
${SRC_DIR}/Python/bootstrap_hash.c
${SRC_DIR}/Python/context.c
${SRC_DIR}/Python/hamt.c
${SRC_DIR}/Python/pathconfig.c
)
else()
list(APPEND PYTHON_COMMON_SOURCES
${SRC_DIR}/Python/random.c
)
endif()
if(PY_VERSION VERSION_GREATER_EQUAL "3.8")
list(APPEND PYTHON_COMMON_SOURCES
${SRC_DIR}/Python/initconfig.c
${SRC_DIR}/Python/preconfig.c
)
endif()
if(UNIX)
list(APPEND PYTHON_COMMON_SOURCES
${SRC_DIR}/Python/frozenmain.c
)
else()
list(APPEND PYTHON_COMMON_SOURCES
${SRC_DIR}/Python/frozen.c
)
endif()
if(UNIX OR MINGW)
set_property(
SOURCE ${SRC_DIR}/Python/getplatform.c
PROPERTY COMPILE_DEFINITIONS
PLATFORM="${PY_PLATFORM}"
)
if(IS_PY3)
set_property(
SOURCE ${SRC_DIR}/Python/sysmodule.c
PROPERTY COMPILE_DEFINITIONS
ABIFLAGS="${ABIFLAGS}"
)
endif()
endif()
list(APPEND MODULE_SOURCES
${SRC_DIR}/Modules/signalmodule.c
)
set(LIBPYTHON_OMIT_FROZEN_SOURCES
${SRC_DIR}/Modules/getbuildinfo.c
${MODULE_SOURCES}
${OBJECT_COMMON_SOURCES}
${PARSER_COMMON_SOURCES}
${PYTHON_COMMON_SOURCES}
)
if(PY_VERSION VERSION_LESS "3.8")
list(APPEND LIBPYTHON_OMIT_FROZEN_SOURCES
${SRC_DIR}/Parser/myreadline.c
${SRC_DIR}/Parser/parsetok.c
${SRC_DIR}/Parser/tokenizer.c
)
endif()
# List of builtin extensions
get_property(builtin_extensions GLOBAL PROPERTY builtin_extensions)
# Collect builtin extension sources
set(builtin_extension_sources)
foreach(name ${builtin_extensions})
get_property(extension_${name}_sources GLOBAL PROPERTY extension_${name}_sources)
list(APPEND builtin_extension_sources ${extension_${name}_sources})
endforeach()
# XXX Associate Py_NO_ENABLE_SHARED with "_ctypes/callbacks.c" if corresponding
# extension is builtin.
if(WIN32)
foreach(src ${builtin_extension_sources})
get_filename_component(filename ${src} NAME)
if(${filename} STREQUAL "callbacks.c")
set_property(SOURCE ${src} APPEND PROPERTY COMPILE_DEFINITIONS Py_NO_ENABLE_SHARED)
endif()
endforeach()
endif()
list(APPEND LIBPYTHON_OMIT_FROZEN_SOURCES ${builtin_extension_sources})
# Collect builtin extension link libraries
set(builtin_link_libraries)
foreach(name ${builtin_extensions})
get_property(extension_${name}_link_libraries GLOBAL PROPERTY extension_${name}_link_libraries)
list(APPEND builtin_link_libraries ${extension_${name}_link_libraries})
endforeach()
# Collect builtin extension includedirs
set(builtin_includedirs)
foreach(name ${builtin_extensions})
get_property(extension_${name}_includedirs GLOBAL PROPERTY extension_${name}_includedirs)
list(APPEND builtin_includedirs ${extension_${name}_includedirs})
endforeach()
# Collect builtin extension definitions
set(builtin_compile_definitions_without_py_limited_api)
foreach(name ${builtin_extensions})
get_property(extension_${name}_definitions GLOBAL PROPERTY extension_${name}_definitions)
if(extension_${name}_definitions)
set_property(SOURCE ${extension_${name}_sources}
APPEND PROPERTY COMPILE_DEFINITIONS ${extension_${name}_definitions})
if(NOT ${name} STREQUAL "xxlimited")
list(APPEND builtin_compile_definitions_without_py_limited_api ${extension_${name}_definitions})
endif()
endif()
endforeach()
include_directories(${builtin_includedirs})
# Create the parts of config.c for platform-specific and user-controlled
# builtin modules.
set(init_return_type_2 "void")
set(init_prefix_2 "init")
set(init_return_type_3 "PyObject*")
set(init_prefix_3 "PyInit_")
set(config_inits "")
set(config_entries "")
foreach(ext ${builtin_extensions})
set(config_inits "${config_inits}extern ${init_return_type_${PY_VERSION_MAJOR}} ${init_prefix_${PY_VERSION_MAJOR}}${ext}(void);\n")
set(config_entries "${config_entries} {\"${ext}\", ${init_prefix_${PY_VERSION_MAJOR}}${ext}},\n")
endforeach()
if(PY_VERSION VERSION_GREATER_EQUAL "3.7")
set(PyInit_imp "PyInit__imp")
else()
set(PyInit_imp "PyInit_imp")
endif()
configure_file(
${PROJECT_SOURCE_DIR}/cmake/config_${PY_VERSION_MAJOR}.c.in
${PROJECT_BINARY_DIR}/CMakeFiles/config.c
)
# Collect libpython target libraries
set(LIBPYTHON_TARGET_LIBRARIES
${builtin_link_libraries}
)
if(HAVE_LIBDL)
list(APPEND LIBPYTHON_TARGET_LIBRARIES ${HAVE_LIBDL})
endif()
if(WITH_THREAD OR PY_VERSION VERSION_GREATER_EQUAL "3.7")
list(APPEND LIBPYTHON_TARGET_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
endif()
if(UNIX)
list(APPEND LIBPYTHON_TARGET_LIBRARIES ${LIBUTIL_LIBRARIES} ${M_LIBRARIES})
endif()
if(WIN32 AND IS_PY3)
list(APPEND LIBPYTHON_TARGET_LIBRARIES ws2_32) # Required by signalmodule
if(PY_VERSION VERSION_GREATER_EQUAL "3.5")
list(APPEND LIBPYTHON_TARGET_LIBRARIES version) # Required by sysmodule
endif()
if(PY_VERSION VERSION_GREATER_EQUAL "3.6")
list(APPEND LIBPYTHON_TARGET_LIBRARIES shlwapi) # Required by PC/getpathp
endif()
if(PY_VERSION VERSION_GREATER_EQUAL "3.9")
list(APPEND LIBPYTHON_TARGET_LIBRARIES pathcch)
endif()
endif()
set(LIBPYTHON_FROZEN_SOURCES )
if(IS_PY3)
# Build _freeze_importlib executable
add_executable(_freeze_importlib
${SRC_DIR}/Programs/_freeze_importlib.c
${LIBPYTHON_OMIT_FROZEN_SOURCES}
)
target_link_libraries(_freeze_importlib ${LIBPYTHON_TARGET_LIBRARIES})
if(builtin_compile_definitions_without_py_limited_api)
target_compile_definitions(_freeze_importlib PUBLIC ${builtin_compile_definitions_without_py_limited_api})
endif()
# Freeze modules
set(LIBPYTHON_FROZEN_SOURCES
${SRC_DIR}/Python/importlib_external.h
${SRC_DIR}/Python/importlib.h
)
if(PY_VERSION VERSION_GREATER_EQUAL "3.8")
list(APPEND LIBPYTHON_FROZEN_SOURCES
${SRC_DIR}/Python/importlib_zipimport.h
)
endif()
add_custom_command(
OUTPUT ${LIBPYTHON_FROZEN_SOURCES}
COMMAND
${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:_freeze_importlib>
$<$<VERSION_GREATER_EQUAL:${PY_VERSION},3.8>:importlib._bootstrap_external>
${SRC_DIR}/Lib/importlib/_bootstrap_external.py
${SRC_DIR}/Python/importlib_external.h
COMMAND
${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:_freeze_importlib>
$<$<VERSION_GREATER_EQUAL:${PY_VERSION},3.8>:importlib._bootstrap>
${SRC_DIR}/Lib/importlib/_bootstrap.py
${SRC_DIR}/Python/importlib.h
DEPENDS
_freeze_importlib
${SRC_DIR}/Lib/importlib/_bootstrap_external.py
${SRC_DIR}/Lib/importlib/_bootstrap.py
)
if(PY_VERSION VERSION_GREATER_EQUAL "3.8")
add_custom_command(
OUTPUT ${LIBPYTHON_FROZEN_SOURCES}
COMMAND
${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:_freeze_importlib>
zipimport
${SRC_DIR}/Lib/zipimport.py
${SRC_DIR}/Python/importlib_zipimport.h
DEPENDS
${SRC_DIR}/Lib/zipimport.py
APPEND
)
endif()
# This is a convenience target allowing to regenerate
# the frozen sources.
add_custom_target(freeze_modules DEPENDS ${LIBPYTHON_FROZEN_SOURCES})
endif()
if(PY_VERSION VERSION_LESS "3.8")
# Build pgen executable
set(PGEN2_SOURCES
${SRC_DIR}/Parser/parsetok.c
)
set(PGEN3_SOURCES
${SRC_DIR}/Python/dynamic_annotations.c
${SRC_DIR}/Parser/parsetok_pgen.c
)
add_executable(pgen
${PARSER_COMMON_SOURCES}
${PGEN${PY_VERSION_MAJOR}_SOURCES}
${SRC_DIR}/Objects/obmalloc.c
${SRC_DIR}/Python/mysnprintf.c
${SRC_DIR}/Python/pyctype.c
${SRC_DIR}/Parser/tokenizer_pgen.c
${SRC_DIR}/Parser/printgrammar.c
${SRC_DIR}/Parser/pgenmain.c
)
if(builtin_compile_definitions_without_py_limited_api)
target_compile_definitions(pgen PUBLIC ${builtin_compile_definitions_without_py_limited_api})
endif()
endif()
# Collect libpython sources
set(LIBPYTHON_SOURCES
${LIBPYTHON_OMIT_FROZEN_SOURCES}
${LIBPYTHON_FROZEN_SOURCES}
)
if(UNIX)
list(APPEND LIBPYTHON_SOURCES
${SRC_DIR}/Python/frozen.c
)
endif()
# Build python libraries
function(add_libpython name type install component)
add_library(${name} ${type} ${LIBPYTHON_SOURCES})
target_link_libraries(${name} ${LIBPYTHON_TARGET_LIBRARIES})
if(MSVC)
# Explicitly disable COMDAT folding. Note that this was not required
# in the original "pcbuild.sln" solution file because it was side effect
# of having "/Zi" flag set.
set_target_properties(${name} PROPERTIES LINK_FLAGS /OPT:NOICF)
endif()
set_target_properties(${name} PROPERTIES
OUTPUT_NAME ${LIBPYTHON}${ABIFLAGS}
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${LIBPYTHON_LIBDIR}
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${LIBPYTHON_LIBDIR}
INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/${LIBPYTHON_LIBDIR}
)
set_target_properties(${name} PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
# Export target
set_property(GLOBAL APPEND PROPERTY PYTHON_TARGETS ${name})
if(install)
install(TARGETS ${name} EXPORT PythonTargets
ARCHIVE DESTINATION ${LIBPYTHON_ARCHIVEDIR}
LIBRARY DESTINATION ${LIBPYTHON_LIBDIR}
RUNTIME DESTINATION ${LIBPYTHON_LIBDIR}
COMPONENT ${component}
)
endif()
endfunction()
if(BUILD_LIBPYTHON_SHARED)
add_libpython(libpython-shared SHARED 1 Runtime)
set_target_properties(libpython-shared PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${LIBPYTHON_ARCHIVEDIR}
)
if(APPLE)
# HACK For python <= 2.7.3, this fix link error related to undefined _environ symbol and
# is equivalent to solution implemented in commit http://hg.python.org/cpython/rev/864b983
# The property is set here because source file properties can't be in one directory
# and used to build a target in an other directory.
set_property(
SOURCE ${SRC_DIR}/Modules/posixmodule.c
APPEND PROPERTY COMPILE_DEFINITIONS WITH_NEXT_FRAMEWORK)
endif()
set(targetname "libpython3-shared")
if(IS_PY3 AND MSVC)
# XXX Add BuildPython3_dDef
# Generate 'python3stub.def'
set(pythonstub_def ${PROJECT_BINARY_DIR}/${LIBPYTHON_ARCHIVEDIR}/${CMAKE_CFG_INTDIR}/python3stub.def)
add_custom_command(
OUTPUT ${pythonstub_def}
COMMAND ${CMAKE_COMMAND}
-DINPUT_DEF_FILE:PATH=${SRC_DIR}/PC/python3.def
-DOUTPUT_DEF_FILE:PATH=${PROJECT_BINARY_DIR}/CMakeFiles/python3stub.def
-P ${CMAKE_CURRENT_SOURCE_DIR}/generate_libpythonstub_def.cmake
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${PROJECT_BINARY_DIR}/CMakeFiles/python3stub.def
${pythonstub_def}
)
add_custom_target(generate_libpython3stub_def DEPENDS ${pythonstub_def})
# Build 'python3stub.lib' before linking 'python3.dll'
set(python3stub_lib ${PROJECT_BINARY_DIR}/${LIBPYTHON_ARCHIVEDIR}/${CMAKE_CFG_INTDIR}/python3stub.lib)
set(machine X86)
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
set(machine X64)
endif()
add_custom_command(
OUTPUT ${python3stub_lib}
COMMAND lib /nologo /def:${pythonstub_def} /out:${python3stub_lib} /MACHINE:${machine}
COMMENT "Rebuilding python3stub.lib"
DEPENDS generate_libpython3stub_def
VERBATIM
)
add_custom_target(generate_libpython3stub_lib DEPENDS ${python3stub_lib})
# Build 'python3.dll'
add_library(${targetname} SHARED ${SRC_DIR}/PC/python3dll.c ${SRC_DIR}/PC/python3.def)
set_target_properties(${targetname} PROPERTIES
OUTPUT_NAME python3
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${LIBPYTHON_LIBDIR}
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${LIBPYTHON_LIBDIR}
INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/${LIBPYTHON_LIBDIR}
)
add_dependencies(${targetname} generate_libpython3stub_lib)
target_link_libraries(${targetname} ${python3stub_lib})
endif()
if(IS_PY3 AND UNIX AND NOT APPLE)
add_library(${targetname} SHARED ${PROJECT_SOURCE_DIR}/cmake/empty.c)
set_target_properties(${targetname} PROPERTIES
LINK_FLAGS "-Wl,--no-as-needed"
OUTPUT_NAME python3
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${LIBPYTHON_LIBDIR}
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${LIBPYTHON_LIBDIR}
INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/${LIBPYTHON_LIBDIR}
)
target_link_libraries(${targetname} libpython-shared)
endif()
# Export target
if(TARGET ${targetname})
set_property(GLOBAL APPEND PROPERTY PYTHON_TARGETS ${targetname})
install(TARGETS ${targetname} EXPORT PythonTargets
ARCHIVE DESTINATION ${LIBPYTHON_ARCHIVEDIR}
LIBRARY DESTINATION ${LIBPYTHON_LIBDIR}
RUNTIME DESTINATION ${LIBPYTHON_LIBDIR}
)
endif()
endif()
if(NOT BUILD_LIBPYTHON_SHARED)
add_libpython(libpython-static STATIC ${INSTALL_DEVELOPMENT} Development)
target_compile_definitions(libpython-static
PUBLIC
Py_NO_ENABLE_SHARED
)
set_target_properties(libpython-static PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${LIBPYTHON_STATIC_ARCHIVEDIR}
)
if(INSTALL_DEVELOPMENT)
install(TARGETS libpython-static
ARCHIVE DESTINATION ${PYTHONHOME}/config/
COMPONENT Development)
endif()
endif()