cpr icon indicating copy to clipboard operation
cpr copied to clipboard

Compatiblity for OSX without filesystem.h

Open kpeo opened this issue 2 years ago • 6 comments

There is a long story of pain with filesystem.h on OSX using CLang, so for those who still wants to compile cpr - this patch could be useful. Surely, boost is not the optimal decision, specially if project doesn't use it. Also there are some failed tests, that requires additional research and fixes.

Tested on OSX 10.13 Clang LLVM 10.0.1: 3 tests failed out of 23:

  • cpr_post_tests (UrlEncodedPostTests.UrlPostAsyncSingleTest)
  • cpr_head_tests (HeadTests.BasicHeadAsyncTest)
  • cpr_options_tests (OptionsTests.AsyncBaseUrlTest, OptionsTests.AsyncSpecificUrlTest)

kpeo avatar Aug 24 '22 01:08 kpeo

Yes, I see:

Checking /home/runner/work/cpr/cpr/cpr/file.cpp ... /home/runner/work/cpr/cpr/include/cpr/filesystem.h:11:0: error: failed to evaluate #elif condition, division/modulo by zero [preprocessorErrorDirective] #elif __has_include(<boost/filesystem.hpp>) ^ make[2]: *** [cpr/CMakeFiles/cpr.dir/build.make:216: cpr/CMakeFiles/cpr.dir/file.cpp.o] Error 1

Looks strange. Checking. Thank you!

kpeo avatar Aug 25 '22 08:08 kpeo

With __has_include("boost/filesystem.hpp") cppcheck passed, but compilation failed. As workaround for the issue with cppcheck, this line could be suppressed:

//cppcheck-suppress preprocessorErrorDirective
#elif __has_include(<boost/filesystem.hpp>)

and cppcheck should be started with --inline-suppr argument.

kpeo avatar Aug 25 '22 11:08 kpeo

cppcheck should be fine now, since --inline-suppr already added in cmake/cppcheck.cmake

kpeo avatar Aug 25 '22 11:08 kpeo

Would you mind creating a option for this. E.g. CPR_USE_BOOST_FILESYSTEM

KingKili avatar Sep 06 '22 06:09 KingKili

yes, working on it. do I need to switch to another branch for PR while WIP (draft)?

kpeo avatar Sep 06 '22 08:09 kpeo

No, there is no need for a new branch

KingKili avatar Sep 06 '22 08:09 KingKili

All looks good. Thanks for your work (and sorry for the many iterations). I will merge after the CI passes.

KingKili avatar Sep 27 '22 07:09 KingKili

Great! Thank you! There are possible bugs on using fs::file still (e.g. suspecting multiperform.h for Download) - not found it yet, tracing/debugging in spare time.

kpeo avatar Sep 27 '22 13:09 kpeo