File tree Expand file tree Collapse file tree 6 files changed +24
-14
lines changed Expand file tree Collapse file tree 6 files changed +24
-14
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,9 @@ pkg_check_modules(libgcrypt REQUIRED IMPORTED_TARGET libgcrypt)
9292
9393option (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+
9598if (USE_SYSTEM_CPR)
9699 find_package (cpr REQUIRED)
97100 add_library (cpr ALIAS cpr::cpr)
Original file line number Diff line number Diff line change @@ -11,11 +11,20 @@ add_subdirectory(libzsync)
1111# external dependencies used as submodules
1212
1313if (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 )
1928endif ()
2029
2130# it's quite simple dealing with the args library directly from CMake
Original file line number Diff line number Diff 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;
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -5,10 +5,6 @@ include(CTest)
55
66set (CMAKE_CXX_STANDARD 11)
77
8- include_directories (../src)
9-
10- include_directories (${CPR_INCLUDE_DIRS} )
11-
128add_executable (test_zsutil test_zsutil.cpp)
139target_link_libraries (test_zsutil PRIVATE libzsync2 gtest cpr)
1410add_test (NAME test_zsutil COMMAND test_zsutil)
You can’t perform that action at this time.
0 commit comments