|
| 1 | +# Building PicoQUIC |
| 2 | + |
| 3 | +See the 'Building Picoquic' section [README](../README.md) for building picoquic for the first time and installing the dependencies. |
| 4 | + |
| 5 | +## Dependencies |
| 6 | + |
| 7 | +Direct dependencies |
| 8 | +- [Picotls implementation of TLS 1.3](https://github.com/h2o/picotls) |
| 9 | + |
| 10 | +Fetching and installing this package can be done through an option when invoking cmake, as follows. |
| 11 | + |
| 12 | +```shell |
| 13 | + cmake -DPICOQUIC_FETCH_PTLS=Y . |
| 14 | +``` |
| 15 | + |
| 16 | +Inherited dependencies |
| 17 | +- [OpenSSL through PicoTLS](https://github.com/openssl/openssl) |
| 18 | + |
| 19 | +TODO: Current issues and ongoing work |
| 20 | + |
| 21 | +There is a current issue trying to enable the use of `mbedtls` instead of `openssl`. |
| 22 | + |
| 23 | +## Targets |
| 24 | + |
| 25 | +Targets are anything that is defined as an executable in `CMakeLists.txt`. |
| 26 | +Available targets: |
| 27 | + |
| 28 | +- picoquicdemo |
| 29 | +- picolog_t |
| 30 | +- picoquic_ct |
| 31 | +- picohttp_ct |
| 32 | +- pico_baton |
| 33 | +- picoquic_sample |
| 34 | +- thread_test |
| 35 | + |
| 36 | +All of these targets are built when the `make .` or `cmake --build .` commands are used to build the project. After which the test program `picoquic_ct` can be used to verify the port. |
| 37 | + |
| 38 | +`picoquicdemo` ([found in picoquicfirst/picoquicdemo.c](../picoquicfirst/picoquicdemo.c)) and `picoquic_sample` ([sample documentation](../sample/README.md)) are a good starting point for developing an application on top of this QUIC implementation. |
| 39 | + |
| 40 | + |
| 41 | +## (Re)Building a Single Target |
| 42 | + |
| 43 | +Targets defined in the `CMakeLists.txt`, listed above for convenience, can be build individually using cmake's `--target` option. The command `cmake --build . --target <target_name>` can be used to build a specific target and all it's dependcies. For example `cmake --build . --target picoquic_sample` will build the sample file transfer application in [sample/](../sample/README.md) as defined in the `CMakeLists.txt`. All the required components will also be built. This works if the command is issued in the top-level directory of the repository. This is useful for recompiling test programs and programs like `picoquic_sample` and `picoquicdemo` if they have been modified. Therefore reducing build times when making small changes. |
| 44 | + |
| 45 | +This also works if `picoquic` has not been built as a whole before. |
| 46 | + |
| 47 | +## Picoquic options |
| 48 | + |
| 49 | +- building and fetching PTLS `-DPICOQUIC_FETCH_PTLS=Y` |
| 50 | +- building with exported debug information `-DCMAKE_BUILD_TYPE=Debug` |
| 51 | + |
| 52 | +These two options can be set when configuring cmake. |
| 53 | + |
| 54 | +- adress sanitation `ASAN` |
| 55 | +- undefined behaviour sanitation `UBSAN` |
| 56 | + |
| 57 | +`ASAN` and `UBSAN` are C/C++ compiler features and can be set by setting compiler flags when using the `cmake`. |
| 58 | +`cmake "-DCMAKE_C_FLAGS=-fsanitize=address,undefined -DCMAKE_CXX_FLAGS=-fsanitize=address,undefined"` sets both the `ASAN/UBSAN` options for C and C++. |
| 59 | +Alternatively these options can be set using `ccmake` as well by setting the flieds `DCMAKE_C_FLAGS & DCMAKE_CXX_FLAGS` to `-fsanitize=address,undefined`. |
| 60 | + |
| 61 | +## Picoquic as a Dependency |
| 62 | + |
| 63 | +When using CMake [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) can be used to fetch the `picoquic` repository from github. |
| 64 | +A snipped that does this can be seen in the [quicrq](https://github.com/Quicr/quicrq) directory in the `dependencies` subdirectory and is shown below. |
| 65 | + |
| 66 | +```cmake |
| 67 | +# Enable fetching content |
| 68 | +include(FetchContent) |
| 69 | +
|
| 70 | +# Fetch the picoquic library, which brings in picotls with it |
| 71 | +FetchContent_Declare( |
| 72 | + picoquic |
| 73 | + GIT_REPOSITORY https://github.com/private-octopus/picoquic.git |
| 74 | + GIT_TAG master |
| 75 | +) |
| 76 | +
|
| 77 | +# Set the option to force picoquic to fetch the picotls |
| 78 | +find_package(PTLS) |
| 79 | +if(NOT PTLS_FOUND) |
| 80 | +set(PICOQUIC_FETCH_PTLS ON) |
| 81 | +end_if() |
| 82 | +
|
| 83 | +# Make dependencies available |
| 84 | +FetchContent_MakeAvailable(picoquic) |
| 85 | +``` |
| 86 | + |
| 87 | +FetchContent can be used to fetch a specific release or tag, if a certain version or release is desired. |
| 88 | +This can be used as fine grain as choosing a single commit, by specifying the commit hash. |
| 89 | + |
| 90 | +In the main `CMakeLists.txt` the subdirectory can be added using the `add_subdirectory(<directory_name>)` directive. |
| 91 | + |
| 92 | +```cmake |
| 93 | +# Add the subdirectory dependencies, where dependencies/CMakeLists.txt looks as above |
| 94 | +add_subdirectory(dependencies) |
| 95 | +
|
| 96 | +# check if the package was loaded/is available and stop the build if it was not |
| 97 | +find_package(picoquic REQUIRED) |
| 98 | +``` |
| 99 | + |
| 100 | +Additionally `cmake` needs to be told where to find the imported dependency, using hints defined in a `cmake/Find<DependencyName>.cmake` file placed in the top-most directory in the repository. |
| 101 | +The cmake documentation describes how to [Create CMake Package Configuration Files](https://cmake.org/cmake/help/book/mastering-cmake/chapter/Finding%20Packages.html). |
| 102 | + |
0 commit comments