taocpp / taopq

C++ client library for PostgreSQL
Boost Software License 1.0
264 stars 40 forks source link

CMake - ExternalProject usage as an example #40

Closed koniarik closed 3 years ago

koniarik commented 3 years ago

Hi,

I like your library, but it's problematic to get it installed. I am playing a lot with getting cmakes ExternalProject_Add to download it,compile it and link/include it.

DO you have any such setup? Could you share it as an example of how to "install" this?

skaae commented 3 years ago

Dont know if this will help you, but i use the following to compile taopq on ubuntu 20.04 with clang 10. I think the postgres paths will change if you are on another system.

apt install libpq-dev
...
LIB_FOLDER=path_to_put_lib
git clone https://github.com/taocpp/taopq.git 
cd taopq && mkdir build && cd build
cmake -DCMAKE_CXX_STANDARD=20 -DCMAKE_BUILD_TYPE=Release -DPostgreSQL_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu -DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql -DPostgreSQL_INCLUDE_DIR=/usr/include/postgresql -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true -DCMAKE_INSTALL_PREFIX="${LIB_FOLDER}"
cmake --build . --target install

and then from make you can find the package with

find_package(taopq REQUIRED PATHS ${replace_with_our_path_do_lib}/lib/lib/cmake NO_DEFAULT_PATH)

and use taocpp::taopq as link target in target_link_libraries. I also add ${replace_with_our_path_do_lib}/lib to target_include_directories, not really sure if the last step is the best way to do this.

koniarik commented 3 years ago

After some digging around, I realized that ExternalProject ias bad choice and used this FetchContent stuff:

include(FetchContent)
set(PostgreSQL_TYPE_INCLUDE_DIR /usr/include/postgresql/)
FetchContent_Declare(
   taopq-build
   GIT_REPOSITORY https://github.com/taocpp/taopq
   GIT_TAG main
)
FetchContent_MakeAvailable(taopq-build)

and than taopq target is available to me. This seems most appropiate? (as it is in the end quite simple)

d-frey commented 3 years ago

Looks good to me, although I'm not a CMake expert. And thanks for sharing this, I might include it into the documentation when I get to it.

uilianries commented 3 years ago

Totally forgot this one, sorry, checking it right now.

uilianries commented 3 years ago

@SquirrelCZE I would suggest you using conan.io to install taocpp projects. All projects are already packaged there, it's totally compatible with cmake, and prebuilt binaries are available too.

TaoPQ: https://conan.io/center/taocpp-taopq

How to install: conan install taocpp-taopq/20200222@

Please, read https://docs.conan.io/en/latest/getting_started.html#getting-started, which there is an example using Poco as external dependency.

So what's the problem using CMake as dependency manager? CMake works pretty well for building, no doubt, however, it doesn't consider many variables and deep dependencies graph.

d-frey commented 3 years ago

@uilianries The version in Conan looks really outdated, it hasn't been updated for quite some time (or am I reading the 20200222 wrong?). As I am working towards a first tagged release, I would think users are currently better off by using the "main" branch for now, even if I might break a few things here and there 😆

uilianries commented 3 years ago

@d-frey Yeah :sweat_smile: Let me update that version on Conan

uilianries commented 3 years ago

Done: https://github.com/conan-io/conan-center-index/pull/6572

koniarik commented 3 years ago

@SquirrelCZE I would suggest you using conan.io to install taocpp projects. All projects are already packaged there, it's totally compatible with cmake, and prebuilt binaries are available too.

TaoPQ: https://conan.io/center/taocpp-taopq

How to install: conan install taocpp-taopq/20200222@

Please, read https://docs.conan.io/en/latest/getting_started.html#getting-started, which there is an example using Poco as external dependency.

So what's the problem using CMake as dependency manager? CMake works pretty well for building, no doubt, however, it doesn't consider many variables and deep dependencies graph.

Cmake so far works well for the use case "get this from this repo", also this one way does not have to push maintainer to update his package in conan :)

I don't want to introduce another mechanism into the project because of just one dependency. Especially because this alternative work just fine.

P.S: and contrary to it's popularity, my experience with conan is not so good, or at least with the packages I wanted to get from it which was not possible to compile. (Which is propably problem with the maintainer of the package, rather than conan)

uilianries commented 3 years ago

also this one way does not have to push maintainer to update his package in conan :)

There is no "maintainer", it's update by the community. Anyone can update.

I don't want to introduce another mechanism into the project because of just one dependency. Especially because this alternative work just fine.

I understand your concern. I'll update the documentation, using FetchContent_Declare.

P.S: and contrary to it's popularity, my experience with conan is not so good, or at least with the packages I wanted to get from it which was not possible to compile. (Which is propably problem with the maintainer of the package, rather than conan)

You still can open an issue to Conan explaining your situation, the community will help you there. Also, there is a Slack channel where people quickly help each other:

koniarik commented 3 years ago

Ah, good to know all that, thanks!