More about targets

Now add the header file helloworld.h with the following contents to your project:

void heyWorld();

And replace the #include directive with the following line at the top of main.cpp:

#include "helloworld.h"

Finally, replace the line containing std::cout << ... with a call to heyWorld();. Now build your project again.

Let's take a look at CMakeLists.txt – open it by double-clicking on the file in the Projects Toolview. The first line in it defines the project's name. You may define the languages used by the project here – if not defined, they default to C and C++. Take a look at the official documentation for the project command.

So, what have we done? With add_library, we defined a static library which is built from helloworld.cpp. The library may be build from multiple source files, you just have to list them after the STATIC keyword. And with target_link_libraries we tell CMake to link our kdevbook target against kdevbook_lib – as the command name suggests, you can link multiple libraries to one target, again by simply listing the targets.