0

Is it possible to use CMake to have multiple projects/programs (i.e., mains) in the same folder structure? I've been working on learning C by building small console apps, and it would be nice to have a "global" build setup so I can have all the "sub-programs" (i.e., individual console apps) build together, rather than setting up a bunch of individual makefiles and having to go in and make them all individually...

for example, in a folder structure like:

/src
  /utils
    utils.h
    utils.c
  /ch01
    /prog1
      prog1.c
      prog1dep.h
      prog1dep.c
    /prog2
      prog2.c
  /ch02
    /prog3
      prog3.c
      prog3dep.h
      prog3dep.c

where, for example prog1 consists of prog1.c, prog1dep.c, and prog1dep.h (and potentially /utils, a common dependency/utility across a subset of the programs); ideally the executables would build to /build for easier management (i.e., running a specific one, removing, etc.).

For reference, I'm mainly using Linux Ubuntu with gcc compiler.

Apologies in advance for the noob-ish question, I'm just at the point now venturing out of C hello world land and very basic makefiles, but I've heard CMake is more capable for this type of task...Thank you!

  • 3
    `Is it possible to use CMake to have multiple projects/programs` Yes. Just add multiple executables (`add_executable`). – tkausl May 08 '21 at 03:36
  • *I've heard CMake is more capable for this type of task.* Both Make and CMake can easily handle these requirements. Arguably for such a simple task it would be easiest to just use Make directly. – kaylum May 08 '21 at 04:05

0 Answers0