forked from fblumenthal/buildem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
python.cmake
91 lines (75 loc) · 3.64 KB
/
python.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
#
# Install python from source
#
# Defines the following:
# PYTHON_INCLUDE_PATH
# PYTHON_EXE -- path to python executable
if (NOT python_NAME)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
include (ExternalProject)
include (ExternalSource)
include (BuildSupport)
include (zlib)
include (openssl) # without openssl, hashlib might have missing encryption methods
external_source (python
2.7.6
Python-2.7.6.tgz
1d8728eb0dfcac72a0fd99c17ec7f386
http://www.python.org/ftp/python/2.7.6)
message ("Installing ${python_NAME} into FlyEM build area: ${BUILDEM_DIR} ...")
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# On Mac, we build a "Framework" build which has all the power of a "normal" build,
# plus it can be used from a native GUI.
# See http://svn.python.org/projects/python/trunk/Mac/README
set (PYTHON_BINARY_TYPE_ARG "--enable-framework=${BUILDEM_DIR}/Frameworks")
set (PYTHON_PREFIX ${BUILDEM_DIR}/Frameworks/Python.framework/Versions/2.7)
else()
# On linux, PYTHON_PREFIX is the same as the general prefix.
set (PYTHON_BINARY_TYPE_ARG "--enable-shared")
set (PYTHON_PREFIX ${BUILDEM_DIR})
endif()
set (PYTHON_BUILD_DEBUG "FALSE" CACHE BOOL "Configure Python --with-pydebug and --without-pymalloc for debugging extensions with gdb.")
if (${PYTHON_BUILD_DEBUG})
# If you want to debug python with gdb, you need --with-pydebug.
# Also, --without-pymalloc is useful if you want to avoid assertions in PyMalloc
# that can be caused by some python extensions (e.g. the python vtk bindings hit those assertions)
# Of course, if those assertions are hit by code that YOU wrote, then you might
# want to change this build command so you can debug WITH pymalloc.
set(PYTHON_DEBUG_CONFIG_ARGS "--with-pydebug --without-pymalloc")
endif()
ExternalProject_Add(${python_NAME}
DEPENDS ${zlib_NAME} ${openssl_NAME}
PREFIX ${BUILDEM_DIR}
URL ${python_URL}
URL_MD5 ${python_MD5}
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ${BUILDEM_ENV_STRING} ${python_SRC_DIR}/configure
--prefix=${BUILDEM_DIR}
${PYTHON_BINARY_TYPE_ARG}
${PYTHON_DEBUG_CONFIG_ARGS}
"LDFLAGS=${BUILDEM_LDFLAGS} ${BUILDEM_ADDITIONAL_CXX_FLAGS}"
"CPPFLAGS=-I${BUILDEM_DIR}/include ${BUILDEM_ADDITIONAL_CXX_FLAGS}"
BUILD_COMMAND ${BUILDEM_ENV_STRING} $(MAKE)
INSTALL_COMMAND ${BUILDEM_ENV_STRING} $(MAKE)
PYTHONAPPSDIR=${BUILDEM_BIN_DIR}/${python_NAME} install
BUILD_IN_SOURCE 1 # Required for Mac
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
ExternalProject_Add_Step(${python_NAME} ${python_NAME}-fix-readline-bug
COMMAND bash ${PATCH_DIR}/python-fix-readline-bug.sh ${PYTHON_PREFIX}
DEPENDEES install
)
endif()
set (PYTHON_INCLUDE_PATH ${PYTHON_PREFIX}/include/python2.7)
set (PYTHON_LIBRARY_FILE ${PYTHON_PREFIX}/lib/libpython2.7.${BUILDEM_PLATFORM_DYLIB_EXTENSION})
set (BUILDEM_PYTHONPATH ${PYTHON_PREFIX}/lib/python2.7:${PYTHON_PREFIX}/lib/python2.7/site-packages:${PYTHON_PREFIX}/lib)
set (PYTHON_EXE ENV PYTHONPATH=${BUILDEM_PYTHONPATH} ${PYTHON_PREFIX}/bin/python)
# Update our bin PATH variable to include the python bin path
# (Important for Mac OS X, which uses a special python prefix. See above)
set (BUILDEM_BIN_PATH ${PYTHON_PREFIX}/bin:${BUILDEM_BIN_PATH})
# Append our revised bin PATH variable to ENV string.
# (This means that PATH will be specified TWICE in the env string, but the second one takes precedence.)
set (BUILDEM_ENV_STRING env ${BUILDEM_ENV_STRING} PATH=${BUILDEM_BIN_PATH})
set_target_properties(${python_NAME} PROPERTIES EXCLUDE_FROM_ALL ON)
endif (NOT python_NAME)