Cmake项目依赖于cmake项目 [英] Cmake project with dependency on cmake project

查看:1080
本文介绍了Cmake项目依赖于cmake项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个cmake项目对另一个库有依赖。其他库也使用cmake,但它的构建步骤似乎更像一个独立的项目,而不是一个库。所以当我的cmake尝试 add_subdirectory()到库cmake,我得到错误,如CPack.cmake已经包括!和找不到CPack自述文件资源文件。所以,除非有一些聪明的技巧,我假设add_subdirectory()不是一个现实的选择在这里?



我想到的几个想法是:


  1. 使用自定义命令即时生成库的cmake构建文件,然后使用更多自定义命令启动构建。



只要手动建立库并存储预先构建的二进制文件和我的项目为各种os / arch /

想法?

解决方案

可能最好的办法是利用 ExternalProject 模块 - 特别是 ExternalProject_Add 函数。



这将让你做任何或所有的:下载,更新/补丁,配置,构建,安装和测试依赖库。它适用于任何构建系统,但显然特别适合与CMake项目一起工作。



如果你它可能更容易看看修改其他库的CMakeLists.txt,以允许它包含在您自己的项目通过 add_subdirectory


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:

  1. Use custom commands to generate the library's cmake build files on the fly, then more custom commands to kick-off the build.

  2. Just build the library manually and store pre-built binaries with my project for the various os/arch/compiler combinations.

Thoughts?

解决方案

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.

这篇关于Cmake项目依赖于cmake项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