Example to build curl (with nghttp2 dependency)
bsergean opened this issue · 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 ?
See also #348
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.
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.
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.
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'.