|
| 1 | +# Branch Metrics C++ SDK |
| 2 | + |
| 3 | +[](https://github.com/BranchMetrics/cpp-branch-deep-linking-attribution/blob/master/LICENSE) |
| 4 | +[](https://circleci.com/gh/BranchMetrics/cpp-branch-deep-linking-attribution) |
| 5 | + |
| 6 | +[Platform prerequisites]: #platform-prerequisites |
| 7 | +[Install CMake and Conan]: #install-cmake-and-conan |
| 8 | +[Set up Branch remote]: #set-up-branch-remote |
| 9 | +[Set up a default conan profile]: #set-up-a-default-conan-profile |
| 10 | +[Integration]: #integration |
| 11 | +[Sample apps]: #sample-apps |
| 12 | + |
| 13 | +## Contents |
| 14 | +- [Platform prerequisites] |
| 15 | +- [Install CMake and Conan] |
| 16 | +- [Set up a default Conan profile] |
| 17 | +- [Set up Branch remote] |
| 18 | +- [Integration] |
| 19 | +- [Sample apps] |
| 20 | + |
| 21 | +## Platform prerequisites |
| 22 | + |
| 23 | +### Windows |
| 24 | + |
| 25 | +- Visual Studio 2019 |
| 26 | +- Python/Pip (can be installed through Visual Studio or otherwise) |
| 27 | +- (Optional): Conan Visual Studio Extension |
| 28 | +- Ensure that python, pip and the pip installation bin folder are in your PATH. |
| 29 | + |
| 30 | +### macOS |
| 31 | + |
| 32 | +```bash |
| 33 | +xcode-select --install # XCode command-line tools required |
| 34 | +brew install python # Python and pip required |
| 35 | +``` |
| 36 | + |
| 37 | +### Ubuntu |
| 38 | + |
| 39 | +```bash |
| 40 | +sudo apt-get install -y g++ |
| 41 | +sudo apt-get install -y python |
| 42 | +sudo apt-get install -y python-pip |
| 43 | +``` |
| 44 | + |
| 45 | +## Install CMake and Conan |
| 46 | + |
| 47 | +``` |
| 48 | +pip install cmake |
| 49 | +pip install conan |
| 50 | +``` |
| 51 | + |
| 52 | +Note that in some cases it may be necessary to run `pip install --user cmake`, |
| 53 | +etc. It may also be necessary to use sudo. |
| 54 | + |
| 55 | +Note that cmake may be installed in different ways. This SDK requires version |
| 56 | +3.12 or later. On Ubuntu, `apt-get install cmake` will only provide 3.10, so |
| 57 | +`pip install cmake` is required. |
| 58 | + |
| 59 | +## Set up a default conan profile |
| 60 | + |
| 61 | +Before installing software with Conan, you have to create a default profile. |
| 62 | +Run the following command once to create a profile called default. |
| 63 | + |
| 64 | +``` |
| 65 | +conan profile new default --detect |
| 66 | +``` |
| 67 | + |
| 68 | +See https://docs.conan.io for detailed information on using Conan. |
| 69 | + |
| 70 | +## Set up Branch remote |
| 71 | + |
| 72 | +_This step will no longer be necessary once the package is contributed to |
| 73 | +conan-center._ |
| 74 | + |
| 75 | +Add the Branch Conan repository. You can call it anything at all. Here and below it is |
| 76 | +called `branch`: |
| 77 | + |
| 78 | +``` |
| 79 | +conan remote add branch https://api.bintray.com/conan/branchsdk/cpp-branch-deep-linking-attribution |
| 80 | +``` |
| 81 | + |
| 82 | +## Integration |
| 83 | + |
| 84 | +Add a file called conanfile.txt to your project root with the following |
| 85 | +contents: |
| 86 | + |
| 87 | +``` |
| 88 | +[requires] |
| 89 | +BranchIO/1.0.0@branch/stable |
| 90 | +
|
| 91 | +[options] |
| 92 | +# master is the default. Uncomment and modify to use a different branch |
| 93 | +# BranchIO:git_branch=master |
| 94 | +``` |
| 95 | + |
| 96 | +And then `conan install . --build outdated -s build_type=CONFIGURATION`, |
| 97 | +where `CONFIGURATION` is Debug or Release. When building on Windows at the |
| 98 | +command line, also pass `-s arch=ARCHITECTURE`, where `ARCHITECTURE` is |
| 99 | +x86 or x86_64. |
| 100 | + |
| 101 | +See the note below on using the Branch remote to download |
| 102 | +prebuilt binary packages for Windows. If you don't specify `-r branch` to |
| 103 | +`conan install` to install from the Branch repository, dependencies will be |
| 104 | +found in conan-center without prebuilt binaries, and you'll be building from |
| 105 | +source. OpenSSL requires the assembler. Use a Native Tools Command Prompt |
| 106 | +when building OpenSSL from source. |
| 107 | + |
| 108 | +**Note:** Once ready for release, the Conan channel will change from `branch/testing` to |
| 109 | +`branch/stable`. |
| 110 | + |
| 111 | +### Visual Studio |
| 112 | + |
| 113 | +The [Conan Visual Studio Extension](https://marketplace.visualstudio.com/items?itemName=conan-io.conan-vs-extension) automatically integrates the dependencies from your conanfile.txt into a Visual Studio project. Version 1.2.1 or later is required. |
| 114 | + |
| 115 | +See [BranchDemo](./BranchSDK-Samples/Windows/BranchDemo) for a working example |
| 116 | +and more information on using the Conan Visual Studio extension. |
| 117 | + |
| 118 | +**Note:** |
| 119 | + |
| 120 | +Binary builds of the packages this SDK depends on are available from the Branch |
| 121 | +Conan repository, but not from conan-center. If you use the Visual Studio |
| 122 | +extension out of the box, it will always initially build OpenSSL, Poco and |
| 123 | +gtest for any configuration that is not yet in the cache. To speed up this |
| 124 | +process considerably, first put the following two-line conanfile.txt anywhere at all on |
| 125 | +your Windows 10 host (not necessarily your project): |
| 126 | + |
| 127 | +``` |
| 128 | +[requires] |
| 129 | +BranchIO/1.0.0@branch/testing |
| 130 | +``` |
| 131 | + |
| 132 | +After you [add the Branch remote](#set-up-branch-remote) and [set up a default profile](#set-up-a-default-conan-profile), just run: |
| 133 | + |
| 134 | +``` |
| 135 | +conan install . -r branch --build BranchIO -s build_type=CONFIGURATION -s arch=ARCHITECTURE |
| 136 | +``` |
| 137 | + |
| 138 | +from a Developer Command Prompt (not necessarily a Native Tools prompt) from the |
| 139 | +directory containing conanfile.txt. CONFIGURATION is Debug or Release. |
| 140 | +ARCHITECTURE is x86 or x86_64. |
| 141 | + |
| 142 | +This will download all dependencies |
| 143 | +prebuilt. The BranchIO package does not yet have binary builds available. |
| 144 | +That will always be built locally from source and cached by Conan. |
| 145 | + |
| 146 | +Building the dependencies takes time, though it is a one-time cost. After you |
| 147 | +build locally, they will be cached. Manually running `conan install -r branch` |
| 148 | +is much faster. This situation will doubtless evolve. |
| 149 | + |
| 150 | +## Sample apps |
| 151 | + |
| 152 | +Running `rmake` in this repo on any platform builds a number of sample apps. Sample apps are |
| 153 | +built in `build/Debug|Release/bin` (Unix) or `build\Debug|Release[x64]\bin`. |
| 154 | +For example: |
| 155 | + |
| 156 | +Unix: |
| 157 | +```bash |
| 158 | +./rmake Debug |
| 159 | +build/Debug/bin/hello |
| 160 | +``` |
| 161 | + |
| 162 | +Windows (64-bit): |
| 163 | +``` |
| 164 | +rmake Debug |
| 165 | +build\Debugx64\bin\hello |
| 166 | +``` |
| 167 | + |
| 168 | +Windows (32-bit): |
| 169 | +``` |
| 170 | +rmake Debug |
| 171 | +build\Debug\bin\hello |
| 172 | +``` |
| 173 | + |
| 174 | +Use the appropriate Native Tools Command Prompt. This script will use |
| 175 | +conan-center for dependencies. |
| 176 | + |
| 177 | +### Hello app |
| 178 | + |
| 179 | +The `hello` app sends a number of requests and logs the output to the console. |
| 180 | + |
| 181 | +This app has a Branch key compiled in. To run, simply |
| 182 | + |
| 183 | +```bash |
| 184 | +build/Debug/bin/hello |
| 185 | +``` |
| 186 | + |
| 187 | + |
| 188 | +### Example app |
| 189 | + |
| 190 | +The `example` app is menu driven and allows you to try a number of scenarios. |
| 191 | +It also prints output to the console. |
| 192 | + |
| 193 | +This app requires a specific Branch key in order to run successfully. |
| 194 | +Provide it as a command-line argument when running. The key is `key_live_efTsR1fbTucbHvX3N5RsOaamDtlPFLap`, e.g. |
| 195 | + |
| 196 | +```bash |
| 197 | +build/Debug/bin/example -k key_live_efTsR1fbTucbHvX3N5RsOaamDtlPFLap |
| 198 | +``` |
| 199 | + |
| 200 | +This app can also pick up preferences from a configuration file, if it exists and is co-located with the exe. |
| 201 | + |
| 202 | +example.properties |
| 203 | +``` |
| 204 | +# Branch Key |
| 205 | +branch_key : key_live_efTsR1fbTucbHvX3N5RsOaamDtlPFLap |
| 206 | +``` |
| 207 | + |
| 208 | +If the key is present in the configuration file, it is not necessary to provide the `-k <key>` parameter. |
| 209 | + |
| 210 | +Note that in Release builds, debug and verbose output log messages are compiled |
| 211 | +out. If you run, e.g.: |
| 212 | + |
| 213 | +```bash |
| 214 | +./rmake Release |
| 215 | +build/Release/bin/hello key_live_bcMneVUDd5sM5vD4BzfcbikdwrmnRDA8 |
| 216 | +``` |
| 217 | + |
| 218 | +you will not see the same output from the SDK as a Debug build. |
0 commit comments