Skip to content

Commit be7df38

Browse files
committed
Update cpr
Last time this submodule was updated to a tag from 2017, this commit fixes this mistake. It allows removing the include dirs hack as well as a few other workarounds, since this was fixed upstream.
1 parent 9442bc5 commit be7df38

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ pkg_check_modules(libgcrypt REQUIRED IMPORTED_TARGET libgcrypt)
9292

9393
option(USE_SYSTEM_CPR OFF "Use system-wide installed CPR")
9494

95+
# makes linking to static libraries easier
96+
option(CMAKE_POSITION_INDEPENDENT_CODE ON)
97+
9598
if(USE_SYSTEM_CPR)
9699
find_package(cpr REQUIRED)
97100
add_library(cpr ALIAS cpr::cpr)

lib/CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@ add_subdirectory(libzsync)
1111
# external dependencies used as submodules
1212

1313
if(NOT USE_SYSTEM_CPR)
14+
# for some reason we don't know, cpr wants to build shared libs by default
15+
# this is not the default behavior of CMake, so we force this option off again
16+
# unfortunately, we have to do this globally...
17+
# long term goal is to replace the submodule in some way, e.g., by using prebuilt cpr binaries
18+
set(BUILD_SHARED_LIBS OFF)
19+
20+
# there is no need to build our own libcurl
21+
# in fact, building it as a static lib creates a whole circus of problems, and also takes time
22+
set(CPR_FORCE_USE_SYSTEM_CURL ON)
23+
1424
add_subdirectory(cpr)
15-
set_property(TARGET cpr PROPERTY POSITION_INDEPENDENT_CODE ON)
1625

17-
# this hack is still needed to make the bundled cpr work, unfortunately
18-
target_include_directories(cpr PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/cpr/include)
26+
# since we want to have static builds of cpr, we have to enable -fPIC manually
27+
set_property(TARGET cpr PROPERTY POSITION_INDEPENDENT_CODE ON)
1928
endif()
2029

2130
# it's quite simple dealing with the args library directly from CMake

lib/cpr

Submodule cpr updated 128 files

src/zsclient.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,15 @@ namespace zsync2 {
282282
bytes << "bytes=" << currentChunk << "-" << currentChunk + chunkSize - 1;
283283
session.SetHeader(cpr::Header{{"range", bytes.str()}});
284284

285-
session.SetRedirect(false);
285+
session.SetRedirect(cpr::Redirect{0L});
286286
auto verificationResponse = session.Get();
287287

288288
// bool digestVerified;
289289
// if (!verifyInstanceDigest(verificationResponse, digestVerified))
290290
// return nullptr;
291291

292-
session.SetRedirect(true);
292+
// according to the docs, 50 is the default
293+
session.SetRedirect(cpr::Redirect{50L});
293294
auto response = session.Get();
294295

295296
// expect a range response
@@ -305,10 +306,11 @@ namespace zsync2 {
305306
currentChunk += chunkSize;
306307
}
307308
} else {
308-
session.SetRedirect(false);
309+
session.SetRedirect(cpr::Redirect{0L});
309310
auto verificationResponse = session.Get();
310311

311-
session.SetRedirect(true);
312+
// 50 is the default value according to the docs
313+
session.SetRedirect(cpr::Redirect{50L});
312314
auto response = session.Get();
313315

314316
bool digestVerified;

src/zsutil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ namespace zsync2 {
107107
}
108108

109109
bool resolveRedirections(const std::string& absoluteUrl, std::string& redirectedUrl) {
110-
auto response = cpr::Head(absoluteUrl);
110+
auto response = cpr::Head(cpr::Url{absoluteUrl});
111111

112112
// check for proper response code
113113
// 4xx and 5xx responses can be considered okay for a redirection resolver, as they're valid responses
@@ -116,7 +116,7 @@ namespace zsync2 {
116116
if (response.status_code >= 300 && response.status_code < 400)
117117
return false;
118118

119-
redirectedUrl = response.url;
119+
redirectedUrl = response.url.str();
120120
return true;
121121
}
122122

tests/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ include(CTest)
55

66
set(CMAKE_CXX_STANDARD 11)
77

8-
include_directories(../src)
9-
10-
include_directories(${CPR_INCLUDE_DIRS})
11-
128
add_executable(test_zsutil test_zsutil.cpp)
139
target_link_libraries(test_zsutil PRIVATE libzsync2 gtest cpr)
1410
add_test(NAME test_zsutil COMMAND test_zsutil)

0 commit comments

Comments
 (0)