CPM.cmake
CPM.cmake copied to clipboard
Fetching and making self-built dependencies available
Hi there, thanks very much for the CPM project!
I saw in #271 that you do not support pre-built binaries as CPM is not hosting builds for packages. However, I have a different use case. I have a C++ project that has a number of external dependencies. Currently I have a build system that will compile each dependency separately, and create a zip file with the built library:
usr/lib/somelib.so
usr/include/somelib/myheader.h
I then extract all the archives into the same structure, and then re-zip all files again.
I currently follow these steps for fetching my dependencies:
- Invoke curl through CMake to download the merged zip
- Extract the zip to a dependencies directory
-
set(CMAKE_FIND_ROOT_PATH "${DEPS_ROOT}")
to allowfind_package
to locate cmake modules - I do the following to allow
pkg_check_modules
to locate pkgconfig files
set(ENV{PKG_CONFIG_PATH} "${DEPS_ROOT}/lib/pkgconfig:${DEPS_ROOT}/share/pkgconfig")
set(PKG_CONFIG_EXECUTABLE pkg-config --define-prefix)
- I am then able to use all my dependencies as required.
This is not really an ideal setup though. It would be great if I could use CPM to simplify the management and fetching of this for me, by fetching and extracting the pre-built archive for each separate package into the build directory (i.e. build/deps/<package>
), and setting the required variables to allow cmake and pkgconfig to find the required files.
Is this use-case workable with CPM currently?
Hey, first of all sorry for the very late response!
I'm not sure I understand your requirements completely, but a similar solution I've used before is to upload a zipped directory containing the built libraries and headers as well as a CMakeLists.txt
. The CMakeLists
creates an interface library that is linked to the provided precompiled libraries and includes the provided include directories. When using CPM to download the zip from its URL, the CMakeLists
is automatically loaded, allowing you directly use the interface library in your projects.