The Concept of a Target

Let's learn about some general target concepts.

If you have ever used GNU Make, you will have already seen the concept of a target. Essentially, it's a recipe that a buildsystem uses to compile a list of files into another file. It can be a .cpp implementation file compiled into an .o object file, a group of .o files packaged into an .a static library, and many other combinations.

CMake, however, allows us to save time and skip the intermediate steps of those recipes; it works on a higher level of abstraction. It understands how to build an executable directly from source files. So, we don't need to write an explicit recipe to compile object files. All that's required is an add_executable() command with the name of the executable target and a list of .cpp files (it can consist of a single .cpp file) that are to be its elements:

Get hands-on with 1400+ tech skills courses.