Used python.in to generate setup.py
Also fixed cmake stuff to copy library to correct location Minor improvements of cmake Automatic install of python packagerelease/4.3a0
parent
4c44ddc4e6
commit
fb8a62dd1d
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# Guard to avoid breaking this code in ccmake if by accident GTSAM_PYTHON_VERSION is set to an empty string
|
# Guard to avoid breaking this code in ccmake if by accident GTSAM_PYTHON_VERSION is set to an empty string
|
||||||
if(GTSAM_PYTHON_VERSION STREQUAL "")
|
if(GTSAM_PYTHON_VERSION STREQUAL "")
|
||||||
set(GTSAM_PYTHON_VERSION "Default" CACHE STRING "Target python version for GTSAM python module. Use 'Default' to chose the default version" FORCE)
|
set(GTSAM_PYTHON_VERSION "Default" CACHE STRING "Target python version for GTSAM python module. Use 'Default' to chose the default version" FORCE)
|
||||||
|
@ -18,6 +17,18 @@ if(NOT (${GTSAM_PYTHON_VERSION} MATCHES ${GTSAM_LAST_PYTHON_VERSION}))
|
||||||
set(GTSAM_LAST_PYTHON_VERSION ${GTSAM_PYTHON_VERSION} CACHE STRING "Updating python version used in the last build" FORCE)
|
set(GTSAM_LAST_PYTHON_VERSION ${GTSAM_PYTHON_VERSION} CACHE STRING "Updating python version used in the last build" FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(GTSAM_PYTHON_VERSION STREQUAL "Default")
|
||||||
|
# Search the default version.
|
||||||
|
find_package(PythonInterp)
|
||||||
|
find_package(PythonLibs)
|
||||||
|
else()
|
||||||
|
find_package(PythonInterp ${GTSAM_PYTHON_VERSION})
|
||||||
|
find_package(PythonLibs ${GTSAM_PYTHON_VERSION})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Find NumPy C-API -- this is part of the numpy package
|
||||||
|
find_package(NumPy)
|
||||||
|
|
||||||
# Compose strings used to specify the boost python version. They will be empty if we want to use the defaut
|
# Compose strings used to specify the boost python version. They will be empty if we want to use the defaut
|
||||||
if(NOT GTSAM_PYTHON_VERSION STREQUAL "Default")
|
if(NOT GTSAM_PYTHON_VERSION STREQUAL "Default")
|
||||||
string(REPLACE "." "" BOOST_PYTHON_VERSION_SUFFIX ${GTSAM_PYTHON_VERSION}) # Remove '.' from version
|
string(REPLACE "." "" BOOST_PYTHON_VERSION_SUFFIX ${GTSAM_PYTHON_VERSION}) # Remove '.' from version
|
||||||
|
@ -29,29 +40,12 @@ else()
|
||||||
set(BOOST_PYTHON_VERSION_SUFFIX_UPPERCASE "")
|
set(BOOST_PYTHON_VERSION_SUFFIX_UPPERCASE "")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Find NumPy C-API -- this is part of the numpy package
|
|
||||||
find_package(NumPy)
|
|
||||||
|
|
||||||
# Find Python
|
|
||||||
# First, be sure that python version can be found by FindPythonLibs.cmake
|
|
||||||
# See: http://stackoverflow.com/a/15660652/2220173
|
|
||||||
set(Python_ADDITIONAL_VERSIONS ${GTSAM_PYTHON_VERSION})
|
|
||||||
# Then look for the the lib. If no version is specified when looking for PythonLibs it searches the default version.
|
|
||||||
# See: https://cmake.org/cmake/help/v3.1/module/FindPythonInterp.html
|
|
||||||
if(GTSAM_PYTHON_VERSION STREQUAL "Default")
|
|
||||||
find_package(PythonLibs)
|
|
||||||
else()
|
|
||||||
find_package(PythonLibs ${GTSAM_PYTHON_VERSION})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Find Boost Python
|
# Find Boost Python
|
||||||
find_package(Boost COMPONENTS python${BOOST_PYTHON_VERSION_SUFFIX})
|
find_package(Boost COMPONENTS python${BOOST_PYTHON_VERSION_SUFFIX})
|
||||||
|
|
||||||
# Build python module library and setup the module inside build
|
|
||||||
if(Boost_PYTHON${BOOST_PYTHON_VERSION_SUFFIX_UPPERCASE}_FOUND AND PYTHONLIBS_FOUND AND NUMPY_FOUND)
|
if(Boost_PYTHON${BOOST_PYTHON_VERSION_SUFFIX_UPPERCASE}_FOUND AND PYTHONLIBS_FOUND AND NUMPY_FOUND)
|
||||||
|
# Build library
|
||||||
include_directories(${NUMPY_INCLUDE_DIRS})
|
include_directories(${NUMPY_INCLUDE_DIRS})
|
||||||
|
|
||||||
include_directories(${PYTHON_INCLUDE_DIRS})
|
include_directories(${PYTHON_INCLUDE_DIRS})
|
||||||
include_directories(${Boost_INCLUDE_DIRS})
|
include_directories(${Boost_INCLUDE_DIRS})
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/gtsam/3rdparty/numpy_eigen/include/)
|
include_directories(${CMAKE_SOURCE_DIR}/gtsam/3rdparty/numpy_eigen/include/)
|
||||||
|
@ -59,24 +53,16 @@ if(Boost_PYTHON${BOOST_PYTHON_VERSION_SUFFIX_UPPERCASE}_FOUND AND PYTHONLIBS_FOU
|
||||||
# Build the python module library
|
# Build the python module library
|
||||||
add_subdirectory(handwritten)
|
add_subdirectory(handwritten)
|
||||||
|
|
||||||
# Copy all .py files that changes since last build
|
# Create and invoke setup.py, see https://bloerg.net/2012/11/10/cmake-and-distutils.html
|
||||||
file(GLOB_RECURSE GTSAM_PY_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.py")
|
set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in")
|
||||||
foreach(PY_SRC ${GTSAM_PY_SRCS})
|
set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
|
||||||
string(REPLACE "/" "_" PY_SRC_TARGET_SUFFIX ${PY_SRC}) # Replace "/" with "_"
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${PY_SRC}
|
|
||||||
DEPENDS ${PY_SRC}
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${PY_SRC} ${CMAKE_CURRENT_BINARY_DIR}/${PY_SRC}
|
|
||||||
COMMENT "Copying python/${PY_SRC}"
|
|
||||||
)
|
|
||||||
add_custom_target(copy_${PY_SRC_TARGET_SUFFIX} DEPENDS ${PY_SRC})
|
|
||||||
# Add dependency so the copy is made BEFORE building the python module
|
|
||||||
add_dependencies(gtsam_python copy_${PY_SRC_TARGET_SUFFIX})
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# Disable python module if we didn't find required libraries
|
configure_file(${SETUP_PY_IN} ${SETUP_PY})
|
||||||
|
|
||||||
|
# TODO(frank): possibly support a different prefix a la matlab wrapper
|
||||||
|
install(CODE "execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${PYTHON_EXECUTABLE} setup.py -v install --prefix ${CMAKE_INSTALL_PREFIX})")
|
||||||
else()
|
else()
|
||||||
|
# Disable python module if we didn't find required libraries
|
||||||
# message will print at end of main CMakeLists.txt
|
# message will print at end of main CMakeLists.txt
|
||||||
SET(GTSAM_PYTHON_WARNINGS "Python dependencies not found - Python module will not be built. Set GTSAM_BUILD_PYTHON to 'Off' to disable this warning. Details:")
|
SET(GTSAM_PYTHON_WARNINGS "Python dependencies not found - Python module will not be built. Set GTSAM_BUILD_PYTHON to 'Off' to disable this warning. Details:")
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# get subdirectories list
|
# get subdirectories list
|
||||||
subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
|
subdirlist(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
@ -16,14 +15,16 @@ set_target_properties(gtsam_python PROPERTIES
|
||||||
SKIP_BUILD_RPATH TRUE
|
SKIP_BUILD_RPATH TRUE
|
||||||
CLEAN_DIRECT_OUTPUT 1
|
CLEAN_DIRECT_OUTPUT 1
|
||||||
)
|
)
|
||||||
target_link_libraries(gtsam_python ${Boost_PYTHON${BOOST_PYTHON_VERSION_SUFFIX_UPPERCASE}_LIBRARY} ${PYTHON_LIBRARY} gtsam)
|
target_link_libraries(gtsam_python
|
||||||
|
${Boost_PYTHON${BOOST_PYTHON_VERSION_SUFFIX_UPPERCASE}_LIBRARY}
|
||||||
|
${PYTHON_LIBRARY} gtsam)
|
||||||
|
|
||||||
# Cause the library to be output in the correct directory.
|
# Cause the library to be output in the correct directory.
|
||||||
# TODO: Change below to work on different systems (currently works only with Linux)
|
# TODO: Change below to work on different systems (currently works only with Linux)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${CMAKE_BINARY_DIR}/python/gtsam/_libgtsam_python.so
|
OUTPUT ${CMAKE_BINARY_DIR}/python/gtsam/_libgtsam_python.so
|
||||||
DEPENDS gtsam_python
|
DEPENDS gtsam_python
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:gtsam_python> ${CMAKE_BINARY_DIR}/python/gtsam/_$<TARGET_FILE_NAME:gtsam_python>
|
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:gtsam_python> ${CMAKE_BINARY_DIR}/python/gtsam/_libgtsam_python.so
|
||||||
COMMENT "Copying extension module to python/gtsam/_libgtsam_python.so"
|
COMMENT "Copying extension module to python/gtsam/_libgtsam_python.so"
|
||||||
)
|
)
|
||||||
add_custom_target(copy_gtsam_python_module ALL DEPENDS ${CMAKE_BINARY_DIR}/python/gtsam/_libgtsam_python.so)
|
add_custom_target(copy_gtsam_python_module ALL DEPENDS ${CMAKE_BINARY_DIR}/python/gtsam/_libgtsam_python.so)
|
|
@ -1,15 +1,11 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
#http://docs.python.org/2/distutils/setupscript.html#setup-script
|
|
||||||
|
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
||||||
setup(name='gtsam',
|
setup(name='gtsam',
|
||||||
version='4.0.0',
|
version='${GTSAM_VERSION_STRING}',
|
||||||
description='GTSAM Python wrapper',
|
description='GTSAM Python wrapper',
|
||||||
license = "BSD",
|
license = "BSD",
|
||||||
author='Dellaert et. al',
|
author='Frank Dellaert et. al',
|
||||||
author_email='Andrew.Melim@gatech.edu',
|
author_email='frank.dellaert@gatech.edu',
|
||||||
maintainer_email='gtsam@lists.gatech.edu',
|
maintainer_email='gtsam@lists.gatech.edu',
|
||||||
url='https://collab.cc.gatech.edu/borg/gtsam',
|
url='https://collab.cc.gatech.edu/borg/gtsam',
|
||||||
packages=['gtsam', 'gtsam.examples', 'gtsam.utils'],
|
packages=['gtsam', 'gtsam.examples', 'gtsam.utils'],
|
Loading…
Reference in New Issue