编程与软件工程cliutils.gitlab.io
现代 CMake 入门
An Introduction to Modern CMake
2018 — 2024,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是一份在线的《现代 CMake 入门》教程,讲解如何用 CMake 3.x 之后的“现代”写法(如 target 为中心、避免全局变量)来组织 C++ 项目的构建系统。作者强调 CMake 官方文档陈旧或缺乏指引,这份免费教程因此成为社区广泛推荐的入门资料。
为什么经久不衰:CMake 文档生态长期碎片化,这份教程由资深从业者维护、持续更新,多年间反复登上 HN 首页,至今仍是学习现代 CMake 用法最常被推荐的起点。
HN 评论精选
认为本教程仍有缺漏,并推荐其他更完整的 CMake 学习材料
我从来没对哪份 CMake 指南满意过:官方书严重过时,官方文档完整但毫无引导,各种博客文档都不成体系,还有些是坏建议。这份没讲依赖图,我觉得这对构建系统很重要,也缺了不少其他内容(不过它是免费的,也说得过去)。我在 KDAB 时写过 CMake 培训材料,自认为那是最好的 CMake 指南。这份现代 CMake 入门应该不错,因为 Steve 是 CMake 的重要贡献者,而且善于讲解。
ahartmetz查看英文原文
Somehow I'm never happy with CMake guides. The official book is ridiculously outdated among other things, the official documentation is complete and current but provides no guidance, and none of the blog-documentation about it gives a complete picture. Some of it is bad advice. This one doesn't talk about the dependency graph, something I consider very important in a build system. It is also missing a lot of other stuff. (Fair enough, it's provided for free.) I wrote the CMake training material for KDAB (www.kdab.com) while I worked there. In my biased opinion it's the best CMake guide around, especially after it was extended and polished by coworkers :). I tried to mix explaining the "inner logic" of a build system, and CMake in particular, with examples, resulting in something I'm reasonably happy with. The main difficulty was ordering the topics to avoid too many forward-references while also not starting with a lot of not-obviously-interesting groundwork [1]. (I don't work there anymore btw, so the interest I have is getting my work used) This intro to modern CMake should be good because Steve is a major CMake contributor and good at explaining. The presentation even contains a dependency graph! https://steveire.wordpress.com/2017/11/05/embracing-modern-cmake/ [1] Aside: I figured that "There are two types of bad software documentation: math textbooks and cooking recipes. The former does not explain why you are doing things and other helpful context, the latter won't help you if you need to do something differently, which is almost always."
批评 CMake 要求项目自带版本兼容样板代码的设计
新项目推荐的兼容性样板代码太繁琐了。应该有办法把这些知识内置到 CMake 本身,而不是要求每个“规范配置”的项目都自己写对这段 cmake_minimum_required 和版本判断的代码——这还没开始写你自己的项目呢。
tux1968查看英文原文
The recommended compatibility boilerplate for new projects is tedious. There must be a way to include this knowledge in cmake itself rather than requiring every "properly" configured project to get this right: cmake_minimum_required(VERSION 3.1) if(${CMAKE_VERSION} VERSION_LESS 3.12) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) else() cmake_policy(VERSION 3.12) endif() This is all before you even start thinking about your own project.
批评教程只讲“怎么做”而不解释 CMake 的执行模型
这份文档和大多数 CMake 文档一样让人恼火:详细讲解显而易见的东西,却对语法背后的执行模型只字不提。学经典 make 时,第一课就是“target 就是个文件,右边是依赖,依赖更新就重新生成命令”。可在 CMake 里怎么做这些?几乎没讲!全是 C++ 文件、库、变量和函数,但它拿这些东西干什么?全是魔法。关于自定义 target 的文档埋在两段话里,甚至没提 CMake 中 target 不等于文件这一点,而这会让 make 老手大吃一惊。
ajross查看英文原文
This has the same kind of infuriating quality that most cmake documentation does. It explains in detail how to do obvious stuff but has nothing to say about what the execution model behind the syntax is. I mean, if you learn classic make, one of the very first things you learn is "this is a target; it's just a file; the stuff on the right are dependencies; the commands below will be run whenever the dependencies are newer than the target". Now, there are implications to learn, but that is the model, and it's obvious: make runs programs to create files when the stuff needed to create the file changes. Now, how do I do that in cmake? It's almost not even here! It's all about C++ files and libraries and how to define variables and write functions and include other cmake files. But what is it going to do with that stuff? It's all just magic. Type it like this and it'll work. Cmake understands your compiler better than you do. What docs there are on creating a custom target are buried in two paragraphs inside a subsection named "Running a command at build time". And it barely tells you how to do this at all (this being a topic I've actually struggled with in the past). In particular it fails to mention that a target is is not the same thing as a file in cmake, and that this has implications that are likely to be surprising to make experts.
指出 CMake 学习资料碎片化,单一教程无法覆盖全部需求
我近几年逐渐上手 CMake,发现不存在单一的好入门材料:CMake 本身在随版本变化;不同形式的资料(网站、幻灯片、视频)侧重不同方面,你可能需要全部看完才能干活;让项目可安装的 CMake 配置极不直观;项目依赖外部代码有五六种方式,无论你选哪种,都得忍受别人用别的方式。所以可以看这份教程,但别指望它够用。
einpoklum查看英文原文
I'm a person who has been easing into CMake use over the past few years. Something I've noticed is that there is no such thing as a single good introduction: * CMake itself is changing. While the "revolution" of modern CMake is upon us already from version 3.0 (or a little earlier), a bunch of thing change with versions 3.12, 3.13 etc. See: https://youtu.be/y7ndUhdQuU8 * Different treatments - a mini-website, PDF presentation or conference video - focus on different aspects of work with CMake, but you probably need most or all of them in focus in order to actually do what you need done. That's how you can see videos entitled "More Modern CMake" and "Oh No! More Modern CMake"... * Setting up the CMake machinery to have your repository/project installed is the opposite of straightforward, and very easy to get confused about. * There are a half-dozen different ways to have your project depend on on other code: External projects, package management CMake modules, relying on other projects being installed in a CMake-idiomatic way and then find_package working, and more. Regardless of which you think is the right one, you'll need to live with others doing something else. So, do follow the link, but don't expect it be sufficient.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选