|
1 | | -# b64 - Install <!-- omit in toc --> |
| 1 | +# b64 - Installation and Use <!-- omit in toc --> |
| 2 | + |
| 3 | +**b64** is a classic-form C/C++ library, insofar as it has implementation |
| 4 | +files in its **src** directory and header files in its **include/b64** |
| 5 | +directory. Thus, once "installed", one must simply include **b64/b64.h** |
| 6 | +(C API) or **b64/b64.hpp** (C++ API), and compile-in or link-in the |
| 7 | +implementation. |
| 8 | + |
| 9 | +The **C API** has no non-standard dependencies. The **C++ API** depends on |
| 10 | +**STLSoft**. Building the project's tests additionally requires **xTests** |
| 11 | +(and optionally recognises **shwild**). |
| 12 | + |
2 | 13 |
|
3 | 14 | ## Table of Contents <!-- omit in toc --> |
4 | 15 |
|
5 | | -- [Installing](#installing) |
| 16 | +- [CMake](#cmake) |
| 17 | +- [Bundled](#bundled) |
6 | 18 |
|
7 | 19 |
|
8 | | -## Installing |
| 20 | +## CMake |
9 | 21 |
|
10 | | -T.B.C. |
| 22 | +The primary choice for installation is by use of **CMake**. |
11 | 23 |
|
| 24 | +1. Obtain the latest distribution of **b64**, from |
| 25 | + https://github.com/synesissoftware/b64/, e.g. |
12 | 26 |
|
13 | | -<!-- ########################### end of file ########################### --> |
| 27 | + ```bash |
| 28 | + $ mkdir -p ~/open-source |
| 29 | + $ cd ~/open-source |
| 30 | + $ git clone https://github.com/synesissoftware/b64/ |
| 31 | + ``` |
| 32 | + |
| 33 | +2. Prepare the CMake configuration, via the **prepare_cmake.sh** script. |
| 34 | + |
| 35 | + For a minimal **C API**-only install (no **STLSoft** / **xTests** |
| 36 | + required): |
| 37 | + |
| 38 | + ```bash |
| 39 | + $ cd ~/open-source/b64 |
| 40 | + $ ./prepare_cmake.sh --no-cpp --disable-testing -v |
| 41 | + ``` |
| 42 | + |
| 43 | + For a full build including the **C++ API**, examples, and tests, install |
| 44 | + **STLSoft** 1.11 (and **xTests** for tests) via their own **CMake** |
| 45 | + scripts first, then: |
| 46 | + |
| 47 | + ```bash |
| 48 | + $ cd ~/open-source/b64 |
| 49 | + $ ./prepare_cmake.sh -v |
| 50 | + ``` |
| 51 | + |
| 52 | + If **STLSoft** is available as a source tree rather than an installed |
| 53 | + **CMake** package, pass its root with `--stlsoft-root-dir` / `-s`. |
| 54 | + |
| 55 | + (**Hint**: execute `$ ./prepare_cmake.sh --help` for more information.) |
| 56 | + |
| 57 | +3. Run a build of the generated **CMake**-derived build files via the |
| 58 | + **build_cmake.sh** script, as in: |
| 59 | + |
| 60 | + ```bash |
| 61 | + $ ./build_cmake.sh |
| 62 | + ``` |
| 63 | + |
| 64 | + (**NOTE**: if you provide the flag `--run-make` (=== `-m`) in step 2 then |
| 65 | + you do not need this step.) |
| 66 | + |
| 67 | +4. As a check (when testing was not disabled), execute the built unit-test |
| 68 | + programs via **run_all_unit_tests.sh**, as in: |
| 69 | + |
| 70 | + ```bash |
| 71 | + $ ./run_all_unit_tests.sh |
| 72 | + ``` |
| 73 | + |
| 74 | +5. Install the library on the host, via `cmake`, as in: |
| 75 | + |
| 76 | + ```bash |
| 77 | + $ sudo cmake --install ${SIS_CMAKE_BUILD_DIR:-./_build} --config Release |
| 78 | + ``` |
| 79 | + |
| 80 | +6. Then to use the library, it is a simple matter as follows: |
| 81 | + |
| 82 | + 1. Assuming a simplest possible program to verify the installation: |
| 83 | + |
| 84 | + ```c |
| 85 | + /* main.c */ |
| 86 | + #include <b64/b64.h> |
| 87 | + |
| 88 | + #include <stdio.h> |
| 89 | + #include <stdlib.h> |
| 90 | + #include <string.h> |
| 91 | + |
| 92 | + int main(void) |
| 93 | + { |
| 94 | + unsigned char const bytes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; |
| 95 | + size_t const cch = b64_encode(bytes, sizeof(bytes), NULL, 0); |
| 96 | + char* const enc = (char*)malloc(cch); |
14 | 97 |
|
| 98 | + if (NULL == enc) |
| 99 | + { |
| 100 | + return EXIT_FAILURE; |
| 101 | + } |
| 102 | + |
| 103 | + b64_encode(bytes, sizeof(bytes), enc, cch); |
| 104 | + |
| 105 | + printf("encoded: %.*s\n", (int)cch, enc); |
| 106 | + |
| 107 | + free(enc); |
| 108 | + |
| 109 | + return EXIT_SUCCESS; |
| 110 | + } |
| 111 | + ``` |
| 112 | + |
| 113 | + 2. Compile your project against **b64**: |
| 114 | + |
| 115 | + Due to the installation step (step 5 above) there is no requirement |
| 116 | + for an explicit include directory for **b64**: |
| 117 | + |
| 118 | + ```bash |
| 119 | + $ cc -c main.c |
| 120 | + ``` |
| 121 | + |
| 122 | + 3. Link your project against **b64**: |
| 123 | + |
| 124 | + Due to the installation step (step 5 above) there is no requirement |
| 125 | + for an explicit library directory for **b64**: |
| 126 | + |
| 127 | + ```bash |
| 128 | + $ cc main.o -lb64 |
| 129 | + ``` |
| 130 | + |
| 131 | + 4. Test your project: |
| 132 | + |
| 133 | + ```bash |
| 134 | + $ ./a.out |
| 135 | + encoded: AQIDBAUGBwgJCg== |
| 136 | + $ |
| 137 | + ``` |
| 138 | + |
| 139 | + Consumers that use **CMake** may instead depend on the installed package: |
| 140 | + |
| 141 | + ```cmake |
| 142 | + find_package(b64 REQUIRED) |
| 143 | + target_link_libraries(your_target PRIVATE b64::core) |
| 144 | + ``` |
| 145 | + |
| 146 | + Use of **b64/b64.hpp** additionally requires **STLSoft** |
| 147 | + (`find_package(STLSoft REQUIRED)`). |
| 148 | + |
| 149 | + |
| 150 | +## Bundled |
| 151 | + |
| 152 | +**b64** is small enough that it is commonly bundled into other projects |
| 153 | +(for example **Pantheios**). In that case: |
| 154 | + |
| 155 | +* add **b64**'s **include** directory to your project's include path; |
| 156 | +* compile **src/b64.c** into your build (or link a previously built |
| 157 | + **libb64**); and |
| 158 | +* `#include <b64/b64.h>` (or **b64/b64.hpp** if the **C++ API** and |
| 159 | + **STLSoft** are available). |
| 160 | + |
| 161 | + |
| 162 | +<!-- ########################### end of file ########################### --> |
0 commit comments