Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to install library and headers through CMake #191

Closed
whoshuu opened this issue Mar 4, 2017 · 15 comments
Closed

Add ability to install library and headers through CMake #191

whoshuu opened this issue Mar 4, 2017 · 15 comments

Comments

@whoshuu
Copy link
Collaborator

whoshuu commented Mar 4, 2017

There are three competing pull requests right now that implement this. My laziness has unfortunately resulted in some duplicate work 😥 .

#176
#132
#56

Unbiased discussion on the pros and cons of each approach would be appreciated. The immediate goal is to make make install in a sane way. The long term goal is to make packaging the library (for something like Homebrew for instance) feasible so it can be distributed without git.

@nyorain
Copy link
Contributor

nyorain commented Mar 6, 2017

At the moment, there is no (convenient) way to install cpr system-wide which makes it hard to package.
Simply providing install() cmake commands does not help this much since this (as you pointed out in #176) would also install the curl headers and libraries which is bad (might mess up linux package manager if installed in /usr).
They are installed because curl is built using add_subdirectory instad of using a cmake external project or something similar.

But changing this might introduce a couple new problems and makes the whole solution more complex so I am not sure if it is worth it if there is another way (but by doing so it would be possible to switch curl installation via a cmake option I guess).

@apollo13
Copy link
Contributor

Well, installation would still be nice in the cases where for instance system curl is used (which would be done if you wanted to package CPR for debian etc…).

@sim590
Copy link

sim590 commented Jun 23, 2017

Debian and Archlinux packages would be appreciated nice.

@sroycode
Copy link

@0biWanKenobi
Copy link

Dear developer,

I have built CPR successfully, however I have no idea - being quite new to the c\c++ world - how to use it. "sudo make install" just copies curl into usr/local.. I see there are already open issues, so opening one seems to be the wrong way to go about it. Instead, could you provide simple instructions on how to include CPR in one's project? You currently mention git subdirectory and cmakelists, but not everyone has his project under versioning, or is using cmake.

Thanks a lot!

@SamuelKarlos
Copy link

You are not finding this include, what should I do?
#include <cpr/cpr.h>

Please, can anyone help me?
I have already added add_subdirectory (cpr) in CMAKE.list and have the following error:

Could not find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_INCLUDE_DIR)

I have already added openssl to the project, but I can not configure it in CMALKELIST.

@sroycode
Copy link

Hi:
Have a look at
https://github.com/sroycode/identt
where CPR is included as a sub-project which you will find in include/cpr
and src/cpr
there is a CMakeLists.txt in src/cpr , you will need these two lines to include curl + openssl in main CMakeLists.txt

find_package(CURL 7.29 REQUIRED)
include_directories(${CURL_INCLUDE_DIRS})
set(YOURPROJECT_LIB_DEPS ${YOURPROJECT_LIB_DEPS} ${CURL_LIBRARIES})

find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
set(YOURPROJECT_LIB_DEPS ${YOURPROJECT_LIB_DEPS} ${OPENSSL_SSL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES})

Regards
SRC

@SamuelKarlos
Copy link

That's awesome! Thank you!

@SamuelKarlos
Copy link

Hello, I encountered another problem:
the include does not work: #include <cpr / cpr.h>

Debug Result:

/Applications/CLion.app/Contents/bin/cmake/bin/cmake -DCMAKE_BUILD_TYPE = Debug -G "CodeBlocks - Unix Makefiles" / Users / samuelkarlos / Downloads / testCmake

  • Checking compiler flags for C ++ 11 support.

  • C ++ 11 is supported.

  • C ++ Requests CMake Options

  • ================================================================= =======

  • USE_SYSTEM_CURL: OFF

  • BUILD_CPR_TESTS: ON

  • GENERATE_COVERAGE: OFF

  • CPR_CURL_NOSIGNAL: OFF

  • USE_SYSTEM_GTEST: OFF

  • CMAKE_USE_OPENSSL: ON

  • ================================================================== =======

  • Not using system curl, using built-in curl project instead.
    CMake Warning at cpr / opt / curl / CMakeLists.txt: 50 (message):
      the curl cmake build system is poorly maintained. Be aware

  • curl version = [7.56.0-DEV]
    Found * nroff option: - -man

  • Could NOT find LibSSH2 (missing: LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY)

  • Enabled features: OpenSSL IPv6 unix-sockets libz AsynchDNS NTLM

  • Enabled protocols: DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP POP3 POP3S RTSP SMTP SMTPS TELNET TFTP

  • Set CURL_FOUND to TRUE.

  • Set CURL_LIBRARIES to libcurl.

  • Set CURL_INCLUDE_DIRS to / Users / samuelkarlos / Downloads / testCmake / cpr / opt / curl / include; / Users / samuelkarlos / Downloads / testCmake / cpr / opt / curl / include / curl.

  • Not using system gtest, using built-in googletest project instead.

  • Set GTEST_FOUND to TRUE.

  • Set GTEST_LIBRARIES to gtest.

  • Set GTEST_MAIN_LIBRARIES to gtest_main.

  • Set GTEST_BOTH_LIBRARIES to gtest; gtest_main.

  • Set GTEST_INCLUDE_DIRS to / Users / samuelkarlos / Downloads / testCmake / cpr / opt / googletest / include.

  • Building mongoose project for test support.

  • Set MONGOOSE_FOUND to TRUE.

  • Set MONGOOSE_LIBRARIES to mongoose.

  • Set MONGOOSE_INCLUDE_DIRS to / Users / samuelkarlos / Downloads / testCmake / cpr / opt / mongoose.

  • Using CURL_INCLUDE_DIRS: / Users / samuelkarlos / Downloads / testCmake / cpr / opt / curl / include; / Users / samuelkarlos / Downloads / testCmake / cpr / opt / curl / include / curl.

  • Using CURL_LIBRARIES: libcurl.

  • Configuring done

  • Generating done

  • Build files have been written to: / Users / samuelkarlos / Downloads / testCmake

