The concept of a target
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 you 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, you don't need to write an explicit recipe to compile any object files. All that's required is an add_executable()
command with the name of the executable target and a list of the files that are to be its elements:
add_executable(app1 a.cpp b.cpp c.cpp)
We already used this command in previous chapters and we already know how executable targets are used in practice – during the generation step...