Author Topic: CMake  (Read 3901 times)

0 Members and 2 Guests are viewing this topic.

Offline westfwTopic starter

  • Super Contributor
  • ***
  • Posts: 4263
  • Country: us
CMake
« on: November 15, 2022, 12:58:54 am »
Is there somewhere a description of sort-of the Philosophy and Purpose of CMake (and how to use it)?

I keep seeing people using CMake to generate Makefiles, when it looks to me like it would have been trivial to generate the makefile manually (at least, if one hadn't created an awful directory structure apparently designed to match the way CMake thinks, or something.)  (cf RPi Pico SDK.)  And I just am not getting it. :-(

 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4637
  • Country: dk
Re: CMake
« Reply #1 on: November 15, 2022, 01:11:37 am »
who wants to write makefiles by hand?
 
The following users thanked this post: newbrain, cfbsoftware

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15095
  • Country: fr
Re: CMake
« Reply #2 on: November 15, 2022, 02:05:04 am »
I only use makefiles. Make is versatile and powerful. And it's like everything else, once you've written makefiles for a few different projects with the structure and features that you want, you can reuse them as templates for other projects, only modifying a few things here and there. It's a bit bizarre to hear people talk about it as though they had to write each of their makefiles from scratch every time, thus spending a lot of time. It doesn't make sense. Once you have covered your bases, it's a matter of a couple minutes for every new makefile - nothing longer than when using CMake. But, you have this initial time investment.

Apart from the syntax, that you get used to pretty quickly, Make is a decent tool.

Most of the criticism (again apart from syntax) I've heard is about dependency handling. Make itself can follow any dependencies you define, but it can't create them on its own (or only in very limited ways), and it's seemingly one of the main reasons new build tools are designed and used. So, if you build C or C++ code, you usually use the compiler to generate dependencies,  GCC for instance have had options to generate Make dependencies for a very long time. For other compilers, that may vary. And, it's always an extra step you need to handle in your makefiles. Again, once you have set up a few makefiles covering your common use cases, it's mostly just a matter of reusing them. But the process may look clunky to many people, and generating dependencies for some other languages can require writing your own tools, which is admittedly not that convenient. And, even for C and C++, generating dependencies using the compiler, while straightforward and fully automatable, can take a pretty long extra time if you deal with big projects. This step is not very optimized.

That is one of the reasons most of these tools are front-ends to Make (or, alternatively, ninja.) Dependencies.

I personally do not use CMake unless I'm forced to, but if you find it useful, go for it. Ultimately it's whatever is most convenient and productive for your use case.
 

Offline AG6QR

  • Frequent Contributor
  • **
  • Posts: 865
  • Country: us
    • AG6QR Blog
Re: CMake
« Reply #3 on: November 15, 2022, 05:58:16 am »
I use CMake in my day job.  I work on a team that develops software that's used for communications across the Internet. The same software must be built to run on Windows, Mac, and more than a dozen varieties of Linux/Unix.  The software has evolved over more than a decade with a large core written in C/C++, plus various bits written in Ruby, Java, and quite a few other languages.  The nice thing about CMake is that we can write the cmakelist.txt file one time and it supports all our platforms.  Before we used CMake, we had different build tools on Windows (dev studio with its project and solution files) than on Mac/Linux/Unix.  Keeping build changes in sync across all platforms has become easier now.
 

Offline westfwTopic starter

  • Super Contributor
  • ***
  • Posts: 4263
  • Country: us
Re: CMake
« Reply #4 on: November 15, 2022, 06:22:44 am »
Quote
Before we used CMake, we had different build tools on Windows [vs Mac/Linux]
How is it easier with CMake?   I have makefiles that work on all three platforms; it wasn't even necessary to install unix-shell-like tools on Windows (though it was easier!)
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8532
  • Country: fi
Re: CMake
« Reply #5 on: November 15, 2022, 06:47:20 pm »
I have never understood the real fundamental purpose of CMake, and no one has been able to properly explain it to me. It seems the only reason to use CMake is because CMake is used, or needs to be used, because someone chose to use CMake.

And make is quite kinda crappy tool for its job, but it gets the job done, not too bad. I don't see how CMake relates, because it's no replacement for make.
 
The following users thanked this post: nfmax

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4637
  • Country: dk
Re: CMake
« Reply #6 on: November 15, 2022, 07:09:43 pm »
I have never understood the real fundamental purpose of CMake, and no one has been able to properly explain it to me. It seems the only reason to use CMake is because CMake is used, or needs to be used, because someone chose to use CMake.

And make is quite kinda crappy tool for its job, but it gets the job done, not too bad. I don't see how CMake relates, because it's no replacement for make.

cmake makes makefiles so of course it is not a replacement ...
 

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
Re: CMake
« Reply #7 on: November 15, 2022, 09:25:39 pm »
Cmake is the reason why I developed myown builder
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 
The following users thanked this post: Ed.Kloonk, Whales, artag

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
Re: CMake
« Reply #8 on: November 15, 2022, 09:37:34 pm »
Quote from: SiliconWizard
GCC for instance have had options to generate Make dependencies for a very long time

I have developed myown dependency builder.
It also checks for deadcode.

My-c independency from everything.
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15095
  • Country: fr
Re: CMake
« Reply #9 on: November 15, 2022, 09:48:43 pm »
Quote from: SiliconWizard
GCC for instance have had options to generate Make dependencies for a very long time

I have developed myown dependency builder.
It also checks for deadcode.

My-c independency from everything.

Ah. That's good!
 

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
Re: CMake
« Reply #10 on: November 15, 2022, 10:09:56 pm »
Gcc, old versions, made me crazy with projrects because didn t behave the same way.
Makefile with kernel v2.4 and <2.6.16 is incompatible with modern tools.

Yet again hours wasted to understand and fix
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline artag

  • Super Contributor
  • ***
  • Posts: 1193
  • Country: gb
Re: CMake
« Reply #11 on: November 15, 2022, 10:21:59 pm »
I don't much like cmake. When it works it's very very good, but when it fails it's horrid.

It's predecessor was autoconf. That was a huge pile of scripts but it was robust. If it broke - which it didn't often do - you could find what was wrong, and  mostly fix it.

Cmake is like the systemd of making. Apparently simpler because there aren't so many bits - but in reality the workings are hard to find, so when it doesn't work it's not easy to fix.

 

Online Whales

  • Super Contributor
  • ***
  • Posts: 2008
  • Country: au
    • Halestrom
Re: CMake
« Reply #12 on: November 15, 2022, 10:58:51 pm »
Every interaction I've ever had with cmake has been trying to fix it on other people's projects.  My eyes glass over as I try and understand the wall of chaos and dependency detection systems.  A programming language to generate a programming language to compile your programming language.

I don't know if cmake is the cause or just a symptom of complex build processes.

Is cmake an operating system?

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15095
  • Country: fr
Re: CMake
« Reply #13 on: November 15, 2022, 11:07:43 pm »
Interestingly, browsing through the official website doesn't necessarily answer your questions: https://cmake.org/ - all they basically say is that you only need to put some text file in each source directory, and bim bam boom. ;D

I also find the "success" page odd: https://cmake.org/success/
As though they were trying to sell something. You usually put those testimonial things when you have something to sell. Right?

« Last Edit: November 15, 2022, 11:10:39 pm by SiliconWizard »
 

Offline switchabl

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: de
Re: CMake
« Reply #14 on: November 15, 2022, 11:33:34 pm »
I really think a big part of the confusion stems from the assumption that CMake is somehow intended as a replacement for Make. It is really more of a replacement for autotools.

CMake does not just manage internal build dependencies, it also manages external library dependencies, e.g. it can check that the correct version of a library is actually available in the build environment and find the correct paths. It also provides an interface for configuring compile time options.

Apart from that, I think one of the central ideas behind CMake is to somewhat decouple the "what" (source files, targets, dependencies etc.) from the "how" (like the actual build system, OS, toolchain, paths and command). The latter could vary wildly for the same project, like you could have a standard make (or ninja) build on Linux, generate Visual Studio projects on Windows and then maybe only later decide to cross-compile for ARM. That also makes it possible for IDEs (and other tools) to understand CMakeLists.txt files and hopefully interpret #includes and #ifdefs correctly for a given target which can improve navigation and code completion quite a bit. And it tends to make life easier for Linux package maintainers too.

It is quite possible that none of that matters to you, and that is completely fine. Many of the features provided by CMake could be hand-coded for each project using Makefiles and maybe some scripts. But for larger and more complex projects that approach doesn't really scale.

Finally, I think a lot of people will use it for smaller stuff too because they are used to it anyway.
 
The following users thanked this post: gmb42, newbrain

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4182
  • Country: gb
Re: CMake
« Reply #15 on: November 16, 2022, 12:32:36 am »
A programming language to generate a programming language to compile your programming language.
I don't know if cmake is the cause or just a symptom of complex build processes.

yup, exactly.
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8532
  • Country: fi
Re: CMake
« Reply #16 on: November 16, 2022, 11:54:46 am »
As though they were trying to sell something. You usually put those testimonial things when you have something to sell. Right?

As you can see from the front page, they are selling support and training.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8532
  • Country: fi
Re: CMake
« Reply #17 on: November 16, 2022, 11:56:12 am »
CMake does not just manage internal build dependencies, it also manages external library dependencies, e.g. it can check that the correct version of a library is actually available in the build environment and find the correct paths.

Which is why I truly cannot understand pushing CMake for embedded microcontroller projects, but I have seen that happen.
 

Offline JohanH

  • Frequent Contributor
  • **
  • Posts: 647
  • Country: fi
Re: CMake
« Reply #18 on: November 16, 2022, 12:03:29 pm »
Cmake is very old (created in 2000). Many open source projects these days seem to move to Meson https://en.wikipedia.org/wiki/Meson_(software)

I haven't really used either (other than messed around with a few projects), so I can't tell which is better, but it sounds like Meson has improved some things. Supposed to be more user friendly (cmake build definitions feel obscure to me).
 
The following users thanked this post: SiliconWizard

Offline JohanH

  • Frequent Contributor
  • **
  • Posts: 647
  • Country: fi
Re: CMake
« Reply #19 on: November 16, 2022, 12:06:34 pm »
And yes, if you have a very simple project it doesn't make sense to use a build system like cmake.
 

Offline Picuino

  • Super Contributor
  • ***
  • Posts: 1027
  • Country: es
    • Picuino web
Re: CMake
« Reply #20 on: November 16, 2022, 04:03:24 pm »
I use makefiles to automate many tasks, not just for compiling programs.
I use them to create compressed project files, automatically create and crop images from PDFs, run Python macros on source files and templates to create final files, create thumbnails, etc.
But better than CMake, I prefer to use GNU Make.

Edit:
https://www.gnu.org/software/make/
https://www.gnu.org/software/make/manual/make.html

And be careful to use tabs instead of spaces !!!
« Last Edit: November 16, 2022, 04:08:26 pm by Picuino »
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15095
  • Country: fr
Re: CMake
« Reply #21 on: November 16, 2022, 06:35:28 pm »
And yes, if you have a very simple project it doesn't make sense to use a build system like cmake.

Sure, but unfortunately, in the embedded world, more and more vendors are switching to CMake for their SDKs, so even for a small project using a modern MCU, you may be faced with CMake.

I have personally run into two such vendors for MCUs that I've used: RPi with the RP2040 and NXP with the iMXRT series. In both cases, the CMake file hierarchies were so intricate that it drove me nuts. In both cases, I wrote my own makefiles for using the SDKs. That took a bit of time (mostly due to figuring out where SDK files were and handling the hierarchy). You can of course do without the SDKs altogether. But while this is absolutely doable for something like the RP2040, good luck with something as complex as a iMXRT106x.
« Last Edit: November 16, 2022, 06:54:11 pm by SiliconWizard »
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15095
  • Country: fr
Re: CMake
« Reply #22 on: November 16, 2022, 06:40:13 pm »
Many open source projects these days seem to move to Meson https://en.wikipedia.org/wiki/Meson_(software)

I have looked at Meson and it seems much better crafted than CMake. As I said, I have no interest in those build tools so far, but it's always nice to have alternatives.
 

Offline switchabl

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: de
Re: CMake
« Reply #23 on: November 16, 2022, 07:50:11 pm »
Sure, but unfortunately, in the embedded world, more and more vendors are switching to CMake for their SDKs, so even for a small project using a modern MCU, you may be faced with CMake.

I have personally run into two such vendors for MCUs that I've used: RPi with the RP2040 and NXP with the iMXRT series. In both cases, the CMake file hierarchies were so intricate that it drove me nuts. In both cases, I wrote my own makefiles for using the SDKs. That took a bit of time (mostly due to figuring out where SDK files were and handling the hierarchy). You can of course do without the SDKs altogether. But while this is absolutely doable for something like the RP2040, good luck with something as complex as a iMXRT106x.

I had the opposite experience a while ago. The (legacy) nRF5 SDK comes with plain Makefiles. But it consists of many small modules that each depend on other modules. In the end I had to:
1. make
2. find each missing include and add path
3. for each linker error find source file that defines the symbol and add to sources
4. goto 1 until build succeeds

And that can take quite a few iterations, so I was really wishing they had used some kind of build system to handle the dependencies. And in fact it turned out someone else was so annoyed by this that they put together... a set of CMake files (https://github.com/Polidea/cmake-nRF5x).
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8532
  • Country: fi
Re: CMake
« Reply #24 on: November 17, 2022, 03:50:10 pm »
But the nRF52 SDK is a total disaster anyway. I tried for a week to make anything happen with it. Didn't get even Hello World working, because that alone meant debugging their 10000-lines-of-code NIH logging library which did not log out of box. Blinking a freaking LED was through a nearly mythological beast called LBS - LEDs And Buttons Service, so no wonder there were a lot of makefiles and a lot of hieararchy. IIRC, just the LED blinker compiled and linked over 200 files. The nRF52 hardware itself is very easy to use.
« Last Edit: November 17, 2022, 03:53:20 pm by Siwastaja »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf