Skip to content

Commit

Permalink
R compatibility
Browse files Browse the repository at this point in the history
goulart-paul committed Apr 9, 2018
1 parent 82f6d37 commit a9e6f99
Showing 4 changed files with 51 additions and 15 deletions.
53 changes: 41 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -223,7 +223,7 @@ if (MATLAB)
message( FATAL_ERROR "You need Matlab libraries to build the Matlab interface" )
endif (NOT Matlab_FOUND)

# Include directories for Python headers
# Include directories for Matlab headers
include_directories(${Matlab_INCLUDE_DIRS})

# Pass MATLAB flag to C compiler
@@ -237,6 +237,35 @@ if (MATLAB)

endif (MATLAB)

# if we are building the R interface, let's look for R
# and set some options
# -----------------------------------------------------------------
if (R_LANG)

message(STATUS "We are building the R interface")

# Look for R libraries
find_package(R)

if (NOT R_FOUND)
message( FATAL_ERROR "You need R libraries to build the R interface" )
endif (NOT R_FOUND)

message(STATUS "Found R includes at: " ${R_INCLUDE_DIRS})

# Include directories for R headers
include_directories(${R_INCLUDE_DIRS})

# Pass R_LANG flag to C compiler
add_definitions(-DR_LANG)

if (UNITTESTS)
# Disable unittests
message(STATUS "Disabling UNITTESTS because we are building the R interface")
set(UNITTESTS OFF)
endif (UNITTESTS)

endif (R_LANG)


# Create Static Library
@@ -252,7 +281,7 @@ add_library (osqpstatic STATIC ${osqp_src} ${osqp_headers} ${linsys_solvers})
target_include_directories(osqpstatic PRIVATE ${linsys_solvers_includes})

# Declare include directories for the cmake exported target
target_include_directories(osqpstatic
target_include_directories(osqpstatic
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/osqp>")

@@ -267,7 +296,7 @@ install(TARGETS osqpstatic
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")


# Install Headers
# ----------------------------------------------

@@ -283,23 +312,23 @@ if (PYTHON)
target_link_libraries (osqpstatic ${PYTHON_LIBRARIES})
endif (PYTHON)

# If we are building Python or Matlab interface:
# If we are building Python/Matlab/R interface:
# - do not build shared library
# - do not build demo
if (NOT PYTHON AND NOT MATLAB)
if (NOT PYTHON AND NOT MATLAB AND NOT R_LANG)
# Create osqp shared library
# NB: Add all the linear system solvers here
add_library (osqp SHARED ${osqp_src} ${osqp_headers} ${linsys_solvers})

# Include directories for linear system solvers
target_include_directories(osqp PRIVATE ${linsys_solvers_includes})

# Declare include directories for the cmake exported target
target_include_directories(osqp
target_include_directories(osqp
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/osqp>")

# Install osqp shared library
# Install osqp shared library
install(TARGETS osqp
EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
@@ -310,9 +339,9 @@ if (NOT PYTHON AND NOT MATLAB)
add_executable (osqp_demo ${PROJECT_SOURCE_DIR}/examples/osqp_demo.c)
target_link_libraries (osqp_demo osqpstatic)

endif (NOT PYTHON AND NOT MATLAB)
endif (NOT PYTHON AND NOT MATLAB AND NOT R_LANG)

# Create CMake packages for the build directory
# Create CMake packages for the build directory
# ----------------------------------------------
include(CMakePackageConfigHelpers)

@@ -325,12 +354,12 @@ if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/osqp-config.cmake)
endif()


# Create CMake packages for the install directory
# Create CMake packages for the install directory
# ----------------------------------------------

set(ConfigPackageLocation lib/cmake/osqp)

install(EXPORT ${PROJECT_NAME}
install(EXPORT ${PROJECT_NAME}
FILE osqp-targets.cmake
NAMESPACE osqp::
DESTINATION ${ConfigPackageLocation})
6 changes: 5 additions & 1 deletion configure/glob_opts.h.in
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ extern "C" {
// We do not need memory allocation functions if EMBEDDED is enabled
# ifndef EMBEDDED

/* define custom printfs and memory allocation (e.g. matlab or python) */
/* define custom printfs and memory allocation (e.g. matlab/python) */
# ifdef MATLAB
# include "mex.h"
static void* c_calloc(size_t num, size_t size) {
@@ -96,6 +96,7 @@ static void* c_calloc(size_t num, size_t size) {
# define c_calloc calloc
# define c_free free
# define c_realloc realloc

# endif /* ifdef MATLAB */

# include <stdlib.h>
@@ -197,6 +198,9 @@ typedef float c_float; /* for numerical values */
# elif defined PYTHON
# include <Python.h>
# define c_print PySys_WriteStdout
# elif defined R_LANG
# include <R_ext/Print.h>
# define c_print Rprintf
# else /* ifdef MATLAB */
# define c_print printf
# endif /* ifdef MATLAB */
3 changes: 2 additions & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
@@ -17,4 +17,5 @@ help:
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

4 changes: 3 additions & 1 deletion lin_sys/direct/suitesparse/SuiteSparse_config.h
Original file line number Diff line number Diff line change
@@ -79,8 +79,10 @@ struct SuiteSparse_config_struct
void *(*malloc_func) (size_t) ; /* pointer to malloc */
void *(*realloc_func) (void *, size_t) ; /* pointer to realloc */
void (*free_func) (void *) ; /* pointer to free */
#ifdef PYTHON
#if defined PYTHON
void (*printf_func) (const char *, ...) ; /* pointer to printf (in Python it returns void)*/
#elif defined R_LANG
void (*printf_func) (const char *, ...) ; /* pointer to printf (in R it returns void)*/
#else
int (*printf_func) (const char *, ...) ; /* pointer to printf */
#endif

0 comments on commit a9e6f99

Please sign in to comment.