Reputation: 2583
I have a cmake project that has a dependency on another library. That other library also uses cmake, but its build steps seem to work more like a standalone project rather than a library. So when my cmake tries to add_subdirectory()
to the library cmake, I get errors such as "CPack.cmake has already been included!!" and "CPack readme resource file could not be found." So, unless there's some clever trick, I'm assuming that add_subdirectory() isn't a realistic option here? What's the best alternative to integrate the building of the library into the building of my project?
A couple ideas that crossed my mind are:
Use custom commands to generate the library's cmake build files on the fly, then more custom commands to kick-off the build.
Just build the library manually and store pre-built binaries with my project for the various os/arch/compiler combinations.
Thoughts?
Upvotes: 3
Views: 902
Reputation: 78458
Probably your best bet is to make use of the ExternalProject
module - specifically the ExternalProject_Add
function.
This will let you do any or all of: download, update/patch, configure, build, install and test the dependent library. It works with any build system, but obviously is particularly suited to work with CMake projects.
If you are looking at doing your option 1 - it might be easier to just look at modifying the other library's CMakeLists.txt to allow it to be included in your own project via add_subdirectory
.
Upvotes: 5