Permalink
Browse files

Cleanup installation of python helpers and closes #48

* New method for creating "python helpers"
* Make core python helpers officially public and version them
* No more header files in pure-python packages
* All python bindings depend exclusively on the python_integration library,
  which, in turn, depends on Boost.Python and Python.
* Solve Ubuntu problems with RPATHs and on OSX/MacPorts with install_name_tool
* Reflected changes on various packages
* No API changes on this one ;-)
  • Loading branch information...
anjos committed Apr 13, 2012
1 parent 67f5666 commit ed9c0bca39c34c035f147e0756be71ad456da668
@@ -41,6 +41,8 @@ if(NOT BOB_SOVERSION)
set(BOB_SOVERSION ${BOB_SOVERSION_INTERNAL})
endif()
option(SET_PUBLIC_LIBRARY_PATH "Use `ld -rpath' (Linux) or `install_name_tool' (Apple) when linking public libraries, executables. This option does not cover python bindings to C++ installed at the Python directories." ON)
option(BOB_BUILD_CXX "Builds the C++ infrastructure." ON)
option(BOB_INSTALL_PYTHON_INTERPRETER "When enabled, installs a version of the python interpreter preset to prepend Bob's environment." OFF)
@@ -98,17 +100,17 @@ set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "Flags used by the
set(CMAKE_CXX_FLAGS ${COMMON_FLAGS} CACHE STRING "Flags used by the compiler during all build types." FORCE)
set(CMAKE_C_FLAGS ${COMMON_FLAGS} CACHE STRING "Flags used by the compiler during all build types." FORCE)
# This is our RPATH policy
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# the RPATH to be used when installing
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
if(SET_PUBLIC_LIBRARY_PATH)
if (APPLE)
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
else()
# This is our RPATH policy under Linux
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
endif()
# This will make sure we consider pkg-config directories that may have been
# added when the user set CMAKE_PREFIX_PATH.
@@ -13,9 +13,22 @@
# are automatically available for the current target. Transitivity
# is correctly handled
# shared: additional libraries to link with.
# headers: [OPTIONAL] where to get the headers for this package from
#
# Example: bob_library(io "foo.cc;bar.cc" "core" "foo.so")
macro(bob_library package src dependencies shared)
if(${ARGC} LESS 5)
set(headers "${package}")
else()
set(headers "${ARGV4}")
endif()
#message(STATUS "package '${package}'")
#message(STATUS "src '${src}'")
#message(STATUS "dependencies '${dependencies}'")
#message(STATUS "shared '${shared}'")
#message(STATUS "headers '${headers}'")
string(TOUPPER "${package}" PACKAGE)
set(deps_list "")
@@ -42,10 +55,6 @@ macro(bob_library package src dependencies shared)
set_target_properties(bob_${package} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# rpath override rule for OSX
set_target_properties(bob_${package} PROPERTIES INSTALL_NAME_DIR
"${CMAKE_INSTALL_PREFIX}/lib")
if (BOB_SOVERSION)
# adds versioning information
set_target_properties(bob_${package} PROPERTIES VERSION ${BOB_VERSION})
@@ -55,7 +64,7 @@ macro(bob_library package src dependencies shared)
install(TARGETS bob_${package} EXPORT bob
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(DIRECTORY ${package} DESTINATION include/bob FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${headers} DESTINATION include/bob FILES_MATCHING PATTERN "*.h")
endmacro()
# Creates a standard Bob test.
@@ -433,20 +442,21 @@ macro(bob_python_bindings cxx_package package cxx_src pydependencies)
string(TOUPPER "${package}" PACKAGE)
string(TOUPPER "${cxx_package}" CXX_PACKAGE)
set(pydeps_list "")
set(pydeps_list "bob_${cxx_package}")
set(pyheader_list "")
if(NOT ("${pydependencies}" STREQUAL ""))
foreach(dep ${pydependencies})
string(TOUPPER "${dep}" DEP)
list(APPEND pydeps_list pybob_${dep})
list(APPEND pyheader_list "${BOB_PYTHON_${DEP}_HEADER_DIRS}")
list(APPEND pydeps_list bob_${dep})
list(APPEND pyheader_list "${BOB_${DEP}_HEADER_DIRS}")
endforeach(dep)
endif(NOT ("${pydependencies}" STREQUAL ""))
list(REMOVE_DUPLICATES pyheader_list)
set(BOB_PYTHON_${PACKAGE}_HEADER_DIRS ${CMAKE_CURRENT_SOURCE_DIR} ${BOB_${CXX_PACKAGE}_HEADER_DIRS} ${pyheader_list} CACHE INTERNAL "${package} header dirs")
include_directories(${BOB_PYTHON_${PACKAGE}_HEADER_DIRS} ${python_INCLUDE_DIRS})
#message(STATUS "Python ${package}:")
#message(STATUS "${pydependencies}")
#message(STATUS "${pyheader_list} !! ${pydeps_list}")
#message(STATUS "${package}/${cxx_package} : ${BOB_PYTHON_${PACKAGE}_HEADER_DIRS} - ${BOB_${CXX_PACKAGE}_HEADER_DIRS}")
@@ -457,27 +467,19 @@ macro(bob_python_bindings cxx_package package cxx_src pydependencies)
else()
add_library(pybob_${package} SHARED ${cxx_src})
target_link_libraries(pybob_${package} bob_${cxx_package} ${pydeps_list} ${Boost_PYTHON_LIBRARY_RELEASE} ${PYTHON_LIBRARIES})
set(pycxx_flags "-Wno-long-long -Wno-unused-function -Winvalid-pch")
target_link_libraries(pybob_${package} ${pydeps_list})
set_target_properties(pybob_${package} PROPERTIES OUTPUT_NAME "${package}")
set_target_properties(pybob_${package} PROPERTIES PREFIX "_")
set_target_properties(pybob_${package} PROPERTIES SUFFIX ".so")
set(pycxx_flags "-Wno-long-long -Wno-unused-function")
set_target_properties(pybob_${package} PROPERTIES COMPILE_FLAGS ${pycxx_flags})
set_target_properties(pybob_${package} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PYTHON_SITE_PACKAGES}/bob/${cxx_package})
string(REPLACE "_" "/" package_path ${package})
# rpath override rule for OSX
set_target_properties(pybob_${package} PROPERTIES INSTALL_NAME_DIR
"${CMAKE_INSTALL_PREFIX}/${PYTHON_SITE_PACKAGES}/bob/${package_path}")
# makes sure bindings to the right places
# makes sure bindings are installed at the right places
install(TARGETS pybob_${package} LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}/bob/${package_path})
# makes sure headers are installed
install(DIRECTORY ${package} DESTINATION include/bob FILES_MATCHING PATTERN "*.h")
endif()
# Install scripts only if not a subpackage
@@ -7,7 +7,18 @@ include(FindBoost)
set(Boost_USE_MULTITHREADED ON)
# Determine here the components you need so the system can verify
find_package(Boost COMPONENTS python unit_test_framework iostreams thread filesystem date_time program_options system regex)
find_package(Boost 1.40.0 REQUIRED
COMPONENTS
python
unit_test_framework
iostreams
thread
filesystem
date_time
program_options
system
regex
)
# Renaming so all works automagically
set(boost_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} CACHE INTERNAL "incdirs")
@@ -23,6 +23,7 @@ if (PYTHON_EXECUTABLE AND PYTHONLIBS_FOUND AND Boost_FOUND)
bob_python_script(root bob_config.py lib/script/config.py)
bob_python_add_test(root bob_config.py)
add_subdirectory(integration)
add_subdirectory(core)
add_subdirectory(io)
add_subdirectory(math)
@@ -3,32 +3,25 @@ cmake_minimum_required(VERSION 2.6)
# Python bindings
set(ccsrc
"src/version.cc"
#"src/array_wrapper_example.cc"
"src/exception.cc"
"src/logging.cc"
"src/profile.cc"
"src/main.cc"
)
set(ccsrc_ndarray
"src/ndarray.cc"
"src/blitz_numpy.cc"
"src/ndarray_numpy.cc"
"src/convert.cc"
"src/tinyvector.cc"
"src/typeinfo.cc"
"src/convert.cc"
#"src/array_wrapper_example.cc"
"src/main_ndarray.cc"
"src/version.cc"
"src/main.cc"
)
set(ccsrc_random
"src/random.cc"
"src/main_random.cc"
)
bob_python_package_bindings(core "${ccsrc}" "")
bob_python_subpackage_bindings(core array "${ccsrc_ndarray}" "")
bob_python_subpackage_bindings(core random "${ccsrc_random}" "")
bob_python_package_bindings(core "${ccsrc}" "python_integration")
bob_python_subpackage_bindings(core random "${ccsrc_random}"
"python_integration")
# Our test units
bob_python_add_unittest(core lib/test/exception.py)
@@ -1,3 +1,6 @@
from ._core_array import *
from .. import convert as __convert__
def convert(*args, **kwargs):
__convert__(*args, **kwargs)
convert.__doc__ = __convert__.__doc__
__all__ = dir()
@@ -30,25 +30,25 @@ class ConversionTest(unittest.TestCase):
def xtest01_default_ranges(self):
x = numpy.array(range(6), 'uint8').reshape(2,3)
c = bob.core.array.convert(x, 'uint16')
c = bob.core.convert(x, 'uint16')
self.assertTrue( numpy.array_equal(x.astype('uint16'), c) )
def xtest02_from_range(self):
x = numpy.array(range(6), 'uint8').reshape(2,3)
c = bob.core.array.convert(x, 'uint16', source_range=(0,255))
c = bob.core.convert(x, 'uint16', source_range=(0,255))
self.assertTrue( numpy.array_equal(x.astype('float64'), c) )
def test03_to_range(self):
x = numpy.array(range(6), 'uint8').reshape(2,3)
c = bob.core.array.convert(x, 'float64', dest_range=(0.,255.))
c = bob.core.convert(x, 'float64', dest_range=(0.,255.))
self.assertTrue( numpy.array_equal(x.astype('float64'), c) )
def test04_from_and_to_range(self):
x = numpy.array(range(6), 'uint8').reshape(2,3)
c = bob.core.array.convert(x, 'float64', source_range=(0,255),
c = bob.core.convert(x, 'float64', source_range=(0,255),
dest_range=(0.,255.))
self.assertTrue( numpy.array_equal(x.astype('float64'), c) )
@@ -155,6 +155,6 @@ static object convert (tp::const_ndarray src, object dtype_like,
BOOST_PYTHON_FUNCTION_OVERLOADS(convert_overloads, convert, 2, 4)
void bind_core_array_convert() {
void bind_core_convert() {
def("convert", &convert, convert_overloads((arg("array"), arg("dtype"), arg("dest_range")=object(), arg("source_range")=object()), "Function which allows to convert/rescale a array of a given type into another array of a possibly different type with re-scaling. Typically, this can be used to rescale a 16 bit precision grayscale image (2D array) into an 8 bit precision grayscale image.\n\n Parameters:\n\n array -- (array) Input array\n\n dtype -- (string) Controls the output element type for the returned array\n\n dest_range -- (tuple) Determines the range to be deployed at the returned array\n\n source_range -- (tuple) Determines the input range that will be used for the scaling\n\n Returns: A new array with the same shape as this one, but re-scaled and with its element type as indicated by the user."));
}
@@ -28,6 +28,11 @@ void bind_core_version();
void bind_core_exception();
void bind_core_logging();
void bind_core_profiler();
void bind_core_bz_numpy();
void bind_core_ndarray_numpy();
void bind_core_typeinfo();
void bind_core_convert();
void bind_core_tinyvector();
BOOST_PYTHON_MODULE(_core) {
docstring_options docopt;
@@ -40,4 +45,9 @@ BOOST_PYTHON_MODULE(_core) {
bind_core_exception();
bind_core_logging();
bind_core_profiler();
bind_core_bz_numpy();
bind_core_ndarray_numpy();
bind_core_typeinfo();
bind_core_convert();
bind_core_tinyvector();
}

This file was deleted.

Oops, something went wrong.
@@ -185,7 +185,7 @@ void register_tinyvec_to_tuple() {
>();
}
void bind_core_array_tinyvector () {
void bind_core_tinyvector () {
/**
* The following struct constructors will make sure we can input
@@ -43,7 +43,7 @@ static tuple ti_stride(const ca::typeinfo& ti) {
}
void bind_core_array_typeinfo() {
void bind_core_typeinfo() {
class_<ca::typeinfo>("typeinfo", "Type information for bob C++ data",
no_init)
@@ -23,7 +23,7 @@ endif()
include(${QT_USE_FILE})
include_directories(${QT_INCLUDE_DIR})
bob_python_package_bindings(daq "${ccsrc}" "core_array")
bob_python_package_bindings(daq "${ccsrc}" "python_integration")
target_link_libraries(pybob_daq ${QT_LIBRARIES})
@@ -0,0 +1,16 @@
project(core-python-integration)
cmake_minimum_required(VERSION 2.6)
# Python helper for blitz::Array<> <-> Numpy.ndarray conversion. This base
# helper *must* be used by all other extensions and is versioned, like any
# other public library in Bob.
set(src
"src/ndarray.cc"
"src/blitz_numpy.cc"
"src/ndarray_numpy.cc"
)
bob_library(python_integration "${src}" "core" "${Boost_PYTHON_LIBRARY_RELEASE};${PYTHON_LIBRARIES}" "core")
set_target_properties(bob_python_integration PROPERTIES COMPILE_FLAGS
"-Wno-long-long -Wno-unused-function")
@@ -20,7 +20,7 @@ endif(FFMPEG_FOUND)
add_definitions("-D__STDC_CONSTANT_MACROS")
bob_python_package_bindings(io "${ccsrc}" "core_array")
bob_python_package_bindings(io "${ccsrc}" "python_integration")
# Our test units
bob_python_add_unittest(io lib/test/array.py)
@@ -37,7 +37,7 @@ if(VLFEAT_FOUND)
set(ccsrc "src/vlsift.cc;src/vldsift.cc;${ccsrc}")
endif()
bob_python_package_bindings(ip "${ccsrc}" "core_array")
bob_python_package_bindings(ip "${ccsrc}" "python_integration")
# Our test units
bob_python_add_unittest(ip lib/test/lbp_new.py)
@@ -25,7 +25,7 @@ if(LIBSVM_FOUND)
set(ccsrc "src/svm.cc;${ccsrc}")
endif()
bob_python_package_bindings(machine "${ccsrc}" "core_array")
bob_python_package_bindings(machine "${ccsrc}" "python_integration")
# Our test units
bob_python_add_unittest(machine lib/test/gaussian.py)
@@ -9,7 +9,7 @@ set(ccsrc
"src/main.cc"
)
bob_python_package_bindings(math "${ccsrc}" "core_array")
bob_python_package_bindings(math "${ccsrc}" "python_integration")
# Our test units
bob_python_add_unittest(math lib/test/interiorpointLP.py)
Oops, something went wrong.

0 comments on commit ed9c0bc

Please sign in to comment.