forked from Slicer/Slicer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlicerBlockInstallPython.cmake
148 lines (131 loc) · 5.36 KB
/
SlicerBlockInstallPython.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
# -------------------------------------------------------------------------
# Find and install python
# -------------------------------------------------------------------------
if(Slicer_USE_PYTHONQT)
# Sanity checks
foreach(varname IN ITEMS Slicer_SUPERBUILD_DIR PYTHON_STDLIB_SUBDIR)
if("${${varname}}" STREQUAL "")
message(FATAL_ERROR "${varname} CMake variable is expected to be set")
endif()
endforeach()
set(PYTHON_DIR "${Slicer_SUPERBUILD_DIR}/python-install")
if(NOT EXISTS "${PYTHON_DIR}/${PYTHON_STDLIB_SUBDIR}")
message(WARNING "###############################################################################
Skipping generation of python install rules
Non-existing directory PYTHON_DIR:${PYTHON_DIR}/${PYTHON_STDLIB_SUBDIR}
This probably means that you are building Slicer against your own installation of Python.
To create a Slicer package including python libraries, you can *NOT* provide your own version of the python libraries.
###############################################################################")
return()
endif()
# Install libraries
set(extra_exclude_pattern)
if(UNIX)
list(APPEND extra_exclude_pattern
REGEX "distutils/command/wininst-.*" EXCLUDE
)
endif()
install(
DIRECTORY "${PYTHON_DIR}/${PYTHON_STDLIB_SUBDIR}/"
DESTINATION "${Slicer_INSTALL_ROOT}lib/Python/${PYTHON_STDLIB_SUBDIR}/"
COMPONENT Runtime
USE_SOURCE_PERMISSIONS
REGEX "lib2to3/tests/" EXCLUDE
REGEX "lib[-]old/" EXCLUDE
REGEX "plat[-].*" EXCLUDE
REGEX "/test/" EXCLUDE
REGEX "/tests/" EXCLUDE
${extra_exclude_pattern}
)
# Strip symbols of selected libraries for which ones (1) stripping has a
# significant impact and (2) stripping does not prevent the import of
# of the module.
# See https://github.com/Slicer/Slicer/issues/5474
slicerStripInstalledLibrary(
PATTERN "${Slicer_INSTALL_ROOT}lib/Python/${PYTHON_STDLIB_SUBDIR}/_SimpleITK.*.so"
COMPONENT Runtime
)
# Install python library
if(UNIX)
if(NOT APPLE)
slicerInstallLibrary(
FILE ${PYTHON_LIBRARY}
DESTINATION ${Slicer_INSTALL_ROOT}lib/Python/lib
COMPONENT Runtime
PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ)
# Explicitly call "slicerStripInstalledLibrary" because directly
# calling "slicerInstallLibrary" improperly gets the python library
# filename ("libpython3" instead of "libpython3.6m").
#
# This happens because "slicerInstallLibrary" internally uses
# "get_filename_component" with the NAME_WE option.
get_filename_component(libname ${PYTHON_LIBRARY} NAME)
slicerStripInstalledLibrary(
FILES "${Slicer_INSTALL_ROOT}lib/Python/lib/${libname}"
COMPONENT Runtime)
endif()
elseif(WIN32)
# Copy Python36.dll
get_filename_component(PYTHON_LIB_BASE ${PYTHON_LIBRARY} NAME_WE)
install(FILES "${PYTHON_LIBRARY_PATH}/${PYTHON_LIB_BASE}.dll"
DESTINATION bin
COMPONENT Runtime)
# Copy python3.dll
# The file name is always exactly this, as this file is guaranteed
# to be ABI compatible across all Python3 versions
# (see https://www.python.org/dev/peps/pep-0384/#linkage
# and https://github.com/Slicer/Slicer/issues/5816 for details).
install(FILES "${PYTHON_LIBRARY_PATH}/python3.dll"
DESTINATION bin
COMPONENT Runtime)
endif()
# Install interpreter
get_filename_component(python_bin_dir ${PYTHON_EXECUTABLE} PATH)
install(
PROGRAMS ${python_bin_dir}/python${CMAKE_EXECUTABLE_SUFFIX}
DESTINATION ${Slicer_INSTALL_BIN_DIR}
RENAME python-real${CMAKE_EXECUTABLE_SUFFIX}
COMPONENT Runtime
)
if(APPLE)
# Fixes Slicer issue #4554
set(dollar "$")
install(CODE
"set(app ${Slicer_INSTALL_BIN_DIR}/python-real)
set(appfilepath \"${dollar}ENV{DESTDIR}${dollar}{CMAKE_INSTALL_PREFIX}/${dollar}{app}\")
message(\"CPack: - Adding rpath to ${dollar}{app}\")
execute_process(COMMAND install_name_tool -add_rpath @loader_path/.. ${dollar}{appfilepath})"
COMPONENT Runtime
)
endif()
# Install Slicer python launcher settings
macro(_install_python_launcher executablename)
# Install Slicer python launcher settings
install(
FILES ${python_bin_dir}/${executablename}LauncherSettingsToInstall.ini
DESTINATION ${Slicer_INSTALL_BIN_DIR}
RENAME ${executablename}LauncherSettings.ini
COMPONENT Runtime
)
# Install Slicer python launcher
# Regardless of how the main application is built (GUI or console application - as specified by Slicer_BUILD_WIN32_CONSOLE),
# the Python console is always use the console launcher (CTKAppLauncher) and not the GUI launcher (CTKAppLauncherW).
set(_launcher CTKAppLauncher)
install(
PROGRAMS ${CTKAppLauncher_DIR}/bin/${_launcher}${CMAKE_EXECUTABLE_SUFFIX}
DESTINATION ${Slicer_INSTALL_BIN_DIR}
RENAME ${executablename}${CMAKE_EXECUTABLE_SUFFIX}
COMPONENT Runtime
)
endmacro()
_install_python_launcher(PythonSlicer)
# Install headers
set(python_include_subdir /Include/)
if(UNIX)
set(python_include_subdir /include/python${Slicer_PYTHON_VERSION_DOT}${Slicer_PYTHON_ABIFLAGS}/)
endif()
install(FILES "${PYTHON_DIR}${python_include_subdir}/pyconfig.h"
DESTINATION ${Slicer_INSTALL_ROOT}lib/Python${python_include_subdir}
COMPONENT Runtime
)
endif()