Skip to content

Instantly share code, notes, and snippets.

@Debilski
Last active June 13, 2016 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Debilski/3bb57bd35e6465cede903443aaeac997 to your computer and use it in GitHub Desktop.
Save Debilski/3bb57bd35e6465cede903443aaeac997 to your computer and use it in GitHub Desktop.
import argparse
import subprocess
description = """
This sets up the build for OpenCV and helps with finding
the right Python versions."
Run as:
cd $OPENCV_directory
mkdir build
cd build
wget -O build.py $THIS_FILE
python2 build.py --python2 PATH-TO-PYTHON2 \
--python3 PATH-TO-PYTHON3 \
-- -DCMAKE_INSTALL_PREFIX=/where/to/install/to ..
make
make install
"""
parser = argparse.ArgumentParser(description=description)
parser.add_argument('--python2', help='The Python 2 executable')
parser.add_argument('--python3', help='The Python 3 executable')
parser.add_argument('cmake_opts', help='Other CMAKE options.', type=str, nargs='+')
def get_include_dir(py):
cmd = [py, '-c', 'from distutils.sysconfig import get_python_inc; print(get_python_inc())']
return subprocess.check_output(cmd).rstrip()
def get_packages_libdir(py):
cmd = [py, '-c', 'from distutils.sysconfig import get_config_var; print(get_config_var("LIBDIR"))']
cmd_lib = [py, '-c', 'from distutils.sysconfig import get_config_var; print(get_config_var("LDLIBRARY"))']
return subprocess.check_output(cmd).rstrip() + "/" + subprocess.check_output(cmd_lib).rstrip()
def get_packages_path(py):
cmd = [py, '-c', 'from distutils.sysconfig import get_python_lib; print(get_python_lib())']
return subprocess.check_output(cmd).rstrip()
cmake_args = ["cmake"]
args = parser.parse_args()
if args.python2:
cmake_args += ["-DPYTHON2_EXECUTABLE=" + args.python2]
cmake_args += ["-DPYTHON2_LIBRARY=" + get_packages_libdir(args.python2)]
cmake_args += ["-DPYTHON2_INCLUDE_DIR=" + get_include_dir(args.python2)]
cmake_args += ["-DPYTHON2_PACKAGES_PATH=" + get_packages_path(args.python2)]
if args.python3:
cmake_args += ["-DPYTHON3_EXECUTABLE=" + args.python3]
cmake_args += ["-DPYTHON3_LIBRARY=" + get_packages_libdir(args.python3)]
cmake_args += ["-DPYTHON3_INCLUDE_DIR=" + get_include_dir(args.python3)]
cmake_args += ["-DPYTHON3_PACKAGES_PATH=" + get_packages_path(args.python3)]
cmake_args += args.cmake_opts
print(cmake_args)
p = subprocess.Popen(cmake_args)
p.wait()
print(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment