TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Modern CMake short tutorial and best practice

170 点作者 radomir_cernoch将近 7 年前

11 条评论

wheels将近 7 年前
It still boggles my mind that CMake was the thing that won for the next generation of build systems. Its syntax is probably even worse than bash (except that it didn&#x27;t have decades of compatibility to blame that on), making it the single worst language I&#x27;ve ever written code in. I struggle to understand how one could sit down to create a language and come up with something that bad.<p>There was apparently at one point effort to replace its frontend with Lua, but that sadly never took off. (I, like everyone else, still hold my nose and use it, but man ... like ... bwa?)
评论 #17164215 未加载
评论 #17164399 未加载
评论 #17164760 未加载
评论 #17164323 未加载
评论 #17164059 未加载
评论 #17165867 未加载
gravypod将近 7 年前
While CMake is verbose I don&#x27;t think it&#x27;s terrible. The complexity of building a simple flat source project vs a multi-stage build project scales very well. One thing that amazed me was how simple it is to script up the creation of generated libraries.<p>For school I had to generate a build step that would allow me to embed Duktap and link to a library called Glad. Both needed to be generated with a python script. Doing this was dead simple [1]. I didn&#x27;t have to do anything crazy to locate the path to python, the source folders I want to output into, etc. CMake has magic for that.<p>Granted I spent just as much time reading the really horrible docs to find out how to use these magic features as it took me to complete the assignment. I think like many amazing technologies it&#x27;s blocked by a steep learning curve and a long long history of worse ways of doing things. Every time you google for how to do something you&#x27;ll get an answer from a different part of the project&#x27;s lifespan.<p>[1] - <a href="https:&#x2F;&#x2F;github.com&#x2F;gravypod&#x2F;solid-snake&#x2F;blob&#x2F;master&#x2F;CMakeLists.txt#L22-L41" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gravypod&#x2F;solid-snake&#x2F;blob&#x2F;master&#x2F;CMakeLis...</a>
评论 #17163847 未加载
striking将近 7 年前
If you liked this piece, please also consider reading <a href="https:&#x2F;&#x2F;pabloariasal.github.io&#x2F;2018&#x2F;02&#x2F;19&#x2F;its-time-to-do-cmake-right&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pabloariasal.github.io&#x2F;2018&#x2F;02&#x2F;19&#x2F;its-time-to-do-cma...</a>, which is a modern (2018) guide to what you should and should not do in CMake.<p>It&#x27;s very enlightening.
ddevault将近 7 年前
Honestly CMake is just as bad as it&#x27;s predecessors. Today I use meson, which isn&#x27;t perfect but is far better than CMake.
评论 #17164911 未加载
dewyatt将近 7 年前
The generator expression used here isn&#x27;t necessary:<p>add_test(NAME plain-run COMMAND $&lt;TARGET_FILE:vector-test&gt;)<p>You can just use:<p>add_test(NAME plain-run COMMAND vector-test)<p>Since the &lt;COMMAND&gt; is an executable target.
dewyatt将近 7 年前
I also found this to be a decent reference (mostly the videos):<p><a href="https:&#x2F;&#x2F;gist.github.com&#x2F;mbinna&#x2F;c61dbb39bca0e4fb7d1f73b0d66a4fd1" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;mbinna&#x2F;c61dbb39bca0e4fb7d1f73b0d66a4...</a><p>Also, some of the Kitware projects on GitHub.
Koshkin将近 7 年前
While I appreciate the need for DSLs, in many cases I feel like I&#x27;d rather use an API. At least, an API imposes no constraints on the features of the language itself. (So, imagine a DOM for VS solutions and projects; writing your own script would be a breeze...)
waynecochran将近 7 年前
<p><pre><code> Make is horrible because it does not handle spaces in paths </code></pre> Putting spaces in pathnames is idiotic to begin with. I have written Perl scripts that are 3x more complicated just to deal with spaces in pathnames. You might as well blame Make for not handling UTF-32 characters in pathnames -- I mean, someone might want to put a GREEK CAPITAL REVERSED DOTTED LUNATE SIGMA SYMBOL (U+03FF) in their path -- Make would suck if it didn&#x27;t allow this.<p>You missed the most egregious problem with Make -- the fact that commands must begin with a friggin&#x27; TAB! No other whitespace will do. Think of every manual writer who has to somehow convey that the whitespace you (don&#x27;t) see is a TAB.
评论 #17164024 未加载
评论 #17163998 未加载
评论 #17163981 未加载
armitron将近 7 年前
CMake is absolutely terrible if not destructive for non-trivial projects that require frequent build system updates and restructuring (especially those tied to cross-compilation).<p>GNU Make might have its share of issues but compared to CMake, it&#x27;s dead simple and I&#x27;ve never once in 20 years of programming encountered a build issue I could not debug.<p>CMake has had me throw up my hands and give up in despair far too many times. It boggles the mind that people continue to use such a rotten tool. Probably because it looks attractive, superficially, but if one examines it in more detail any possible justifications for using it should completely fall apart.
评论 #17164892 未加载
评论 #17164748 未加载
gkya将近 7 年前
I&#x27;d suggest everyone to check out bmake. It has a very nice standard library of makefiles with which often your makefile can be a couple lines long, one of which just includes the relevant library.
评论 #17164452 未加载
ddavis将近 7 年前
I think it’s recommended to avoid set(...) in modern&#x2F;best practice cmake because it’s global. Use the target_* functions.
评论 #17163877 未加载