CPM.cmake icon indicating copy to clipboard operation
CPM.cmake copied to clipboard

Example to build curl (with nghttp2 dependency)

Open bsergean opened this issue 3 years ago • 6 comments

Hi there,

I am trying to build libcurl and one of its dependency (nghttp2). This sounds like a chicken and egg problem ; nghttp2 needs to be built first, and its header installed, before curl can be 'configured', since at cmake 'configure' time curl is looking for nghttp2 headers.

Is this solvable with cpm ? Should curl CMakefiles themself use a target_link_xxx step so that things gets built in order ?

bsergean avatar Aug 03 '22 16:08 bsergean

See also https://github.com/cpm-cmake/CPM.cmake/issues/348

bsergean avatar Aug 03 '22 16:08 bsergean

Currently CPM.cmake creates custom CMake modules that allow using the standard find_package(nghttp2) to add the library in downstream dependencies. However, curl ships their own FindNGHTTP2.cmake module, which uses find_path(NGHTTP2_INCLUDE_DIR "nghttp2/nghttp2.h") and find_library(NGHTTP2_LIBRARY NAMES nghttp2) to discover the library paths. These assume the library to be installed on the system.

Unfortunately, I'm not sure if there is an easy fix at this point that wouldn't require patching curl's CMakeLists.txt to use the already included library or having an additional build step that installs nghttp in a custom directory and setting the CMake path variables accordingly.

TheLartians avatar Aug 03 '22 22:08 TheLartians

Would if we were to patch our own fork of curl, remove their FindNGHttp2 module so that cpm one is used instead ?

On Aug 3, 2022, at 3:03 PM, Lars Melchior @.***> wrote:

Currently CPM.cmake creates custom CMake modules that allow using the standard find_package(nghttp2) to add the library in downstream dependencies. However, curl ships their own FindNGHTTP2.cmake module, which uses find_path(NGHTTP2_INCLUDE_DIR "nghttp2/nghttp2.h") and find_library(NGHTTP2_LIBRARY NAMES nghttp2) to discover the library paths. These assume the library to be installed on the system.

Unfortunately, I'm not sure if there is an easy fix at this point that wouldn't require patching curl's CMakeLists.txt to use the already included library or having an additional build step that installs nghttp in a custom directory and setting the CMake path variables accordingly.

— Reply to this email directly, view it on GitHub https://github.com/cpm-cmake/CPM.cmake/issues/382#issuecomment-1204532003, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2O6UMXAJTM2IFMMC4CZSDVXLUD7ANCNFSM55PNEEQA. You are receiving this because you authored the thread.

bsergean avatar Aug 03 '22 22:08 bsergean

That's hard to say without really knowing both libraries. TBH it's quite likely that more changes will be needed to the curl build system or even source code, but if you're lucky it may just work. However I still wouldn't recommend it as you'll end up with a custom version of curl that would need to be maintained alongside your own projects.

Depending on your use-case it may be easier to add a meta build script that installs nghttp2 "properly" first.

TheLartians avatar Aug 03 '22 22:08 TheLartians

I think I'm gonna go ahead with the build nghtttp2 approach first.

I noticed that cmake 3.24 has a new 'fetch-content + find_package' integration feature. https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html#fetchcontent-and-find-package-integration

I wonder if this could use to trigger a build from source if find_package cannot find a package, that is to say some sort of recursive/dynamic "resolve dependencies" feature.

bsergean avatar Aug 04 '22 17:08 bsergean

Also I tried to delete/rename the curl FindPackage for nghttp2, which make curl configure step works, but after that curl was built concurrently with nghttp2, too early, and I had a 'cannot find #include <nghttp2/nghttp2.h> error'.

bsergean avatar Aug 04 '22 17:08 bsergean