2021-10-05 11:48:15 +00:00
|
|
|
[< Back](../README.md)
|
2021-10-05 11:44:51 +00:00
|
|
|
|
2021-10-05 11:00:57 +00:00
|
|
|
# Exercise: Add files to the build
|
2021-09-29 13:42:04 +00:00
|
|
|
|
|
|
|
In this exercise we will add a couple of files to the project.
|
|
|
|
|
2021-10-05 12:29:27 +00:00
|
|
|
## Background: CMake
|
2021-09-29 13:42:04 +00:00
|
|
|
|
2021-10-05 08:00:50 +00:00
|
|
|
As described in the slides, the project is defined by several CMake files. The ones we are interested
|
2021-10-05 08:15:47 +00:00
|
|
|
is [`CMakeLists.txt`](../../../CMakeLists.txt) in the root project folder and
|
|
|
|
the [`CMakeLists.txt`](../../../lib/CMakeLists.txt) file in the `lib` folder.
|
2021-09-29 13:42:04 +00:00
|
|
|
|
2021-10-05 08:00:50 +00:00
|
|
|
You can see that the root CMake file is adding the `lib` subdirectory, this means that it is looking for
|
|
|
|
a `CMakeLists.txt` file within that folder.
|
2021-09-29 13:42:04 +00:00
|
|
|
|
2021-10-05 08:00:50 +00:00
|
|
|
The CMake file in the `lib` folder describes a few package requirements and then it does this
|
2021-09-29 13:42:04 +00:00
|
|
|
|
|
|
|
```cmake
|
|
|
|
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp" "*.hpp")
|
|
|
|
```
|
|
|
|
|
2021-10-05 08:15:47 +00:00
|
|
|
Here it is creating a CMake variable called `sources` that will contain all `.cpp` and `.hpp` files within the `lib`
|
|
|
|
folder. This means that if we want to add new files, we don't have to list them here, as any applicable files are
|
|
|
|
included. But adding a file will not automatically add the file in the IDE, as CMake needs to be run again for those
|
|
|
|
changes to apply.
|
2021-09-29 13:42:04 +00:00
|
|
|
|
|
|
|
# Exercise
|
|
|
|
|
2021-10-05 08:15:47 +00:00
|
|
|
One of the Pac-Man ghosts is missing. We will fully implement this ghost later but for now let's add the `.cpp`
|
2021-10-05 08:00:50 +00:00
|
|
|
and `.hpp` files to the project.
|
2021-09-29 13:42:04 +00:00
|
|
|
|
2021-10-05 08:15:47 +00:00
|
|
|
1. Create a `Clyde.hpp` in the `lib/include` folder and a `Clyde.cpp` file in the `lib` folder.
|
2021-09-29 13:42:04 +00:00
|
|
|
|
2021-10-05 08:15:47 +00:00
|
|
|
2. Run CMake again and see your IDE update to include these new files. You can try compiling again and see what happens.
|
2021-09-29 13:42:04 +00:00
|
|
|
|
2021-10-05 08:15:47 +00:00
|
|
|
3. Include the `Clyde.hpp` file within the `Clyde.cpp` file, and add `#pragma once` to `Clyde.hpp`.
|
2021-09-29 13:42:04 +00:00
|
|
|
|
2021-10-05 08:15:47 +00:00
|
|
|
4. Include `Clyde.hpp` in [GameState.hpp](../../../lib/include/GameState.hpp) and rebuild
|