CMake 的新手会想知道哪些尘土飞扬的角落? [英] What are the dusty corners a newcomer to CMake will want to know?

查看:21
本文介绍了CMake 的新手会想知道哪些尘土飞扬的角落?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做过很多项目和很多不同的构建系统和 CI 工具.最近,我接触到了为合理大小的 C++ 应用程序添加到基于自动工具的环境的偶尔具有挑战性的任务.虽然我喜欢最终用户的易用性,但我不太喜欢从开发人员方面处理 m4 和所有 auto* 工具.

I've done a lot of projects and a lot of different build systems and CI tools. Most recently, I've been exposed to the occasionally challenging task of adding to an autotools based environment for a reasonably sized C++ application. While I love the ease of use for the end user, I'm not so fond of dealing with m4 and all of the auto* tools from the developer side.

我在业余时间从事一个相当大的副项目,并决定使用 CMake 进行试驾.由于我刚刚开始,我显然计划深入研究文档、常见问题解答、维基等,并边做边学.顺便说一句,我会为掌握 CMake"这本书花钱,但我在亚马逊上找到的评论足以让我决定它可能不值得花钱.话虽如此,在任何新事物中,新人经常会遇到一些陷阱",而老专家早已学会避免这些陷阱".我想知道那些基于人们使用 CMake 的经验是什么,我希望通过在这里提问来减少我的学习痛苦.

I'm working on a reasonably large side project in my spare time and have decided that I'd like to take CMake for a test drive. Since I'm just starting out, I'm obviously planning on digging through the documentation, FAQ, wikis, etc. and learning by doing. BTW, I'd fork over money for the "Mastering CMake" book, but the comments that I found on Amazon were enough to make me decide that it probably isn't worth the money. All that being said, in anything new there are often "gotchas" that a newcomer will often stumble over that the old pros have long since learned to avoid. I'm wondering what those are based on people's experience with CMake, and I'm hoping to cut my learning pains down a bit by asking here.

我应该指出,我计划主要在 Linux 和其他 UN*X 变体上构建.Windows 并不是我的 POV 真正关心的问题.这是一个大型服务器端应用程序,具有用于操作员的 Web 和 CLI 接口、用于自动化/与 OSS 工具集成的北向 REST 接口以及用于 CPE 的 SOAP 南向接口.我将需要大量的第三方库和应用程序才能使这一切正常工作,除非我想在接下来的 10 年里手工构建这一切.:)

I should point out that I'm planning on building on Linux primarily, and other UN*X variants. Windows isn't really a concern from my POV. This is a large server-side application, with a Web and CLI interface for operators, a northbound REST interface for automation/integration with OSS tooling, and a SOAP southbound interface for CPEs. I'm going to need a lot of third-party libraries and applications to get this all to work unless I want to take the next 10 years to build this all by hand. :)

推荐答案

首先,我认为 CMake 是一个出色的构建工具.在我看来,它迄今为止对多平台构建的支持最好,并且具有查找 3rd 方库的强大机制.结合CPack,它甚至提供了合理的打包和安装选项.一些提示和可能的问题:

First of all, I think CMake is an excellent build-tool. It has in my opinion by far the best support for multi-platform-builds and has a powerful mechanism for finding 3rd-party libraries. Combined with CPack it even provides reasonable options for packaging and installation. Some hints and possible problems:

  1. 始终以源外构建为目标:一个显而易见的问题:为源内构建而设计的项目很难在源外构建.因此,如果您可以从一开始就设计它,请瞄准外源构建.

  1. Always aim for out-of-source builds: An obvious one: It can be difficult for a project designed for in-source builds to get it built out-of-source. So, if you can design it from the start, aim for out-of-source builds.

语法:语法可能很奇怪,有很多奇怪的怪癖,尽管从 2.6 和 2.8 版本开始变得更好了.

Syntax: The syntax can be bizarre with a lot of strange quirks, although this is getting better since the 2.6 and 2.8 versions.

缓存变量.CMake 会跟踪变量和设置的缓存,有时在重建某些内容时这可能是一个问题.尝试删除 CMakeCache.txt(或清理源外构建目录)并重建.DarenW也提到了这个.

Caching of variables. CMake keeps track of a cache of variables and settings and sometimes this can be a problem when rebuilding something. Try to remove the CMakeCache.txt (or clean your out-of-source build-directory) and rebuild. This one is also mentioned by DarenW.

查找和配置第 3 方库:如果您有一个依赖于多个库(您自己的或第 3 方库)的大型项目,这可能是最麻烦的.

Finding and configuring 3rd-party libraries: If you have a large project depending on several libraries (your own or 3rd-party), this will likely be the most troublesome.

  • 我强烈建议深入研究 find_package 命令.它非常强大,但完全取决于 FindXXX.cmake 文件的质量.尤其是在多个平台(主要是 Windows 和 Mac)上构建时,这些文件可能需要进行一些调整,或者您可能需要编写自己的文件.

  • I seriously recommend diving into the find_package command. It is very powerful, but fully depends on the quality of the FindXXX.cmake files. Especially when building on multiple platforms (mostly Windows and Mac), these files may require some tweaking or you may need to write your own.

链接库的问题,例如调试未定义的引用"或 debug|release 或 static|shared 之间的不匹配,可能难以调试.特别是对于 3rd 方库,这些问题可能是由不正确的 3rd 方 FindXXX.cmake 文件引起的...

Problems with linking libraries like debugging "undefined references" or mismatches between debug|release or static|shared can be difficult to debug. Especially with 3rd-party libraries these problems may be caused by incorrect 3rd-party FindXXX.cmake files...

这篇关于CMake 的新手会想知道哪些尘土飞扬的角落?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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