16021
|
1 |
# Adding Corrosion to your project
|
|
2 |
|
|
3 |
There are two fundamental installation methods that are supported by Corrosion - installation as a
|
|
4 |
CMake package or using it as a subdirectory in an existing CMake project. For CMake versions below
|
|
5 |
3.19 Corrosion strongly recommends installing the package, either via a package manager or manually
|
|
6 |
using CMake's installation facilities.
|
|
7 |
If you have CMake 3.19 or newer, we recommend to use either the [FetchContent](#fetchcontent) or the
|
|
8 |
[Subdirectory](#subdirectory) method to integrate Corrosion.
|
|
9 |
|
|
10 |
## FetchContent
|
|
11 |
If you are using CMake >= 3.19 or installation is difficult or not feasible in
|
|
12 |
your environment, you can use the
|
|
13 |
[FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) module to include
|
|
14 |
Corrosion. This will download Corrosion and use it as if it were a subdirectory at configure time.
|
|
15 |
|
|
16 |
In your CMakeLists.txt:
|
|
17 |
```cmake
|
|
18 |
include(FetchContent)
|
|
19 |
|
|
20 |
FetchContent_Declare(
|
|
21 |
Corrosion
|
|
22 |
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
|
23 |
GIT_TAG v0.5 # Optionally specify a commit hash, version tag or branch here
|
|
24 |
)
|
|
25 |
# Set any global configuration variables such as `Rust_TOOLCHAIN` before this line!
|
|
26 |
FetchContent_MakeAvailable(Corrosion)
|
|
27 |
```
|
|
28 |
|
|
29 |
## Subdirectory
|
|
30 |
Corrosion can also be used directly as a subdirectory. This solution may work well for small
|
|
31 |
projects, but it's discouraged for large projects with many dependencies, especially those which may
|
|
32 |
themselves use Corrosion. Either copy the Corrosion library into your source tree, being sure to
|
|
33 |
preserve the `LICENSE` file, or add this repository as a git submodule:
|
|
34 |
```bash
|
|
35 |
git submodule add https://github.com/corrosion-rs/corrosion.git
|
|
36 |
```
|
|
37 |
|
|
38 |
From there, using Corrosion is easy. In your CMakeLists.txt:
|
|
39 |
```cmake
|
|
40 |
add_subdirectory(path/to/corrosion)
|
|
41 |
```
|
|
42 |
|
|
43 |
## Installation
|
|
44 |
|
|
45 |
|
|
46 |
Installation will pre-build all of Corrosion's native tooling (required only for CMake versions
|
|
47 |
below 3.19) and install it together with Corrosions CMake files into a standard location.
|
|
48 |
On CMake >= 3.19 installing Corrosion does not offer any speed advantages, unless the native
|
|
49 |
tooling option is explicitly enabled.
|
|
50 |
|
|
51 |
### Install from source
|
|
52 |
|
|
53 |
First, download and install Corrosion:
|
|
54 |
```bash
|
|
55 |
git clone https://github.com/corrosion-rs/corrosion.git
|
|
56 |
# Optionally, specify -DCMAKE_INSTALL_PREFIX=<target-install-path> to specify a
|
|
57 |
# custom installation directory
|
|
58 |
cmake -Scorrosion -Bbuild -DCMAKE_BUILD_TYPE=Release
|
|
59 |
cmake --build build --config Release
|
|
60 |
# This next step may require sudo or admin privileges if you're installing to a system location,
|
|
61 |
# which is the default.
|
|
62 |
cmake --install build --config Release
|
|
63 |
```
|
|
64 |
|
|
65 |
You'll want to ensure that the install directory is available in your `PATH` or `CMAKE_PREFIX_PATH`
|
|
66 |
environment variable. This is likely to already be the case by default on a Unix system, but on
|
|
67 |
Windows it will install to `C:\Program Files (x86)\Corrosion` by default, which will not be in your
|
|
68 |
`PATH` or `CMAKE_PREFIX_PATH` by default.
|
|
69 |
|
|
70 |
Once Corrosion is installed, and you've ensured the package is available in your `PATH`, you
|
|
71 |
can use it from your own project like any other package from your CMakeLists.txt:
|
|
72 |
```cmake
|
|
73 |
find_package(Corrosion REQUIRED)
|
|
74 |
```
|
|
75 |
|
|
76 |
### Package Manager
|
|
77 |
|
|
78 |
#### Homebrew (unofficial)
|
|
79 |
|
|
80 |
Corrosion is available via Homebrew and can be installed via
|
|
81 |
|
|
82 |
```bash
|
|
83 |
brew install corrosion
|
|
84 |
```
|
|
85 |
|
|
86 |
Please note that this package is community maintained. Please also keep in mind that Corrosion follows
|
|
87 |
semantic versioning and minor version bumps (i.e. `0.3` -> `0.4`) may contain breaking changes, while
|
|
88 |
Corrosion is still pre `1.0`.
|
|
89 |
Please read the release notes when upgrading Corrosion.
|