David Benjamin | 95aaf4a | 2015-09-03 12:09:36 -0400 | [diff] [blame] | 1 | # Building BoringSSL |
| 2 | |
| 3 | ## Build Prerequisites |
| 4 | |
| 5 | * [CMake] [1] 2.8.8 or later is required. |
| 6 | |
| 7 | * Perl 5.6.1 or later is required. On Windows, [Strawberry Perl] [2] and MSYS |
| 8 | Perl have both been reported to work. If not found by CMake, it may be |
| 9 | configured explicitly by setting `PERL_EXECUTABLE`. |
| 10 | |
| 11 | * On Windows you currently must use [Ninja] [3] to build; on other platforms, |
| 12 | it is not required, but recommended, because it makes builds faster. |
| 13 | |
| 14 | * If you need to build Ninja from source, then a recent version of |
| 15 | [Python] [4] is required (Python 2.7.5 works). |
| 16 | |
| 17 | * On Windows only, [Yasm] [5] is required. If not found by CMake, it may be |
| 18 | configured explicitly by setting `CMAKE_ASM_NASM_COMPILER`. |
| 19 | |
| 20 | * A C compiler is required. On Windows, MSVC 12 (Visual Studio 2013) or later |
| 21 | with Platform SDK 8.1 or later are supported. Recent versions of GCC and |
| 22 | Clang should work on non-Windows platforms, and maybe on Windows too. |
| 23 | |
| 24 | * [Go] [6] is required. If not found by CMake, the go executable may be |
| 25 | configured explicitly by setting `GO_EXECUTABLE`. |
| 26 | |
| 27 | ## Building |
| 28 | |
| 29 | Using Ninja (note the 'N' is capitalized in the cmake invocation): |
| 30 | |
| 31 | mkdir build |
| 32 | cd build |
| 33 | cmake -GNinja .. |
| 34 | ninja |
| 35 | |
| 36 | Using Make (does not work on Windows): |
| 37 | |
| 38 | mkdir build |
| 39 | cd build |
| 40 | cmake .. |
| 41 | make |
| 42 | |
| 43 | You usually don't need to run `cmake` again after changing `CMakeLists.txt` |
| 44 | files because the build scripts will detect changes to them and rebuild |
| 45 | themselves automatically. |
| 46 | |
| 47 | Note that the default build flags in the top-level `CMakeLists.txt` are for |
| 48 | debugging—optimisation isn't enabled. |
| 49 | |
| 50 | If you want to cross-compile then there is an example toolchain file for 32-bit |
| 51 | Intel in `util/`. Wipe out the build directory, recreate it and run `cmake` like |
| 52 | this: |
| 53 | |
| 54 | cmake -DCMAKE_TOOLCHAIN_FILE=../util/32-bit-toolchain.cmake -GNinja .. |
| 55 | |
| 56 | If you want to build as a shared library, pass `-DBUILD_SHARED_LIBS=1`. On |
| 57 | Windows, where functions need to be tagged with `dllimport` when coming from a |
| 58 | shared library, define `BORINGSSL_SHARED_LIBRARY` in any code which `#include`s |
| 59 | the BoringSSL headers. |
| 60 | |
| 61 | ### Building for Android |
| 62 | |
| 63 | It's possible to build BoringSSL with the Android NDK using CMake. This has |
| 64 | been tested with version 10d of the NDK. |
| 65 | |
| 66 | Unpack the Android NDK somewhere and export `ANDROID_NDK` to point to the |
| 67 | directory. Clone https://github.com/taka-no-me/android-cmake into `util/`. Then |
| 68 | make a build directory as above and run CMake *twice* like this: |
| 69 | |
| 70 | cmake -DANDROID_NATIVE_API_LEVEL=android-9 \ |
| 71 | -DANDROID_ABI=armeabi-v7a \ |
| 72 | -DCMAKE_TOOLCHAIN_FILE=../util/android-cmake/android.toolchain.cmake \ |
| 73 | -DANDROID_NATIVE_API_LEVEL=16 \ |
| 74 | -GNinja .. |
| 75 | |
| 76 | Once you've run that twice, Ninja should produce Android-compatible binaries. |
| 77 | You can replace `armeabi-v7a` in the above with `arm64-v8a` to build aarch64 |
| 78 | binaries. |
| 79 | |
| 80 | ## Known Limitations on Windows |
| 81 | |
| 82 | * Versions of CMake since 3.0.2 have a bug in its Ninja generator that causes |
| 83 | yasm to output warnings |
| 84 | |
| 85 | yasm: warning: can open only one input file, only the last file will be processed |
| 86 | |
| 87 | These warnings can be safely ignored. The cmake bug is |
| 88 | http://www.cmake.org/Bug/view.php?id=15253. |
| 89 | |
| 90 | * CMake can generate Visual Studio projects, but the generated project files |
| 91 | don't have steps for assembling the assembly language source files, so they |
| 92 | currently cannot be used to build BoringSSL. |
| 93 | |
| 94 | |
| 95 | [1]: http://www.cmake.org/download/ |
| 96 | [2]: http://strawberryperl.com/ |
| 97 | [3]: https://martine.github.io/ninja/ |
| 98 | [4]: https://www.python.org/downloads/ |
| 99 | [5]: http://yasm.tortall.net/ |
| 100 | [6]: https://golang.org/dl/ |