3
AvyChanna
38d

Today I fell in love with cmake. Dunno why everybody hates it.

Comments
  • 4
    Because you have to learn a config instead of just writing what should be compiled by which commands.

    Makefile ftw.
  • 4
    @nitwhiz cmake can write those commands for me, that too with cross platform suppprt. Plus I find cmake more readable than make

    The last line is a personal opinion. I've been using make for years, and readability drops with the number of files in source. I still use make for smaller builds
  • 1
    @AvyChanna genuine interest: does cmake limit you to gcc/g++ or could you wrap other tasks (say docker run, rm -rf, unzip, whatever) with it?
    Does cmake even work like make, as in you call cmake <target> or does it solely work with compilers on source files?
  • 0
    @nitwhiz If every compiler would take the same flags, headers and libraries are always at the same location (and installed) and every platform would behave the same, then yes, makefiles would be superior. But on fortunately this isn't the case and my software should work on BSDs, Linux and Windows without 5 different make files.
  • 0
    @sbiewald you solve that with some flags in the makefile
  • 1
    @nitwhiz cmake initiates your actual build. On linux, it will generate a makefile. On windows, it will make a VS sln project. You can add custom outputs/commands for building, or even prebiild/postbuild.

    Basically, you call cmake to make a makefile, and then you run that makefile manually to get the desired result(and it has targets like all/build/clean/install/your custom targets)

    Edit: You dont need to add flags. You just specify libname and it automatically links to it.
  • 1
    @matt-jd Huh? Do you mind giving an example, especially for Windows/Linux compatibility? Visual studio (which is the most used compiler on Windows) is "a bit" different and I would generally like to write a build instruction that works compiler agnostic (extra work for very specific things like hardening flags are okay).
    How do I do "header testing", e.g. if a functionality can be in one or more headers at different locations?
Add Comment