cmake Build Targets Executables


To create a build target producing an executable, one should use the add_executable command:


This creates a build target, e.g. make my_exe for GNU make, with the appropriate invocations of the configured compiler to produce an executable my_exe from the two source files main.cpp and utilities.cpp.

By default, all executable targets are added to the builtin all target (all for GNU make, BUILD_ALL for MSVC).
To exclude an executable from being built with the default all target, one can add the optional parameter EXCLUDE_FROM_ALL right after the target name:

add_executable(my_optional_exe EXCLUDE_FROM_ALL main.cpp)