[Finished]

I added add_subdirectory (cpr) to my CMAKELIST.

How to solve this? Please

@SamuelKarlos
Copy link

SamuelKarlos commented Apr 19, 2018

Hello, I was able to solve the above problem, but I came across another problem ...

/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build / Users / samuelkarlos / Downloads / testCmake --target testCmake - -j 4
Scanning dependencies of target testCmake
Building CXX object CMakeFiles / testCmake.dir / src / main.cpp.o
Linking CXX executable testeCmake
Undefined symbols for architecture x86_64:
  "cpr :: Parameters :: Parameters (std :: initializer_list const &)", referenced from:
      _main in main.cpp.o
  "cpr :: Session :: Get ()", referenced from:
      cpr :: Parameters (std :: __ 1 :: allocator ), cpr :: Parameters (std :: __ 1 :: allocator : __ 1 :: basic_string <char, std :: __ 1 :: char_traits , std :: __ 1 :: allocator > &&, cpr :: Parameters &&) in main.cpp.o
  "cpr :: Session :: SetOption (cpr :: Parameters &&)", referenced from:
      void cpr :: priv :: set_option (cpr :: Session &, cpr :: Parameters &&) in main.cpp.o
  "char, std :: __ 1 :: allocator char :: std :: __ 1 :: char_traits , std :: __ 1 :: allocator > const"), referenced from:
      void cpr :: priv :: set_option <std :: __ 1 :: basic_string <char, std :: __ 1 :: char_traits , std :: __ 1 :: allocator > (cpr :: Session &, std: : __ 1 :: basic_string <char, std :: __ 1 :: char_traits , std :: __ 1 :: allocator > &&) in main.cpp.o
  "cpr :: Session :: Session ()", referenced from:
      cpr :: Parameters (std :: __ 1 :: allocator ), cpr :: Parameters (std :: __ 1 :: allocator : __ 1 :: basic_string <char, std :: __ 1 :: char_traits , std :: __ 1 :: allocator > &&, cpr :: Parameters &&) in main.cpp.o
  "cpr :: Session :: ~ Session ()", referenced from:
      cpr :: Parameters (std :: __ 1 :: allocator ), cpr :: Parameters (std :: __ 1 :: allocator : __ 1 :: basic_string <char, std :: __ 1 :: char_traits , std :: __ 1 :: allocator > &&, cpr :: Parameters &&) in main.cpp.o
ld: symbol (s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make [3]: *** [testCmake] Error 1
make [2]: *** [CMakeFiles / testCmake.dir / all] Error 2
make [1]: *** [CMakeFiles / testCmake.dir / rule] Error 2
make: *** [testCmake] Error 2


Here is my sample code:

#include
#include "cube.h"
#include <cpr / cpr.h>

int main (int argc, char ** argv) {

    auto r = cpr :: Get (cpr :: url {"http://www.httpbin.org/get"),
                      cpr :: Parameters {{"hello", "world"}});
    std :: cout << r.url << std :: endl; // http://www.httpbin.org/get?hello=world
    std :: cout << r.text << std :: endl;
}

@tolstenko
Copy link

Have you tried the hunter approach? It is full CMake approach. https://github.com/ruslo/hunter/tree/master/examples/cpr

@pizzard
Copy link

pizzard commented Apr 4, 2019

we had to add
install( TARGETS indurad-util DESTINATION lib OPTIONAL )
at the end of the cpr cmake lists and this fixed all our problems.
We do not build curl but just take it from the system.

Can we just add that routine for the case one uses system lib? Because for that case its that easy.

@HarrisDePerceptron
Copy link

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)

@jungletek
Copy link

jungletek commented Mar 24, 2020

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)

It's telling you right there that you're missing two CMake variables in your CMakeLists.txt (root one): CPR_LIBRARY and CPR_INCLUDE_DIR.

So add this before the find() or find_package() or whatever:


set(CPR_INCLUDE_DIR "path_to_cpr_includes") # can be an absolute path, or relative to the project directory
set(CPR_LIBRARY "path_to_CPR_root/cpr")

If you've already set CPR_DIR, then you can just use that macro as a path reference. Mine looks like this:

set(CPR_DIR "cpr-feature-Stream-MOD")
add_subdirectory(${CPR_DIR} ${CPR_DIR} EXCLUDE_FROM_ALL)
set(CPR_INCLUDE_DIR ${CPR_DIR}/include)
set(CPR_LIBRARY ${CPR_DIR}/cpr)
find_package(CPR REQUIRED)

@COM8
Copy link
Member

COM8 commented Oct 18, 2021

Should be fixed in #645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests