GithubHelp home page GithubHelp logo

Comments (17)

whoshuu avatar whoshuu commented on May 6, 2024

Great suggestion @niklas88, CMake is definitely the build system of choice for this project, and supporting downstream projects easily through CMake is a high priority.

from cpr.

niklas88 avatar niklas88 commented on May 6, 2024

Hey great seeing you work on this, I just tried using the cpr-config.cmake in my vendoring setting but sadly it failed. I used the following lines to embed it and compiled cpr in it's directory myproject/vendor/cpr:

set ( CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} vendor/cpr/)
find_package ( CPR REQUIRED )
include_directories ( ${CPR_INCLUDE_DIRS} )

Cmake somehow has really horrible error reporting:

cmake --debug-output ..
Running with debug output on.
CMake Error at /usr/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find CPR (missing: CPR_LIBRARY)
Call Stack (most recent call first):
  /usr/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  vendor/cpr/cpr-config.cmake:21 (find_package_handle_standard_args)
  CMakeLists.txt:19 (find_package)


   Called from: [2]     /home/niklas/scratch/cprtest/vendor/cpr/cpr-config.cmake
            [1]     /home/niklas/scratch/cprtest/CMakeLists.txt
    -- Configuring incomplete, errors occurred!
See also "/home/niklas/scratch/cprtest/build/CMakeFiles/CMakeOutput.log".

I can send you the source tree if you like I tried to build a minimal example before integrating it in my other project.

from cpr.

whoshuu avatar whoshuu commented on May 6, 2024

Hey @niklas88, thanks for giving it a try. If you can link me a github repo that's a minimal example you think should work, that'd help a lot. I'll take a look at this again in the morning.

from cpr.

niklas88 avatar niklas88 commented on May 6, 2024

Ok, I have prepared my test as a github project https://github.com/niklas88/cprtest

from cpr.

whoshuu avatar whoshuu commented on May 6, 2024

Have you built the project in the submodule? What were the steps you took in the build. I'm most interested in the root build directory, because that will tell me where to find the path to the cpr library.

For instance, if you do an idiomatic build in vendor/cpr/build, then the library path would be vendor/cpr/build/cpr. Since this is a vendored build, you have to set a hint to tell find_library where to find this library. To do that, set CPR_LIBRARY_ROOT to ${CURRENT_CMAKE_LIST_DIR}/vendor/cpr/build/cpr before calling find_package( CPR REQUIRED ) and you should be good.

from cpr.

whoshuu avatar whoshuu commented on May 6, 2024

My suggestion is that if you have cpr included as a submodule in your project, then it's easier to use add_subdirectory to bring in the includes and symbols. Simple throw in a add_subdirectory(vendor/cpr) in your main CMakeLists.txt and CPR_INCLUDE_DIRS and CPR_LIBRARIES will be correctly populated. An added bonus is that you don't have to manually find and integrate libcurl with your project, that dependency is happened automatically with an add_subdirectory of cpr.

from cpr.

whoshuu avatar whoshuu commented on May 6, 2024

In other words, using find_package(CPR) with cpr-config.cmake is useful for when the cpr source/build is outside the natural scope of your project. If your project includes cpr as a submodule, it's better to use add_subdirectory.

from cpr.

niklas88 avatar niklas88 commented on May 6, 2024

Yeah I realized building in vendor/cpr/build would create things in the wrong path, I tried vendor/cpr als the build directory too. I thought the first line in

set ( CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} vendor/cpr/)
find_package ( CPR REQUIRED )
include_directories ( ${CPR_INCLUDE_DIRS} )

would then set the correct path and at least it finds the cpr-config.cmake because this is what works with the same setup but using netlib-cpp:

set ( CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} vendor/cpp-netlib/)
find_package ( cppnetlib REQUIRED )
include_directories ( ${CPPNETLIB_INCLUDE_DIRS} )

from cpr.

whoshuu avatar whoshuu commented on May 6, 2024

Gotcha. I think I understand the issue now. I don't set an explicit location for putting libcpr.a. It just shows up in <build>/cpr, when it should show up in <build>/lib, since that's where libraries are searched for when CMAKE_PREFIX_PATH is set. Thanks a bunch! I'll get this resolved soon.

from cpr.

whoshuu avatar whoshuu commented on May 6, 2024

If you rebuild cpr from the latest release/1.1 branch, libcpr.a should be put into the right directory so that CMAKE_PREFIX_PATH can find it. Let me know if it works for you.

from cpr.

niklas88 avatar niklas88 commented on May 6, 2024

@whoshuu ok we are definitely making progress. This is definitely an improvement, also sorry I missed adding the rapidjson header only library to the git project. Now it looks like the libcurl symbols aren't available through libcpr.a see this error output:
http://pastebin.com/5aQQarc0

If I link with my system libcurl (I'm on Arch and it may or may not be the same version) the executable works

from cpr.

whoshuu avatar whoshuu commented on May 6, 2024

Yeah see my note about libcurl in this comment. I don't compile the curl sources into libcpr, so you still have to manually link libcurl to your project. This can be avoided if you use add_subdirectory because CMake figures out the dependencies for you and carries it through when you specify the link libraries of a target.

from cpr.

whoshuu avatar whoshuu commented on May 6, 2024

It's possible to manually add libcurl to CPR_LIBRARIES in cpr-config.cmake, but I don't believe that's a pattern that's used a lot. It would make it easier to integrate the library in one fell swoop but is far less transparent than having the library client link libcurl themselves.

from cpr.

niklas88 avatar niklas88 commented on May 6, 2024

But then one would have to make sure that cpr uses the system library as well and not it's local clone so that non-matching versions are easier to discover. Personally I prefer linking with system libraries when available because that means one gets security updates to dynamic libraries but that might not be common on non Linux systems.

from cpr.

whoshuu avatar whoshuu commented on May 6, 2024

There's something to be said for having defaults that almost never fail, and allowing customization beyond that for options that may fail. In my experience, libraries which have no external dependencies are highly preferred -- they're the easiest to get up and running, and C++ is notoriously bad at supporting plug and play libraries.

While I sympathize with your concern, the most important thing for me is to encourage using submodules as the first choice for library integration. This method will have first-class support.

If the library is built separately and included later, extra care must be taken by the integrator to make sure the dependencies are compatible, and I am perfectly okay with this. The library is pretty explicit about which dependencies are used from where, though the documentation could use some work with regard to build options. I'll note this and make a separate issue to address that.

For now, I'm going to limit the scope of this issue to simply having a working cpr-config.cmake file that allows an application developer to integrate a cpr library that's built outside the scope of the application. I think you're in a good position to give me the green light on that, so whenever possible, let me know if this issue is resolved by the latest release branch (30bc418).

from cpr.

niklas88 avatar niklas88 commented on May 6, 2024

Sorry for the delay I'm a bit busy working on my masters thesis. I can confirm it does indeed work wonderfully with my test project now, great work!

from cpr.

HarrisDePerceptron avatar HarrisDePerceptron commented on May 6, 2024

I do not want a submodule. apparently the proj i am working on has all compiled deps system wide and i do not want just this perticular library as a submodule.

Trying to install system wide:

git clone https://github.com/whoshuu/cpr.git
cd cpr
git submodule update --init opt/curl
cmake -DBUILD_CPR_TESTS=OFF ..
make -j
sudo make install

From the root of the project: cd path/to/project
included this at my root CMakeLists.txt:
find_package(CPR REQUIRED)

mkdir build && cd build 
cmake ..

Gives me an error:

[cmake] CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
[cmake] Could NOT find CPR (missing: CPR_LIBRARY CPR_INCLUDE_DIR)

from cpr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.