依赖我的CMake C ++项目中基于make的C库的最简洁方法 [英] Cleanest way to depend on a make-based C library in my CMake C++ project

查看:88
本文介绍了依赖我的CMake C ++项目中基于make的C库的最简洁方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究C ++项目(我正在使用CMake),并且需要依赖于这样的C库(但使用的是make):

I'm working on a C++ project (I am using CMake) and need to depend on a C library like this one (but uses make): https://github.com/RoaringBitmap/CRoaring

将该库集成到我的项目中,最干净的方法是什么?

What's the cleanest way for me to integrate that library into my project?

一个选项是将代码导入到我的源代码树中,为该外部依赖项创建CMakeLists.txt并将其用作CMake子模块.但是我不想这样做,因为该项目可能会发展,我只希望该代码作为git子模块的依赖项,而不是真正提交到我的存储库中.

One option is importing that code into my source tree, creating a CMakeLists.txt for that external dependency and using it as a CMake submodule. But I don't want to do that, since that project might evolve, and I just want that code as a git submodule dependency, and not actually committed into my repository.

推荐答案

如果您进入CRoaring的源代码并使用 execute_process 命令:

What you could do is use the build system of make within CMake if you cd into the sources of CRoaring and call external commands within CMakeLists.txt using the execute_process command:

execute_process

使用INSTALL_PREFIX,您可以指示在哪里编译该库,然后cmake将在该库中使用它.

With INSTALL_PREFIX you can indicate where to compile that library and cmake would use it then.

这也意味着,每当触发configure时,make编译就会开始,尽管我想您可以控制一点.如果您想避免 add_custom_command 可以在此方面为您提供帮助,

This also would mean, that the make compilation starts whenever you trigger configure though I imagine that you could control that a bit. If you want to avoid that add_custom_command could help you on this:

add_custom_command

对于Commander Genius,我们在构建Windows版本和使用 icotool 时已经使用了它们,因此可执行文件将应用程序图标嵌入到 exe 中.

For Commander Genius we have using those when building the Windows version and using icotool so the executable gets an application icon embedded into the exe.

另一种选择是使用 ExternalProject ,如Tsyvarev在类似文章中指出的那样:

Another alternative would be using ExternalProject like indicated in the similar post by Tsyvarev:

ExternalProject

但是我不确定该电话是否足够灵活以满足您的需求.但是,它有很多选择.

Yet I'm not sure if that call is flexible enough for your needs. It has a lot of options though.

因此使用CMake的最干净方法实际上取决于您需要为项目做些什么.

So the cleanest way to use CMake really depends on what you need to do for your project.

这篇关于依赖我的CMake C ++项目中基于make的C库的最简洁方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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