Skip to content

Commit

Permalink
Build using cmake, even if using setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
paulinus committed Feb 27, 2015
1 parent 098acb4 commit 2c38c62
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 141 deletions.
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ Be sure to update your `PYTHONPATH` to include `/usr/local/lib/python2.7/site-pa
sudo pip install scipy


## Building inplace using setup.py
## Building

python setup.py build_clib
python setup.py build_ext --inplace
python setup.py build

## Building using CMake

mkdir build
cd build
cmake ../opensfm/src
make

## Running

Expand Down
5 changes: 1 addition & 4 deletions opensfm/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,5 @@ def mkdir_p(path):
try:
os.makedirs(path)
except os.error as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
if exc.errno != errno.EEXIST or not os.path.isdir(path):
raise

146 changes: 18 additions & 128 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,136 +1,29 @@
#!/usr/bin/env python

from distutils.core import setup, Extension
import numpy as np
from distutils.core import setup
import sys
import os
import glob
import errno
import subprocess

default_include_dirs = [
'/usr/local/include',
'/usr/include',
]

cplus_include_path = os.getenv('CPLUS_INCLUDE_PATH', '')
if cplus_include_path:
default_include_dirs.extend(cplus_include_path.split(':'))
def mkdir_p(path):
'''Make a directory including parent directories.
'''
try:
os.makedirs(path)
except os.error as exc:
if exc.errno != errno.EEXIST or not os.path.isdir(path):
raise

print "Configuring..."
mkdir_p('cmake_build')
subprocess.Popen(['cmake','../opensfm/src'], cwd='cmake_build').wait()

def find_path(name, hints, path_suffixes=[]):
suffixes = [''] + path_suffixes
for c in hints:
for s in suffixes:
path = os.path.join(c, s)
if os.path.isfile(os.path.join(path, name)):
return path
return None

def find_include(name, hints, path_suffixes=[]):
return find_path(name, hints + default_include_dirs, path_suffixes)


libraries = []
library_dirs = ['/usr/local/lib']

# Eigen
eigen_include_dir = find_include('Eigen/Core', [], ['eigen3'])

# Ceres
ceres_libraries = ['ceres', 'glog', 'gflags']
libraries.extend(ceres_libraries)

if sys.platform.startswith('linux'):
# SuiteSparse
suitesparse_libraries = ['spqr', 'cholmod', 'ccolamd', 'camd', 'colamd', 'amd', 'lapack', 'f77blas', 'atlas', 'f77blas', 'atlas', 'suitesparseconfig', 'rt',]
libraries.extend(suitesparse_libraries)

# Lapack
lapack_libraries = ['lapack', 'f77blas', 'atlas',]
libraries.extend(lapack_libraries)

# Boost Python
boost_python_libraries = ['boost_python']
libraries.extend(boost_python_libraries)

# OpenCV
opencv_libraries = ['opencv_videostab', 'opencv_video', 'opencv_ts', 'opencv_superres', 'opencv_stitching', 'opencv_photo', 'opencv_ocl', 'opencv_objdetect', 'opencv_nonfree', 'opencv_ml', 'opencv_legacy', 'opencv_imgproc', 'opencv_highgui', 'opencv_gpu', 'opencv_flann', 'opencv_features2d', 'opencv_core', 'opencv_contrib', 'opencv_calib3d']

libraries.extend(opencv_libraries)

# Akaze
akaze_include_dir = 'opensfm/src/third_party/akaze/lib'
akaze_sources = [
'opensfm/src/third_party/akaze/lib/AKAZE.cpp',
'opensfm/src/third_party/akaze/lib/fed.cpp',
'opensfm/src/third_party/akaze/lib/nldiffusion_functions.cpp',
'opensfm/src/third_party/akaze/lib/utils.cpp',
]
akaze_depends = [
'opensfm/src/third_party/akaze/lib/AKAZEConfig.h',
'opensfm/src/third_party/akaze/lib/AKAZE.h',
'opensfm/src/third_party/akaze/lib/fed.h',
'opensfm/src/third_party/akaze/lib/nldiffusion_functions.h',
'opensfm/src/third_party/akaze/lib/utils.h',
]
akaze_library = ('akaze', {
'sources': akaze_sources,
'depends': akaze_depends,
'include_dirs': [akaze_include_dir],
})

# libmv
libmv_include_dir = 'opensfm/src/third_party'
libmv_sources = [
'opensfm/src/third_party/libmv/multiview/fundamental.cc',
'opensfm/src/third_party/libmv/multiview/projection.cc',
'opensfm/src/third_party/libmv/multiview/five_point.cc',
'opensfm/src/third_party/libmv/multiview/robust_five_point.cc',
'opensfm/src/third_party/libmv/multiview/triangulation.cc',
'opensfm/src/third_party/libmv/multiview/conditioning.cc',
'opensfm/src/third_party/libmv/numeric/numeric.cc',
'opensfm/src/third_party/libmv/numeric/poly.cc',
]
libmv_library = ('mv', {
'sources': libmv_sources,
'include_dirs': [libmv_include_dir, eigen_include_dir],
})

# VLFeat
vlfeat_include_dir = 'opensfm/src/third_party/vlfeat'
vlfeat_sources = glob.glob('opensfm/src/third_party/vlfeat/vl/*.c')
vlfeat_depends = glob.glob('opensfm/src/third_party/vlfeat/vl/*.h')
vlfeat_library = ('vl', {
'sources': vlfeat_sources,
'depends': vlfeat_depends,
'macros': [('VL_DISABLE_AVX', '1')],
})

# cSfM
csfm_extra_compile_args = ['-std=c++11']
csfm_extra_link_args = []
if sys.platform.startswith('darwin'):
csfm_extra_compile_args.extend(['-stdlib=libc++', '-mmacosx-version-min=10.7'])
elif sys.platform.startswith('linux'):
csfm_extra_compile_args.extend(['-fopenmp'])
csfm_extra_link_args.extend(['-fopenmp'])

csfm_extension = Extension(
'opensfm.csfm',
sources=['opensfm/src/csfm.cc'],
depends=['bundle.h'],
include_dirs=[
np.get_include(),
eigen_include_dir,
libmv_include_dir,
akaze_include_dir,
vlfeat_include_dir,
],
libraries=libraries,
library_dirs = library_dirs,
extra_compile_args=csfm_extra_compile_args,
extra_link_args=csfm_extra_link_args,
)
print "Compiling extension..."
subprocess.Popen(['make','-j4'], cwd='cmake_build').wait()

print "Building package"
setup(
name='OpenSfM',
version='0.1',
Expand All @@ -139,8 +32,5 @@ def find_include(name, hints, path_suffixes=[]):
author='Mapillary',
license='BSD',
packages=['opensfm'],
libraries=[vlfeat_library, libmv_library, akaze_library],
ext_modules=[csfm_extension],
package_data={'opensfm': ['csfm.so']},
)


0 comments on commit 2c38c62

Please sign in to comment.