Understanding the concept of a target
If you have ever used GNU Make, you have already seen the concept of a target. Essentially, it's a recipe that a buildsystem follows to compile a set of files into another file. It can be a .cpp
implementation file compiled into an .o
object file, or a group of .o
files packaged into a .a
static library. There are numerous combinations and possibilities when it comes to targets and their transformations within a build system.
CMake, however, allows you to save time and skip defining the intermediate steps of those recipes; it works on a higher level of abstraction. It understands how most languages build an executable directly from their source files. So, you don't need to write explicit commands to compile your C++ object files (as you would using GNU Make). All that's required is an add_executable()
command with the name of the executable target followed by a list of the source files:
add_executable(app1 a.cpp b.cpp c.cpp)
We have...