diff --git a/CMakeLists.txt b/CMakeLists.txt index 21c08ba..4d7c019 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,11 @@ set(SRCS src/Utils.cpp) add_library(${PROJECT_NAME} ${SRCS}) +set(qpOASES_PYTHON_SRC + interfaces/python/qpoases.pxd + interfaces/python/qpoases.pyx +) + # # building example applications # @@ -73,3 +78,28 @@ install(DIRECTORY include/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.hpp" PATTERN ".svn" EXCLUDE) + +# the files listed above are present when qpoases_svn (i.e. getting source files) is completed +add_custom_command(OUTPUT ${qpOASES_SRC} ${qpOASES_PYTHON_SRC} + DEPENDS ${PROJECT_NAME}) + +# Custom build Python wrappers +add_custom_target(qpOASES_Python ALL + COMMAND python setup.py build_ext --include-dirs include ${INCLUDE_DIRECTORIES} --build-lib ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION} --build-temp ${CMAKE_CURRENT_BINARY_DIR} --sources ${qpOASES_PYTHON_SRC} ${SRCS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${PROJECT_NAME} + COMMENT "Building Python wrappers." +) + +# Tell CMake about the build output +set(qpOASES_PYTHON_LIB + ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION}/qpoases.so +) + +add_custom_command(OUTPUT ${qpOASES_PYTHON_LIB} + DEPENDS qpOASES_Python) + +# Install +install(FILES ${qpOASES_PYTHON_LIB} + DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION} +) \ No newline at end of file diff --git a/interfaces/python/qpoases.pxd b/interfaces/python/qpoases.pxd index 89ec661..25b5b58 100644 --- a/interfaces/python/qpoases.pxd +++ b/interfaces/python/qpoases.pxd @@ -436,9 +436,9 @@ cdef extern from "qpOASES/extras/SolutionAnalysis.hpp" namespace "qpOASES": SolutionAnalysis(const SolutionAnalysis&) # ~SolutionAnalysis() # SolutionAnalysis& operator=(const SolutionAnalysis&) - returnValue getKktViolation(const QProblem*, const real_t*, const real_t*, const real_t*) - returnValue getKktViolation(const QProblemB*, const real_t*, const real_t*, const real_t*) - returnValue getKktViolation(const SQProblem*, const real_t*, const real_t*, const real_t*) + real_t getKktViolation(const QProblem*, const real_t*, const real_t*, const real_t*) + real_t getKktViolation(const QProblemB*, const real_t*, const real_t*, const real_t*) + real_t getKktViolation(const SQProblem*, const real_t*, const real_t*, const real_t*) returnValue getVarianceCovariance(QProblem*, real_t*, real_t*) returnValue getVarianceCovariance(QProblemB*, real_t*, real_t*) returnValue getVarianceCovariance(SQProblem*, real_t*, real_t*) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..51ec9c0 --- /dev/null +++ b/setup.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +"""qpOASES python distutils setup script.""" + +# +# This file is part of qpOASES. +# +# qpOASES -- An Implementation of the Online Active Set Strategy. +# Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka, +# Christian Kirches et al. All rights reserved. +# +# qpOASES is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# qpOASES is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with qpOASES; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# + +# +# Filename: setup.py +# Author: Sebastian F. Walter, Manuel Kudruss (thanks to Felix Lenders) +# Version: 3.2 +# Date: 2013-2017 +# + +import sys +import numpy as np + +from distutils.core import setup +from distutils.extension import Extension +from Cython.Distutils import build_ext +from Cython.Build import cythonize + +# HACK for passing source files via command line +sources_index = sys.argv.index('--sources') +sources = sys.argv[(sources_index + 1):] +sys.argv = sys.argv[:sources_index] + +extra_params = { + 'include_dirs': [ + np.get_include() + ], + 'extra_compile_args': [ + "-O2", + "-Wno-unused-variable", + "-Wall", + "-pedantic", + "-Wshadow", + "-Wfloat-equal", + "-O3", + "-Wconversion", + "-Wsign-conversion", + "-finline-functions", + "-fPIC", + "-DLINUX", + "-D__USE_LONG_INTEGERS__", + "-D__USE_LONG_FINTS__", + "-D__NO_COPYRIGHT__", + ], + 'extra_link_args': ["-Wl,--as-needed"], + 'language': 'c++' +} + +ext_modules = [ + Extension("qpoases", sources, **extra_params), +] + +setup( + name='qpOASES interface', + cmdclass={'build_ext': build_ext}, + ext_modules=cythonize(ext_modules), +)