Austin Schuh | 9049e20 | 2022-02-20 17:34:16 -0800 | [diff] [blame^] | 1 | .. _build_from_sources: |
| 2 | |
| 3 | |
| 4 | Build from sources |
| 5 | ================== |
| 6 | |
| 7 | Install GCC and CMake |
| 8 | ---------------------- |
| 9 | |
| 10 | The main compilation directives are specified using |
| 11 | |
| 12 | - `GCC compiler <https://gcc.gnu.org/>`_ to build the binaries |
| 13 | - `CMake <https://cmake.org/>`__ to create the Makefiles |
| 14 | |
| 15 | |
| 16 | Linux |
| 17 | ^^^^^ |
| 18 | Both :code:`gcc` and :code:`cmake` commands are already installed by default. |
| 19 | |
| 20 | Mac OS |
| 21 | ^^^^^^ |
| 22 | |
| 23 | Install Xcode and command line tools |
| 24 | """""""""""""""""""""""""""""""""""" |
| 25 | |
| 26 | #. Install the latest release of `Xcode <https://developer.apple.com/download/>`_. |
| 27 | |
| 28 | #. Install the command line tools by executing from the terminal |
| 29 | |
| 30 | .. code:: bash |
| 31 | |
| 32 | xcode-select --install |
| 33 | |
| 34 | Install CMake via Homebrew |
| 35 | """"""""""""""""""""""""""" |
| 36 | |
| 37 | #. Install `Homebrew <https://brew.sh/>`_ and update its packages to the latest version. |
| 38 | |
| 39 | #. Install cmake by executing |
| 40 | |
| 41 | .. code:: bash |
| 42 | |
| 43 | brew install cmake |
| 44 | |
| 45 | |
| 46 | Windows |
| 47 | ^^^^^^^ |
| 48 | |
| 49 | #. Install `TDM-GCC <http://tdm-gcc.tdragon.net/download>`_ 32bit or 64bit depending on your platform. |
| 50 | |
| 51 | #. Install the latest binaries of `CMake <https://cmake.org/download/#latest>`__. |
| 52 | |
| 53 | |
| 54 | Build the binaries |
| 55 | ------------------ |
| 56 | |
| 57 | Run the following commands from the terminal |
| 58 | |
| 59 | #. You first need to get the sources from one of these two options: |
| 60 | |
| 61 | * Download the compressed source file from the latest OSQP release `at GitHub <https://github.com/osqp/osqp/releases>`_. |
| 62 | |
| 63 | * Clone the repository |
| 64 | |
| 65 | .. code:: bash |
| 66 | |
| 67 | git clone --recursive https://github.com/osqp/osqp |
| 68 | |
| 69 | #. Create :code:`build` directory and change directory |
| 70 | |
| 71 | .. code:: bash |
| 72 | |
| 73 | cd osqp |
| 74 | mkdir build |
| 75 | cd build |
| 76 | |
| 77 | #. Create Makefiles |
| 78 | |
| 79 | - In Linux and Mac OS run |
| 80 | |
| 81 | .. code:: bash |
| 82 | |
| 83 | cmake -G "Unix Makefiles" .. |
| 84 | |
| 85 | - In Windows run |
| 86 | |
| 87 | .. code:: bash |
| 88 | |
| 89 | cmake -G "MinGW Makefiles" .. |
| 90 | |
| 91 | |
| 92 | #. Compile OSQP |
| 93 | |
| 94 | .. code:: bash |
| 95 | |
| 96 | cmake --build . |
| 97 | |
| 98 | |
| 99 | Thanks to CMake, it is possible to create projects for a wide variety of IDEs; see `here <https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html>`_ for more details. For example, to create a project for Visual Studio 14 2015, it is just necessary to run |
| 100 | |
| 101 | .. code:: bash |
| 102 | |
| 103 | cmake -G "Visual Studio 14 2015" .. |
| 104 | |
| 105 | |
| 106 | The compilation will generate the demo :code:`osqp_demo` and the unittests :code:`osqp_tester` executables. In the case of :code:`Unix` or :code:`MinGW` :code:`Makefiles` option they are located in the :code:`build/out/` directory. Run them to check that the compilation was correct. |
| 107 | |
| 108 | |
| 109 | Once the sources are built, the generated static :code:`build/out/libosqp.a` and shared :code:`build/out/libosqp.ext` libraries can be used to interface any C/C++ software to OSQP (see :ref:`install_osqp_libs` installation). |
| 110 | |
| 111 | .. _install_the_binaries: |
| 112 | |
| 113 | Install the binaries |
| 114 | -------------------- |
| 115 | |
| 116 | |
| 117 | |
| 118 | To install the generated libraries and headers to a system-wide location compatible with `GNU standards <http://www.gnu.org/prep/standards/html_node/Directory-Variables.html>`_ it is just necessary to run |
| 119 | |
| 120 | .. code:: bash |
| 121 | |
| 122 | cmake --build . --target install |
| 123 | |
| 124 | This code installs the libraries in :code:`libdir` and the headers into :code:`includedir/osqp`. For mode details see the defaults folders on the `GNU standards <http://www.gnu.org/prep/standards/html_node/Directory-Variables.html>`_ website. |
| 125 | To change the installation prefix, in the "Create Makefiles" step above, you need to specify the destination folder as :code:`cmake -DCMAKE_INSTALL_PREFIX:PATH=myfolder ..`. |
| 126 | |
| 127 | .. note:: This step requires write permissions in the destination |
| 128 | folders. You might be able to gain access using the |
| 129 | :code:`sudo` command. |
| 130 | |
| 131 | We provided also an uninstall routine to remove the copied files by running |
| 132 | |
| 133 | .. code:: bash |
| 134 | |
| 135 | cmake --build . --target uninstall |
| 136 | |
| 137 | Note that this corresponds to running :code:`make install` and :code:`make uninstall` on unix machines. |