forked from facebookarchive/caffe2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_python_cmake_flags.py
41 lines (36 loc) · 1.27 KB
/
get_python_cmake_flags.py
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
## @package get_python_cmake_flags
# Module scripts.get_python_cmake_flags
##############################################################################
# Use this script to find your preferred python installation.
##############################################################################
#
# You can use the following to build with your preferred version of python
# if your installation is not being properly detected by CMake.
#
# mkdir -p build && cd build
# cmake $(python ../scripts/get_python_libs.py) ..
# make
#
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from distutils import sysconfig
import os
import sys
import platform
version = platform.python_version()
if version[:3] != '2.7':
print('ERROR: Python {version} is not officially supported yet.'
.format(version=version), file=sys.stderr)
exit(1)
# Flags to print to stdout
flags = ''
inc = sysconfig.get_python_inc()
lib = sysconfig.get_config_var("LIBDIR")
# macOS specific
if sys.platform == "darwin":
lib = os.path.dirname(lib) + '/Python'
if os.path.isfile(lib):
flags += '-DPYTHON_LIBRARY={lib}'.format(lib=lib)
if os.path.isfile(inc + '/Python.h'):
flags += '-DPYTHON_INCLUDE_DIR={inc}'.format(inc=inc)