在CMake中建立依赖 [英] Build dependency in CMake

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

问题描述

我想在我的应用程序中构建和使用静态链接的Botan,这意味着首先

I want to build and use Botan linked statically in my application, which means first

python configure.py --disable shared

跟随

make

然后我想为libbotan创建一个依赖目标。我可以在其余的CMake文件中使用的 libbotan。由于Botan未使用CMake,所以我不确定如何在项目中包含依赖项。

And then I'd like to create a dependency target for libbotan.a as "libbotan" that I can use in the rest of my CMake files. Since Botan not using CMake I'm not sure how to include the dependency in my project.

我当前的尝试如下:



in deps/Botan.1.11.7/CmakeLists.txt

add_custom_command(OUTPUT botan-configure COMMAND ./configure.py --disable-shared)
add_custom_command(OUTPUT botan-build COMMAND make DEPENDS botan-configure)
add_custom_target(botan DEPENDS botan-configure botan-build)

,但是当我像这样将botan作为依赖项添加到core / CMakeLists.txt中时

but when I added botan as a dependency in core/CMakeLists.txt like this

add_executable(console console.cpp)
target_link_libraries(console messages core botan ${Boost_LIBRARIES})

我得到

CMake Error at simpleclient/CMakeLists.txt:5 (target_link_libraries):
 Target "botan" of type UTILITY may not be linked into another target.  One
 may link only to STATIC or SHARED libraries, or to executables with the
 ENABLE_EXPORTS property set.

我尝试使用ExternalProject_Add这样

I tried using ExternalProject_Add like this

ExternalProject_Add(botan
    GIT_REPOSITORY https://github.com/randombit/botan.git
    CONFIGURE_COMMAND python configure.py --disable-shared
    BUILD_COMMAND make
    INSTALL_COMMAND make install
)

但这给了我同样的错误。 / p>

But that gives me the same error.

推荐答案

看看 ExternalProject 模块:


'ExternalProject_Add'函数创建一个自定义目标来驱动
外部项目的
下载,更新/补丁,配置,构建,安装和测试步骤

The 'ExternalProject_Add' function creates a custom target to drive download, update/patch, configure, build, install and test steps of an external project

请注意,这只会创建一个工具目标。也就是说,您可以运行目标来构建库,并且可以将项目目标中的依赖项添加到实用程序目标中。您可以不能,但是直接链接到目标。

Note that this will only create a utility target. That is, you may run the target to build the library and you may add dependencies from your project's targets to the utility target. You can not however link to the target directly.

您仍然需要获取库的路径并手动包含外部项目的目录。由于所讨论的项目似乎并未单独使用CMake,因此这意味着您可以自己编写对 find_library find_path 等,并使用这些调用的结果正确集成依赖项。

You still need to obtain the paths to the library and include directories of the external project manually. Since the project in question does not seem to use CMake by itself, that means writing your own calls to find_library, find_path, etc. and use the results from those calls to properly integrate the dependency.

由于外部项目是作为常规CMake运行的一部分构建的,因此应该很容易通过搜索指定给的安装路径来获取正确的值。 ExternalProject_Add

Since the external project is built as part of your normal CMake run it should be quite easy to obtain the correct values by searching in the install path given to ExternalProject_Add.

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

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