-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some python version issues with cmake
Summary: This script will attempt to determine files that will be useful for building with the correct python version. Currently on macOS with various python installations CMake fails to determine the correct location of python libraries. Closes facebookarchive/caffe2#163 Reviewed By: Yangqing Differential Revision: D4594954 Pulled By: bwasti fbshipit-source-id: c2b750ee9608a02fad4ce2f2293f5fa54dc7011c
- Loading branch information
1 parent
26be197
commit 7a65736
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
############################################################################## | ||
# 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) |