Project Setup

Project Structure

jp-engine/
├── engine/
│   ├── app.cc
│   └── CMakeLists.txt
├── game/
│   ├── main.cc
│   └── CMakeLists.txt
├── CMakeLists.txt
├── .clang-format
├── .clang-tidy
└── .gitignore
  • engine/: This directory will house our game engine's core code.

  • game/: This directory contains the game's executable code, which uses the engine.

  • CMakeLists.txt: This is the top-level CMake configuration, orchestrating the build process.

  • .clang-format: Defines the formatting rules.

  • .clang-tidy: Defines the static analysis rules.

  • .gitignore: Used by git to determine which files or directories to ignore in the source control.

CMake Files

The root CMake script configures the whole build process and adds two sub-directories, engine and game to the build. After that, if found, it attempts to locate the clang-tidy static analysis tool and enables it for both targets.

This CMake script makes available the SFML library via FetchContent and configures a library namedengine. The target requires C++23 and compiler-specific warning flags (extra warnings and no compiler extensions). The engine library is linked against SFML's Audio and Graphics components so that they are available in the code. The parent source directory is added to the include paths so that the C++ includes will look like #include "engine/some_file.h".

This CMake script configures the build process for an executable named game. Most of the compiler flags are the same as the engine ones, except that in the game project, for non-MSVC compilers, in Debug mode, it enables the address and undefined behavior sanitizers for runtime error detection. These are extremely useful for finding memory leaks and undefined behaviour. Finally, the game executable is linked against the engine library. Later, we'll add one more command to this script to copy the resources directory containing the game assets.

Note: As you add more source files to the engine and game projects, remember to also update the add_library and add_executable commands in their respective CMakeLists.txt files. Failing to do so will prevent these new files from being compiled, leading to undefined reference errors during the linking stage.

Source Files

Pretty much empty source files, for now.

Configuration Files

If you don't use some of the following tools, you can skip them.

This YAML file configures the code formatting style for C++ code using clang-format. It is based on the Google C++ style guide.

This YAML file configures the clang-tidy static analysis tool.

And this is the usual .gitignore file used to avoid git tracking the build directory and the code editor-specific config files.

Last updated