Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Simplify build process
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzo committed Aug 19, 2014
1 parent bc9e046 commit 7c4c0e1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 48 deletions.
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g -std=c++0x")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++0x")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-unused-parameter -Wno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -mfpmath=sse -msse4.1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -funsafe-math-optimizations")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-trapping-math -ffinite-math-only -fvect-cost-model -mrecip")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx") # on sandy bridge and later

if(DEFINED ENV{CXX_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXX_FLAGS}") # for testing
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXX_FLAGS}")
endif()
message("CXX_FLAGS =${CMAKE_CXX_FLAGS}")

set(CMAKE_DEBUG_POSTFIX _dbg)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -DDIST_DEBUG_LEVEL=3 -DDIST_THROW_ON_ERROR")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -DNDEBUG=1")

if(DEFINED EXTRA_INCLUDE_PATH)
include_directories(${EXTRA_INCLUDE_PATH})
endif()
Expand Down
31 changes: 18 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ ifdef VIRTUAL_ENV
library_path=$(LIBRARY_PATH):$(VIRTUAL_ENV)/lib/
nose_env+=$(ld_library_path)=$($(ld_library_path)):$(VIRTUAL_ENV)/lib/
else
cmake_args=-DCMAKE_INSTALL_PREFIX=..
cmake_args=-DCMAKE_INSTALL_PREFIX=../..
library_path=$(LIBRARY_PATH):`pwd`/lib/
nose_env+=$(ld_library_path)=$($(ld_library_path)):`pwd`/lib/
endif

cy_deps=
ifdef PYDISTRIBUTIONS_USE_LIB
cy_deps=install_cc
ifdef CMAKE_INSTALL_PREFIX
cmake_args=-DCMAKE_INSTALL_PREFIX=$(CMAKE_INSTALL_PREFIX)
endif

all: test
Expand All @@ -40,16 +38,23 @@ src/test_headers.cc: $(headers)
echo 'int main () { return 0; }' >> src/test_headers.cc

configure_cc: src/test_headers.cc FORCE
mkdir -p build lib
cd build && cmake $(cmake_args) ..
mkdir -p build/debug build/release lib
cd build/debug \
&& cmake -DCMAKE_BUILD_TYPE=Debug $(cmake_args) ../..
cd build/release \
&& cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo $(cmake_args) ../..

debug_cc: configure_cc FORCE
cd build/debug && $(MAKE)

build_cc: configure_cc FORCE
cd build && $(MAKE)
release_cc: configure_cc FORCE
cd build/release && $(MAKE)

install_cc: build_cc FORCE
cd build && $(MAKE) install
install_cc: debug_cc release_cc FORCE
cd build/debug && $(MAKE) install
cd build/release && $(MAKE) install

deps_cy: $(cy_deps) FORCE
deps_cy: install_cc FORCE
pip install -r requirements.txt

dev_cy: deps_cy FORCE
Expand All @@ -60,7 +65,7 @@ install_cy: deps_cy FORCE

install: install_cc install_cy FORCE

package: build_cc FORCE
package: debug_cc release_cc FORCE
cd build && $(MAKE) package

install_cc_examples: install_cc FORCE
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and now powers machine learning infrastructure at Salesforce.com.

## Installation

distributions with pip:
For python-only support (no C++) you can install with pip:

pip install distributions

Expand Down
20 changes: 8 additions & 12 deletions doc/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@ Install requirements::

sudo apt-get install cmake libeigen3-dev

Then::
To install in ``./lib``::

mkdir build; cd build
cmake -DCMAKE_INSTALL_PREFIX=/my/prefix ..
make install

Alternatively, set a custom install location::

CMAKE_INSTALL_PREFIX=/my/prefix make install


Python wrapping libdistributions
--------------------------------

Follow instructions for C++ Standalone. Install numpy and scipy. Then::

PYDISTRIBUTIONS_USE_LIB=1 LIBRARY_PATH=/my/prefix/lib pip install distributions
LIBRARY_PATH=/my/prefix/lib pip install distributions

.. warning::

Expand Down Expand Up @@ -77,12 +79,6 @@ Install cmake. Install numpy, scipy, cython, and nosetests so that
they're available within a python virtualenv. Activate that
virtualenv. Then::

PYDISTRIBUTIONS_USE_LIB=1 make test

The top-level ``Makefile`` provides many targets useful for
development.

To use distributions in CMake targest, and to make the distributions unit
tests run faster, set the environment variable ``DISTRIBUTIONS_PATH`` to your git cloned location, for example
make test

echo 'export DISTRIBUTIONS_PATH=/path/to/distributions' >> $VIRTUAL_ENV/bin/postactivate
The top-level ``Makefile`` provides many targets useful for development.
19 changes: 1 addition & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
])


use_libdistributions = 'PYDISTRIBUTIONS_USE_LIB' in os.environ
use_protobuf = 'DISTRIBUTIONS_USE_PROTOBUF' in os.environ


Expand All @@ -111,23 +110,7 @@ def make_extension(name):
if use_protobuf:
libraries.append('protobuf')
if name.startswith('lp'):
if use_libdistributions:
libraries = ['distributions_shared'] + libraries
else:
sources += [
'src/common.cc',
'src/special.cc',
'src/random.cc',
'src/vector_math.cc',
]
if name == 'lp.clustering':
sources.append('src/clustering.cc')
elif name in ('lp.models.nich', 'lp.models._nich'):
sources.append('src/models/nich.cc')
elif name in ('lp.models.niw', 'lp.models._niw'):
sources.append('src/models/niw.cc')
elif name in ('lp.models.gp', 'lp.models._gp'):
sources.append('src/models/gp.cc')
libraries = ['distributions_shared_dbg'] + libraries
return Extension(
module,
sources=sources,
Expand Down

0 comments on commit 7c4c0e1

Please sign in to comment.