7 ms·
An Introduction to Modern CMake
- hulitu 3y ago[flagged]
- jjkosni 3y agoCMake <= 2.8
- hoangkplog 3y agoStop posting dump comments like this
- gkbrk 3y agoIf you read 7 sentences further than the title, the author explain what they meant by "modern" CMake. > Not CMake 2.8 though; that was released before C++11 even existed! > Modern CMake. CMake 3.5+, maybe even CMake 3.28+ Surely one can see that a tutorial written for CMake 1.0 and CMake 3.28 might have different content.
- jjkosni 3y agoThis document seems antique, judging from the referenced talks and CMake versions
- _mlbt 3y agoThe C++ community moves slowly for the most part, particularly when it comes to tooling like build systems. From a quick glance most of it looks pretty relevant to me.
- SAI_Peregrinus 3y agoYep. Anything less than 10 years old is new & untested, anything less than 20 years old is new but probably decently common. Give a tool about 40 years to reach mass adoption (to the point that earlier tools aren't seen often).
- highfrequency 3y agoFeel free to link to a more up-to-date tutorial
- henryiii 3y agoOr update things that are dated now. I’ve been mostly keeping the max version up to date but haven’t bumped the min version yet. I’d like to make it 3.11 or 3.15 in the near future.
- Pinus 3y agoIs there a good introduction to CMake for those of us on the receiving end, i.e., we’re trying to build a package, maintained by someone else, which uses CMake? Things like how to tell it where to find this other package that I just built (and which is not in /usr/local!), how to get proper @rpath:s installed in my .dylibs on macOS, etc?
- SAI_Peregrinus 3y agoCmake's built-in find_package[1] often[2] just ends up using pkg-config[3] under the hood. There are a bunch of environment variables you can set to add more search paths, either to pkg-config or to CMake Find scripts. If a library isn't packaged for CMake or pkg-config, you can write a CMake package and add it to your user package registry[4]. This is, of course, a massive pain in the ass, but C & C++ library packaging is about twelve different kinds of massive pain in the ass, and CMake is easier to write than a lot of the other packaging formats, so this is a small part of it. [1] https://cmake.org/cmake/help/latest/command/find_package.html https://cmake.org/cmake/help/latest/command/find_package.htm... [2] https://cmake.org/cmake/help/latest/module/FindPkgConfig.html#module:FindPkgConfig https://cmake.org/cmake/help/latest/module/FindPkgConfig.htm... [3] https://www.freedesktop.org/wiki/Software/pkg-config/ https://www.freedesktop.org/wiki/Software/pkg-config/ [4] https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html https://cmake.org/cmake/help/latest/manual/cmake-packages.7....
- helloiamsomeone 3y ago> find_package often just ends up using pkg-config find_package() is just a souped-up include(). What happens once it finds the script matching the criteria provided by arguments and cache variables depends entirely on the script(s) (plural, because version criterion is satisfied by the *ConfigVersion.cmake script for config mode search) it runs. The PkgConfig module is only mentioned in a couple of CMake provided find modules: >find -maxdepth 1 -type f -name "Find*.cmake" -not -name FindPkgConfig.cmake -exec ugrep -HFe PkgConfig {} + | cut -d: -f1 | sort | uniq | sed s/..//;s/\.cmake// FindBLAS FindCURL FindCurses FindEXPAT FindFontconfig FindGLUT FindGSL FindGnuTLS FindImageMagick FindLAPACK FindLibXml2 FindLibXslt FindLibinput FindMPI FindOpenSP FindOpenSSL The prevalent method of discovering packages is via the package provided config scripts, which of course have to come from upstream. Kitware stopped adding new find modules, because they are not worth the maintenance effort (e.g. find modules require maintaining a list of versions like for Python or Boost) and instead upstreams should provide a proper CMake package. pkg-config also really only works in the Linux bubble. CPS[1] is trying to bridge the gap here if you are interested. [1]: https://github.com/cps-org/cps https://github.com/cps-org/cps
- cassepipe 3y agoMy usual comment shilling for xmake in any build system conversation, that's how much I like it : https://xmake.io/#/ https://xmake.io/#/
- sebtron 3y agoUnrelated, but why do so many modern tools tell you to curl | sh to install them? It feels so wrong to run random code from the web. Surely "get the files from here and run install.sh" is not a hard instruction to follow for a developer, right?
- jcelerier 3y ago... What's the actual difference between these two cases in terms of security ? Downloading install.sh from Firefox won't be magically safer than downloading it from curl and I'm not going to read 2k lines of shell script every time I install a new version of cmake on a new machine
- sebtron 3y agoWhat's an install script doing in 2k lines? If it is a reasonable size, I would definitely skim through it to check that it does not mess up with my environment. Or at least that it is not an obviously malicious script.
- acdha 3y agoOkay, so what happens next? It downloads and installs something which you almost certainly aren’t auditing before you install it. If you don’t trust their installer, you shouldn’t trust their code. The reason why a vocal subcommunity gets hung up on “curl | sh” is that they aren’t comfortable accepting the degree of trust which they’re placing in so many third parties but haven’t fully accepted the implications. Saying “download the file and open it manually” is basically the same as the TSA making you throw out a water bottle – it feels like diligence even though it’s pointless. This is why most security people are focused on things like pervasive sandboxing to contain the damage when someone makes a mistake, code-signing and revocation, and trusted third-party providers (e.g. a Linux distribution or App Store) which are more trustworthy and can possibly do things like audit every binary they ship.
- a-french-anon 3y agoI'll use "modern" and "CMake" in the same sentence once I can have true functions and not just procedures; give me a `set -u` equivalent, while at it.
- helloiamsomeone 3y ago> give me a `set -u` equivalent --warn-uninitialized and -Werror=dev will do just that: https://cmake.org/cmake/help/latest/manual/cmake.1.html https://cmake.org/cmake/help/latest/manual/cmake.1.html
- mdaniel 3y agoI wanted to shout out to $(cmake --system-information) <https://cmake.org/cmake/help/v3.29/manual/cmake.1.html#cmdoption-cmake-system-information https://cmake.org/cmake/help/v3.29/manual/cmake.1.html#cmdop...> that I discovered yesterday and really goes a long way toward helping to understand what cmake sees about the world. I don't offhand know what version introduced it, but in terms of "modern" cmake it's the one that comes with Homebrew
- henryiii 3y agoFeel free to make a MR, that sounds like a good tip. :)
- amadio 3y agoNice to see cliutils trending. Henry really understands CMake, so advice by him is always good to follow. I'm not a big fan of CMake, but after years of suffering, I mean, experience, I've learned how to use it relatively well. One feature I like is the "dashboard" model of ctest. It's somewhat painful to setup, but once you have it working, it makes your life building and testing your project much easier. Unfortunately, when I posted it nobody noticed, but if you want to have a really simple CI setup for your CMake project, checkout this link: https://news.ycombinator.com/item?id=39657703 https://news.ycombinator.com/item?id=39657703 See the CI workflow using my script here: https://github.com/xrootd/xrootd/blob/master/.github/workflows/CI.yml https://github.com/xrootd/xrootd/blob/master/.github/workflo... Also, with some advice from Henry I wrote a nice new setup.py for the Python bindings of XRootD integrated with the CMake build. I didn't want a dependency in scikit-build in the end, but his advice helped me a lot.