Squashed 'third_party/osqp/' content from commit 33454b3e23

Change-Id: I056df0582ca06664e86554c341a94c47ab932001
git-subtree-dir: third_party/osqp
git-subtree-split: 33454b3e236f1f44193bfbbb6b8c8e71f8f04e9a
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/configure/cmake/FindPythonModule.cmake b/configure/cmake/FindPythonModule.cmake
new file mode 100644
index 0000000..f890d4f
--- /dev/null
+++ b/configure/cmake/FindPythonModule.cmake
@@ -0,0 +1,94 @@
+# Find python module and version
+#
+# It sets the variables (given module called MODULE)
+# unless MODULE is __FUTURE__. In that case
+# it only checks if it has been found.
+#
+# MODULE_FOUND               - has the module been found?
+# MODULE_VERSION             - module version as a string
+# MODULE_VERSION_MAJOR       - major version number
+# MODULE_VERSION_MINOR       - minor version number
+# MODULE_VERSION_PATCH       - patch version number
+# MODULE_VERSION_DECIMAL     - e.g. version 1.6.1 is 10601
+#
+
+
+function(find_python_module module)
+    # Write module in upper and lower case
+	string(TOUPPER ${module} module_upper)
+	string(TOLOWER ${module} module_lower)
+
+    unset(${module_upper}_VERSION)
+    #
+    # if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED")
+    #     set(${module_upper}_FIND_REQUIRED TRUE)
+    # endif()
+
+    if(PYTHONINTERP_FOUND)
+        if (NOT ${module} STREQUAL "__future__")
+            execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
+              "import ${module_lower} as n; print(n.__version__);"
+              RESULT_VARIABLE __result
+              OUTPUT_VARIABLE __output
+              ERROR_QUIET
+              OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+              if(__result MATCHES 0)
+                string(REGEX REPLACE ";" "\\\\;" __values ${__output})
+                string(REGEX REPLACE "\r?\n" ";"    __values ${__values})
+                list(GET __values 0 ${module_upper}_VERSION)
+
+                string(REGEX MATCH "^([0-9])+\\.([0-9])+\\.([0-9])+" __ver_check "${${module_upper}_VERSION}")
+
+                if(NOT "${__ver_check}" STREQUAL "")
+                  set(${module_upper}_VERSION_MAJOR ${CMAKE_MATCH_1})
+                  set(${module_upper}_VERSION_MINOR ${CMAKE_MATCH_2})
+                  set(${module_upper}_VERSION_PATCH ${CMAKE_MATCH_3})
+                  math(EXPR ${module_upper}_VERSION_DECIMAL
+                    "(${CMAKE_MATCH_1} * 10000) + (${CMAKE_MATCH_2} * 100) + ${CMAKE_MATCH_3}")
+                else()
+                 unset(${module_upper}_VERSION)
+                 message(STATUS "Requested ${module_lower} version, but got instead:\n${__output}\n")
+                endif()
+
+                find_package_handle_standard_args(${module_upper}
+                    FOUND_VAR ${module_upper}_FOUND
+                    REQUIRED_VARS ${module_upper}_VERSION
+                    VERSION_VAR  ${module_upper}_VERSION)
+
+              endif()
+        else()
+            execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
+              "import ${module_lower} as n"
+              RESULT_VARIABLE __result
+              OUTPUT_VARIABLE __output
+              ERROR_QUIET
+              OUTPUT_STRIP_TRAILING_WHITESPACE)
+              if(NOT __result)
+                  set(${module_upper}_FOUND ON)
+              endif()
+              message(STATUS "Found Python __FUTURE__")
+        endif()
+
+
+    else()
+        message(STATUS "Python interpreter not found. To find ${module} you need the Python interpreter.")
+    endif()
+
+
+    # Set variables in parent scope
+    if(${module_upper}_FOUND)
+        set(${module_upper}_FOUND ON PARENT_SCOPE)
+        if (NOT ${module} STREQUAL "__future__")
+            set(${module_upper}_VERSION ${${module_upper}_VERSION} PARENT_SCOPE)
+            set(${module_upper}_VERSION_MAJOR ${${module_upper}_VERSION_MAJOR} PARENT_SCOPE)
+            set(${module_upper}_VERSION_MINOR ${${module_upper}_VERSION_MINOR} PARENT_SCOPE)
+            set(${module_upper}_VERSION_PATCH ${${module_upper}_VERSION_PATCH} PARENT_SCOPE)
+            set(${module_upper}_VERSION_DECIMAL ${${module_upper}_VERSION_DECIMAL} PARENT_SCOPE)
+        endif()
+    endif()
+
+    # Clear variables
+    osqp_clear_vars(__result __output __values __ver_check)
+
+endfunction(find_python_module)
diff --git a/configure/cmake/FindR.cmake b/configure/cmake/FindR.cmake
new file mode 100644
index 0000000..5a39077
--- /dev/null
+++ b/configure/cmake/FindR.cmake
@@ -0,0 +1,34 @@
+# CMake module to find R
+# - Try to find R.  If found, defines:
+#
+#  R_FOUND        - system has R
+#  R_EXEC         - the system R command
+#  R_ROOT_DIR     - the R root directory
+#  R_INCLUDE_DIRS - the R include directories
+
+set(TEMP_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE})
+set(CMAKE_FIND_APPBUNDLE "NEVER")
+find_program(R_EXEC NAMES R R.exe)
+set(CMAKE_FIND_APPBUNDLE ${TEMP_CMAKE_FIND_APPBUNDLE})
+
+#---Find includes and libraries if R exists
+if(R_EXEC)
+
+  set(R_FOUND TRUE)
+
+  if((CMAKE_HOST_SOLARIS) AND (DEFINED ENV{R_HOME}))
+      message(STATUS "Unsetting R_HOME on Solaris.")
+      unset(ENV{R_HOME})
+  endif()
+
+  execute_process(WORKING_DIRECTORY .
+  COMMAND ${R_EXEC} RHOME
+  OUTPUT_VARIABLE R_ROOT_DIR
+  OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+  find_path(R_INCLUDE_DIRS R.h
+            PATHS /usr/local/lib /usr/local/lib64 /usr/share /usr/include ${R_ROOT_DIR} PATH_SUFFIXES include R R/include)
+
+endif()
+
+mark_as_advanced(R_FOUND R_EXEC R_ROOT_DIR R_INCLUDE_DIRS)
diff --git a/configure/cmake/Utils.cmake b/configure/cmake/Utils.cmake
new file mode 100644
index 0000000..ac4cc71
--- /dev/null
+++ b/configure/cmake/Utils.cmake
@@ -0,0 +1,8 @@
+# Clears variables from list
+# Usage:
+#   osqp_clear_vars(<variables_list>)
+macro(osqp_clear_vars)
+  foreach(_var ${ARGN})
+    unset(${_var})
+  endforeach()
+endmacro()
diff --git a/configure/cmake/cmake_uninstall.cmake.in b/configure/cmake/cmake_uninstall.cmake.in
new file mode 100644
index 0000000..4457d1b
--- /dev/null
+++ b/configure/cmake/cmake_uninstall.cmake.in
@@ -0,0 +1,21 @@
+if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+  message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
+endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
+
+file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
+string(REGEX REPLACE "\n" ";" files "${files}")
+foreach(file ${files})
+  message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
+  if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    exec_program(
+      "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
+      OUTPUT_VARIABLE rm_out
+      RETURN_VALUE rm_retval
+      )
+    if(NOT "${rm_retval}" STREQUAL 0)
+      message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
+    endif(NOT "${rm_retval}" STREQUAL 0)
+  else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+    message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
+  endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
+endforeach(file)
\ No newline at end of file