updates to Cmake to use the new wrap package
parent
4945642481
commit
3a80b38a9a
|
@ -62,6 +62,11 @@ add_subdirectory(CppUnitLite)
|
||||||
|
|
||||||
# This is the new wrapper
|
# This is the new wrapper
|
||||||
if(GTSAM_BUILD_PYTHON)
|
if(GTSAM_BUILD_PYTHON)
|
||||||
|
# Need to set this for the wrap package so we don't use the default value.
|
||||||
|
set(WRAP_PYTHON_VERSION ${GTSAM_PYTHON_VERSION}
|
||||||
|
CACHE STRING "The Python version to use for wrapping")
|
||||||
|
|
||||||
|
add_subdirectory(wrap)
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/wrap/cmake")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/wrap/cmake")
|
||||||
add_subdirectory(python)
|
add_subdirectory(python)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -240,12 +240,16 @@ function(wrap_library_internal interfaceHeader linkLibraries extraIncludeDirs ex
|
||||||
|
|
||||||
set(_ignore gtsam::Point2
|
set(_ignore gtsam::Point2
|
||||||
gtsam::Point3)
|
gtsam::Point3)
|
||||||
add_custom_command(
|
|
||||||
|
# set the matlab wrapping script variable
|
||||||
|
set(MATLAB_WRAP_SCRIPT "${GTSAM_SOURCE_DIR}/wrap/scripts/matlab_wrap.py")
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
OUTPUT ${generated_cpp_file}
|
OUTPUT ${generated_cpp_file}
|
||||||
DEPENDS ${interfaceHeader} ${module_library_target} ${otherLibraryTargets} ${otherSourcesAndObjects}
|
DEPENDS ${interfaceHeader} ${module_library_target} ${otherLibraryTargets} ${otherSourcesAndObjects}
|
||||||
COMMAND
|
COMMAND
|
||||||
${PYTHON_EXECUTABLE}
|
${PYTHON_EXECUTABLE}
|
||||||
${CMAKE_SOURCE_DIR}/wrap/matlab_wrapper.py
|
${MATLAB_WRAP_SCRIPT}
|
||||||
--src ${interfaceHeader}
|
--src ${interfaceHeader}
|
||||||
--module_name ${moduleName}
|
--module_name ${moduleName}
|
||||||
--out ${generated_files_path}
|
--out ${generated_files_path}
|
||||||
|
|
|
@ -1,22 +1,48 @@
|
||||||
# Set Python version if either Python or MATLAB wrapper is requested.
|
# Set Python version if either Python or MATLAB wrapper is requested.
|
||||||
if(GTSAM_BUILD_PYTHON OR GTSAM_INSTALL_MATLAB_TOOLBOX)
|
if(GTSAM_BUILD_PYTHON OR GTSAM_INSTALL_MATLAB_TOOLBOX)
|
||||||
if(${GTSAM_PYTHON_VERSION} STREQUAL "Default")
|
if(${GTSAM_PYTHON_VERSION} STREQUAL "Default")
|
||||||
# Get info about the Python3 interpreter
|
|
||||||
# https://cmake.org/cmake/help/latest/module/FindPython3.html#module:FindPython3
|
|
||||||
find_package(Python3 COMPONENTS Interpreter Development)
|
|
||||||
|
|
||||||
if(NOT ${Python3_FOUND})
|
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
|
||||||
message(FATAL_ERROR "Cannot find Python3 interpreter. Please install Python >= 3.6.")
|
# Use older version of cmake's find_python
|
||||||
endif()
|
find_package(PythonInterp)
|
||||||
|
|
||||||
|
if(NOT ${PYTHONINTERP_FOUND})
|
||||||
|
message(
|
||||||
|
FATAL_ERROR
|
||||||
|
"Cannot find Python interpreter. Please install Python >= 3.6.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(PythonLibs ${PYTHON_VERSION_STRING})
|
||||||
|
|
||||||
|
set(Python_VERSION_MAJOR ${PYTHON_VERSION_MAJOR})
|
||||||
|
set(Python_VERSION_MINOR ${PYTHON_VERSION_MINOR})
|
||||||
|
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
|
||||||
|
|
||||||
|
else()
|
||||||
|
# Get info about the Python3 interpreter
|
||||||
|
# https://cmake.org/cmake/help/latest/module/FindPython3.html#module:FindPython3
|
||||||
|
find_package(Python3 COMPONENTS Interpreter Development)
|
||||||
|
|
||||||
|
if(NOT ${Python3_FOUND})
|
||||||
|
message(
|
||||||
|
FATAL_ERROR
|
||||||
|
"Cannot find Python3 interpreter. Please install Python >= 3.6.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(Python_VERSION_MAJOR ${Python3_VERSION_MAJOR})
|
||||||
|
set(Python_VERSION_MINOR ${Python3_VERSION_MINOR})
|
||||||
|
|
||||||
set(GTSAM_PYTHON_VERSION "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}"
|
|
||||||
CACHE
|
|
||||||
STRING
|
|
||||||
"The version of Python to build the wrappers against."
|
|
||||||
FORCE)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(GTSAM_PYTHON_VERSION
|
||||||
|
"${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}"
|
||||||
|
CACHE STRING "The version of Python to build the wrappers against."
|
||||||
|
FORCE)
|
||||||
|
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Check for build of Unstable modules
|
||||||
if(GTSAM_BUILD_PYTHON)
|
if(GTSAM_BUILD_PYTHON)
|
||||||
if(GTSAM_UNSTABLE_BUILD_PYTHON)
|
if(GTSAM_UNSTABLE_BUILD_PYTHON)
|
||||||
if (NOT GTSAM_BUILD_UNSTABLE)
|
if (NOT GTSAM_BUILD_UNSTABLE)
|
||||||
|
|
|
@ -4,20 +4,26 @@ if (NOT GTSAM_BUILD_PYTHON)
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Common directory for storing data/datasets stored with the package.
|
|
||||||
# This will store the data in the Python site package directly.
|
|
||||||
set(GTSAM_PYTHON_DATASET_DIR "./gtsam/Data")
|
|
||||||
|
|
||||||
# Generate setup.py.
|
# Generate setup.py.
|
||||||
file(READ "${PROJECT_SOURCE_DIR}/README.md" README_CONTENTS)
|
file(READ "${PROJECT_SOURCE_DIR}/README.md" README_CONTENTS)
|
||||||
configure_file(${PROJECT_SOURCE_DIR}/python/setup.py.in
|
configure_file(${PROJECT_SOURCE_DIR}/python/setup.py.in
|
||||||
${GTSAM_PYTHON_BUILD_DIRECTORY}/setup.py)
|
${GTSAM_PYTHON_BUILD_DIRECTORY}/setup.py)
|
||||||
|
|
||||||
set(WRAP_USE_CUSTOM_PYTHON_LIBRARY ${GTSAM_USE_CUSTOM_PYTHON_LIBRARY})
|
# Supply MANIFEST.in for older versions of Python
|
||||||
set(WRAP_PYTHON_VERSION ${GTSAM_PYTHON_VERSION})
|
file(COPY ${PROJECT_SOURCE_DIR}/python/MANIFEST.in
|
||||||
|
DESTINATION ${GTSAM_PYTHON_BUILD_DIRECTORY})
|
||||||
|
|
||||||
include(PybindWrap)
|
include(PybindWrap)
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
## Load the necessary files to compile the wrapper
|
||||||
|
|
||||||
|
# Load the pybind11 code
|
||||||
|
add_subdirectory(${PROJECT_SOURCE_DIR}/wrap/pybind11 pybind11)
|
||||||
|
# Set the wrapping script variable
|
||||||
|
set(PYBIND_WRAP_SCRIPT "${PROJECT_SOURCE_DIR}/wrap/scripts/pybind_wrap.py")
|
||||||
|
############################################################
|
||||||
|
|
||||||
add_custom_target(gtsam_header DEPENDS "${PROJECT_SOURCE_DIR}/gtsam/gtsam.i")
|
add_custom_target(gtsam_header DEPENDS "${PROJECT_SOURCE_DIR}/gtsam/gtsam.i")
|
||||||
add_custom_target(gtsam_unstable_header DEPENDS "${PROJECT_SOURCE_DIR}/gtsam_unstable/gtsam_unstable.i")
|
add_custom_target(gtsam_unstable_header DEPENDS "${PROJECT_SOURCE_DIR}/gtsam_unstable/gtsam_unstable.i")
|
||||||
|
|
||||||
|
@ -67,55 +73,68 @@ set(GTSAM_MODULE_PATH ${GTSAM_PYTHON_BUILD_DIRECTORY}/gtsam)
|
||||||
create_symlinks("${CMAKE_CURRENT_SOURCE_DIR}/gtsam"
|
create_symlinks("${CMAKE_CURRENT_SOURCE_DIR}/gtsam"
|
||||||
"${GTSAM_MODULE_PATH}")
|
"${GTSAM_MODULE_PATH}")
|
||||||
|
|
||||||
|
# Common directory for data/datasets stored with the package.
|
||||||
|
# This will store the data in the Python site package directly.
|
||||||
|
file(COPY "${GTSAM_SOURCE_DIR}/examples/Data" DESTINATION "${GTSAM_MODULE_PATH}")
|
||||||
|
|
||||||
|
# Add gtsam as a dependency to the install target
|
||||||
|
set(GTSAM_PYTHON_DEPENDENCIES gtsam_py)
|
||||||
|
|
||||||
|
|
||||||
if(GTSAM_UNSTABLE_BUILD_PYTHON)
|
if(GTSAM_UNSTABLE_BUILD_PYTHON)
|
||||||
set(ignore
|
set(ignore
|
||||||
gtsam::Point2
|
gtsam::Point2
|
||||||
gtsam::Point3
|
gtsam::Point3
|
||||||
gtsam::LieVector
|
gtsam::LieVector
|
||||||
gtsam::LieMatrix
|
gtsam::LieMatrix
|
||||||
gtsam::ISAM2ThresholdMapValue
|
gtsam::ISAM2ThresholdMapValue
|
||||||
gtsam::FactorIndices
|
gtsam::FactorIndices
|
||||||
gtsam::FactorIndexSet
|
gtsam::FactorIndexSet
|
||||||
gtsam::BetweenFactorPose3s
|
gtsam::BetweenFactorPose3s
|
||||||
gtsam::Point2Vector
|
gtsam::Point2Vector
|
||||||
gtsam::Pose3Vector
|
gtsam::Pose3Vector
|
||||||
gtsam::KeyVector
|
gtsam::KeyVector
|
||||||
gtsam::FixedLagSmootherKeyTimestampMapValue
|
gtsam::FixedLagSmootherKeyTimestampMapValue
|
||||||
gtsam::BinaryMeasurementsUnit3
|
gtsam::BinaryMeasurementsUnit3
|
||||||
gtsam::CameraSetCal3_S2
|
gtsam::CameraSetCal3_S2
|
||||||
gtsam::CameraSetCal3Bundler
|
gtsam::CameraSetCal3Bundler
|
||||||
gtsam::KeyPairDoubleMap)
|
gtsam::KeyPairDoubleMap)
|
||||||
|
|
||||||
pybind_wrap(gtsam_unstable_py # target
|
pybind_wrap(gtsam_unstable_py # target
|
||||||
${PROJECT_SOURCE_DIR}/gtsam_unstable/gtsam_unstable.i # interface_header
|
${PROJECT_SOURCE_DIR}/gtsam_unstable/gtsam_unstable.i # interface_header
|
||||||
"gtsam_unstable.cpp" # generated_cpp
|
"gtsam_unstable.cpp" # generated_cpp
|
||||||
"gtsam_unstable" # module_name
|
"gtsam_unstable" # module_name
|
||||||
"gtsam" # top_namespace
|
"gtsam" # top_namespace
|
||||||
"${ignore}" # ignore_classes
|
"${ignore}" # ignore_classes
|
||||||
${PROJECT_SOURCE_DIR}/python/gtsam_unstable/gtsam_unstable.tpl
|
${PROJECT_SOURCE_DIR}/python/gtsam_unstable/gtsam_unstable.tpl
|
||||||
gtsam_unstable # libs
|
gtsam_unstable # libs
|
||||||
"gtsam_unstable;gtsam_unstable_header" # dependencies
|
"gtsam_unstable;gtsam_unstable_header" # dependencies
|
||||||
ON # use_boost
|
ON # use_boost
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(gtsam_unstable_py PROPERTIES
|
set_target_properties(gtsam_unstable_py PROPERTIES
|
||||||
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
|
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
|
||||||
INSTALL_RPATH_USE_LINK_PATH TRUE
|
INSTALL_RPATH_USE_LINK_PATH TRUE
|
||||||
OUTPUT_NAME "gtsam_unstable"
|
OUTPUT_NAME "gtsam_unstable"
|
||||||
LIBRARY_OUTPUT_DIRECTORY "${GTSAM_PYTHON_BUILD_DIRECTORY}/gtsam_unstable"
|
LIBRARY_OUTPUT_DIRECTORY "${GTSAM_PYTHON_BUILD_DIRECTORY}/gtsam_unstable"
|
||||||
DEBUG_POSTFIX "" # Otherwise you will have a wrong name
|
DEBUG_POSTFIX "" # Otherwise you will have a wrong name
|
||||||
RELWITHDEBINFO_POSTFIX "" # Otherwise you will have a wrong name
|
RELWITHDEBINFO_POSTFIX "" # Otherwise you will have a wrong name
|
||||||
)
|
)
|
||||||
|
|
||||||
set(GTSAM_UNSTABLE_MODULE_PATH ${GTSAM_PYTHON_BUILD_DIRECTORY}/gtsam_unstable)
|
set(GTSAM_UNSTABLE_MODULE_PATH ${GTSAM_PYTHON_BUILD_DIRECTORY}/gtsam_unstable)
|
||||||
|
|
||||||
|
# Symlink all tests .py files to build folder.
|
||||||
|
create_symlinks("${CMAKE_CURRENT_SOURCE_DIR}/gtsam_unstable"
|
||||||
|
"${GTSAM_UNSTABLE_MODULE_PATH}")
|
||||||
|
|
||||||
|
# Add gtsam_unstable to the install target
|
||||||
|
list(APPEND GTSAM_PYTHON_DEPENDENCIES gtsam_unstable_py)
|
||||||
|
|
||||||
# Symlink all tests .py files to build folder.
|
|
||||||
create_symlinks("${CMAKE_CURRENT_SOURCE_DIR}/gtsam_unstable"
|
|
||||||
"${GTSAM_UNSTABLE_MODULE_PATH}")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Add custom target so we can install with `make python-install`
|
||||||
set(GTSAM_PYTHON_INSTALL_TARGET python-install)
|
set(GTSAM_PYTHON_INSTALL_TARGET python-install)
|
||||||
add_custom_target(${GTSAM_PYTHON_INSTALL_TARGET}
|
add_custom_target(${GTSAM_PYTHON_INSTALL_TARGET}
|
||||||
COMMAND ${PYTHON_EXECUTABLE} ${GTSAM_PYTHON_BUILD_DIRECTORY}/setup.py install
|
COMMAND ${PYTHON_EXECUTABLE} ${GTSAM_PYTHON_BUILD_DIRECTORY}/setup.py install
|
||||||
DEPENDS gtsam_py gtsam_unstable_py
|
DEPENDS ${GTSAM_PYTHON_DEPENDENCIES}
|
||||||
WORKING_DIRECTORY ${GTSAM_PYTHON_BUILD_DIRECTORY})
|
WORKING_DIRECTORY ${GTSAM_PYTHON_BUILD_DIRECTORY})
|
||||||
|
|
Loading…
Reference in New Issue