Skip to content

Commit 9edd373

Browse files
author
guy levy
committed
📝 add documentation to CMake find-package support libcpr#645
1 parent ab6ec0b commit 9edd373

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ For a quick overview about the planed features, have a look at the next [Milesto
7474
7575
### CMake
7676
77+
#### fetch_content:
7778
If you already have a CMake project you need to integrate C++ Requests with, the primary way is to use `fetch_content`.
7879
Add the following to your `CMakeLists.txt`.
7980
@@ -95,6 +96,30 @@ That should do it!
9596
There's no need to handle `libcurl` yourself. All dependencies are taken care of for you.
9697
All of this can be found in an example [**here**](https://github.com/libcpr/example-cmake-fetch-content).
9798

99+
#### find_package():
100+
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.
101+
102+
**Note:** this feature is feasible only if CPR_USE_SYSTEM_CURL is set. (see [#645](https://github.com/libcpr/cpr/pull/645))
103+
```Bash
104+
$ git clone https://github.com/libcpr/cpr.git
105+
$ cd cpr && mkdir build && cd build
106+
$ cmake .. -DCPR_USE_SYSTEM_CURL=ON
107+
$ make -j
108+
$ sudo make install
109+
```
110+
In your CMakeLists.txt:
111+
112+
```cmake
113+
find_package(cpr REQUIRED)
114+
if (cpr_FOUND)
115+
message(STATUS "Found cpr: ${cpr_CONFIG} (found version ${cpr_VERSION})")
116+
endif ()
117+
118+
add_executable(your_target your_target.cpp)
119+
120+
target_link_libraries(your_target PRIVATE cpr::cpr)
121+
```
122+
98123
### Packages for Linux Distributions
99124

100125
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.

0 commit comments

Comments
 (0)