| 1 |
# How to build from source |
| 2 |
|
| 3 |
## Requirements |
| 4 |
|
| 5 |
### Common requirements |
| 6 |
|
| 7 |
In order to build libssh, you need to install several components: |
| 8 |
|
| 9 |
- A C compiler |
| 10 |
- [CMake](https://www.cmake.org) >= 3.12.0 |
| 11 |
- [libz](https://www.zlib.net) >= 1.2 |
| 12 |
- [openssl](https://www.openssl.org) >= 1.1.1 |
| 13 |
or |
| 14 |
- [gcrypt](https://www.gnu.org/directory/Security/libgcrypt.html) >= 1.5 |
| 15 |
or |
| 16 |
- [Mbed TLS](https://www.trustedfirmware.org/projects/mbed-tls/) |
| 17 |
|
| 18 |
optional: |
| 19 |
- [cmocka](https://cmocka.org/) >= 1.1.0 |
| 20 |
- [socket_wrapper](https://cwrap.org/) >= 1.1.5 |
| 21 |
- [nss_wrapper](https://cwrap.org/) >= 1.1.2 |
| 22 |
- [uid_wrapper](https://cwrap.org/) >= 1.2.0 |
| 23 |
- [pam_wrapper](https://cwrap.org/) >= 1.0.1 |
| 24 |
- [priv_wrapper](https://cwrap.org/) >= 1.0.0 |
| 25 |
|
| 26 |
Note that these version numbers are version we know works correctly. If you |
| 27 |
build and run libssh successfully with an older version, please let us know. |
| 28 |
|
| 29 |
For Windows use vcpkg: |
| 30 |
|
| 31 |
https://github.com/Microsoft/vcpkg |
| 32 |
|
| 33 |
which you can use to install openssl and zlib. libssh itself is also part of |
| 34 |
vcpkg! |
| 35 |
|
| 36 |
## Building |
| 37 |
First, you need to configure the compilation, using CMake. Go inside the |
| 38 |
`build` dir. Create it if it doesn't exist. |
| 39 |
|
| 40 |
GNU/Linux, MacOS X, MSYS/MinGW: |
| 41 |
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug .. |
| 42 |
make |
| 43 |
|
| 44 |
On Windows you should choose a makefile generator with -G or use |
| 45 |
|
| 46 |
cmake-gui.exe .. |
| 47 |
|
| 48 |
To enable building tests use -DUNIT_TESTING=ON. For this, the |
| 49 |
[cmocka](https://cmocka.org) dependency is required. |
| 50 |
|
| 51 |
To enable additional client tests against a local OpenSSH server, add the |
| 52 |
compile option -DCLIENT_TESTING=ON. These tests require an OpenSSH |
| 53 |
server package and some wrapper libraries (see optional requirements) to |
| 54 |
be installed. |
| 55 |
|
| 56 |
If you're interested in server testing, then a OpenSSH client should be |
| 57 |
installed on the system and if possible also dropbear. Once that is done |
| 58 |
enable server support with -DWITH_SERVER=ON and enable testing of it with |
| 59 |
-DSERVER_TESTING=ON. |
| 60 |
|
| 61 |
## Testing build |
| 62 |
|
| 63 |
make test |
| 64 |
|
| 65 |
### CMake standard options |
| 66 |
Here is a list of the most interesting options provided out of the box by |
| 67 |
CMake. |
| 68 |
|
| 69 |
- CMAKE_BUILD_TYPE: The type of build (can be Debug Release MinSizeRel |
| 70 |
RelWithDebInfo) |
| 71 |
- CMAKE_INSTALL_PREFIX: The prefix to use when running make install (Default |
| 72 |
to /usr/local on GNU/Linux and MacOS X) |
| 73 |
- CMAKE_C_COMPILER: The path to the C compiler |
| 74 |
- CMAKE_CXX_COMPILER: The path to the C++ compiler |
| 75 |
|
| 76 |
### CMake options defined for libssh |
| 77 |
|
| 78 |
Options are defined in the following files: |
| 79 |
|
| 80 |
- DefineOptions.cmake |
| 81 |
|
| 82 |
They can be changed with the -D option: |
| 83 |
|
| 84 |
`cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DWITH_ZLIB=OFF ..` |
| 85 |
|
| 86 |
### Browsing/editing CMake options |
| 87 |
|
| 88 |
In addition to passing options on the command line, you can browse and edit |
| 89 |
CMake options using `cmakesetup` (Windows), `cmake-gui` or `ccmake` (GNU/Linux |
| 90 |
and MacOS X). |
| 91 |
|
| 92 |
- Go to the build dir |
| 93 |
- On Windows: run `cmakesetup` |
| 94 |
- On GNU/Linux and MacOS X: run `ccmake ..` |
| 95 |
|
| 96 |
### Useful Windows options: |
| 97 |
|
| 98 |
If you have installed OpenSSL or ZLIB in non standard directories, maybe you |
| 99 |
want to set: |
| 100 |
|
| 101 |
OPENSSL_ROOT_DIR |
| 102 |
|
| 103 |
and |
| 104 |
|
| 105 |
ZLIB_ROOT_DIR |
| 106 |
|
| 107 |
## Installing |
| 108 |
|
| 109 |
If you want to install libssh after compilation run: |
| 110 |
|
| 111 |
make install |
| 112 |
|
| 113 |
## Running |
| 114 |
|
| 115 |
The libssh binary can be found in the `build/src` directory. |
| 116 |
You can use `build/examples/samplessh` which is a sample client to |
| 117 |
test libssh on UNIX. |
| 118 |
|
| 119 |
## About this document |
| 120 |
|
| 121 |
This document is written using [Markdown][] syntax, making it possible to |
| 122 |
provide usable information in both plain text and HTML format. Whenever |
| 123 |
modifying this document please use [Markdown][] syntax. |
| 124 |
|
| 125 |
[markdown]: https://www.daringfireball.net/projects/markdown |