Skip to content

Commit

Permalink
📝 add documentation to CMake find-package support libcpr#645
Browse files Browse the repository at this point in the history
  • Loading branch information
guy levy committed Aug 12, 2022
1 parent ab6ec0b commit 9edd373
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ For a quick overview about the planed features, have a look at the next [Milesto
### CMake
#### fetch_content:
If you already have a CMake project you need to integrate C++ Requests with, the primary way is to use `fetch_content`.
Add the following to your `CMakeLists.txt`.
Expand All @@ -95,6 +96,30 @@ That should do it!
There's no need to handle `libcurl` yourself. All dependencies are taken care of for you.
All of this can be found in an example [**here**](https://github.com/libcpr/example-cmake-fetch-content).

#### find_package():
As an alternative to `fetch_content`, it is possible to download, build and install the library and then simply integrate the library to a project via the standard CMake `find-package()` function.

**Note:** this feature is feasible only if CPR_USE_SYSTEM_CURL is set. (see [#645](https://github.com/libcpr/cpr/pull/645))
```Bash
$ git clone https://github.com/libcpr/cpr.git
$ cd cpr && mkdir build && cd build
$ cmake .. -DCPR_USE_SYSTEM_CURL=ON
$ make -j
$ sudo make install
```
In your CMakeLists.txt:

```cmake
find_package(cpr REQUIRED)
if (cpr_FOUND)
message(STATUS "Found cpr: ${cpr_CONFIG} (found version ${cpr_VERSION})")
endif ()
add_executable(your_target your_target.cpp)
target_link_libraries(your_target PRIVATE cpr::cpr)
```

### Packages for Linux Distributions

Alternatively, you may install a package specific to your Linux distribution. Since so few distributions currently have a package for cpr, most users will not be able to run your program with this approach.
Expand Down

0 comments on commit 9edd373

Please sign in to comment.