https://github.com/snikulov/conan.examples
Examples how to use conan.io C++ package manager
https://github.com/snikulov/conan.examples
boost cmake conan conan-usage cplusplus cpp
Last synced: about 1 year ago
JSON representation
Examples how to use conan.io C++ package manager
- Host: GitHub
- URL: https://github.com/snikulov/conan.examples
- Owner: snikulov
- License: cc0-1.0
- Created: 2020-05-30T11:46:52.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-11T14:09:27.000Z (about 6 years ago)
- Last Synced: 2025-03-27T08:48:25.831Z (over 1 year ago)
- Topics: boost, cmake, conan, conan-usage, cplusplus, cpp
- Language: C++
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Boost + conan.io + CMake example
Why the dependency manager???
Because:
* It's hard to maintain, especially when the project goes large.
* I'm personally, prefer don't repeat myself (see [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)) and re-use binary whenever possible.
I try to use conan.io for this.
* It quite easy to switch between Boost versions on any platform.
* And even do this automatically on CI/CD servers.
Usage example
1. Intrusive way.
We inject generated by Conan settings into CMakeLists.txt by editing it (ref. to [include](https://github.com/snikulov/conan.examples/blob/master/boost.log.intrusive/CMakeLists.txt#L14) ).
```shell
$ cd boost.log.intrusive; mkdir build; cd build
$ conan install .. --build missing
$ cmake ..
$ cmake --build .
```
We all set.
2. Non-intrusive or less intrusive way.
We already have our CMakeLists.txt file with a lot of ```find_packages(...)``` in it.
How to tell CMake to use Conan's binary packages?
Inject search paths using [CMAKE_TOOLCHAIN_FILE](https://cmake.org/cmake/help/latest/variable/CMAKE_TOOLCHAIN_FILE.html).
```shell
$ cd boost.log.nonintrusive; mkdir build; cd build
$ conan install .. --build missing
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_paths.cmake
$ cmake --build .
```
We all set.
**NOTE:**
I'm not sure if it correct, because I, sometimes, check for CMAKE_TOOLCHAIN_FILE variable to detect if I'm in cross-compilation mode.
To avoid TOOLCHAIN_FILE usage, a perhaps better way to provide conan_paths.cmake's variables through the command line.
for example
* ```$ cmake .. -D= [-D...]``` etc.
* include conan_paths.cmake on top of your CMakeLists.txt (intrusive, but less changes in find_packages).