/CMake-VSCode-SDL-Example

SDL C++ multidirectory startup project using CMake, Google Test and Github Workflows for automated tests run. Contains tasks and configuration for development in Visual Studio Code.

Primary LanguageCMakeMIT LicenseMIT

Description

This is simple startup project using CMake for multidirectory C++ project with SDL, SDL_Image, GoogleTest and Github Workflows for automated tests run.

Prerequisites

On Windows:

  1. Install Mingw-w64
  2. Install cmake
  3. Download SDL development library
  4. Download SDL image development library

How to run

On Windows:

Pre-steps

Update CmakeLists.txt

  1. Rename CMakeLists.txt.example to CMakeLists.txt
  2. Replace [PATH_TO_SDL] in CMakeLists.txt with path where you keep SDL source
  3. Replace [PATH_TO_SDL_image] in CMakeLists.txt with path where you keep SDL source

Update Visual Studio Code configuration

  1. Rename .vscode/c_cpp_properties.json.example to .vscode/c_cpp_properties.json
  2. Replace [PATH_TO_SDL] in .vscode/c_cpp_properties.json with path where you keep SDL source
  3. Replace [PATH_TO_SDL_image] in .vscode/c_cpp_properties.json with path where you keep SDL source

Prepare SDL

  1. Set prefix, SDL2_PREFIX, SDL2_EXEC_PREFIX in sdl2-config.cmake in [PATH_TO_SDL]/lib/cmake/SDL2 directory to [PATH_TO_SDL]
  2. Replace [PATH_TO_SDL_image] in utils/sdl2_image-config.cmake.example
  3. Copy utils/sdl2_image-config.cmake.example to [PATH_TO_SDL_image]/SDL2_image-2.0.5/lib/x64/cmake/sdl2_image-config.cmake (create folder if not exists)
    1. Alternatively you can just rename utils/sdl2_image-config.cmake.example to utils/sdl2_image-config.cmake and point SDL2_image_DIR in CMakeLists.txt to utils folder
  4. Copy SDL2.dll, SDL2_image.dll, libpng16-16.dll, zlib.1.dll to output directory

From terminal:

  1. From root directory run command cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=True -G "MinGW Makefiles" .
  2. Run command mingw32-make.exe
  3. Run executable ./output/game.exe
  4. For tests run executable ./output/test.exe

From VSCode:

To build project from VSCode go to Terminal -> Run Build Task

To debug project in VSCode go to Run -> Start Debugging or Run -> Start without Debugging

Notes

  • Having separate CmakeLists.txt for Github Workflows is probably not the best solution. Although configuring SDL on Windows Workflow Machine seems like tedious task thats why i went with running build on Ubuntu machine with dedicated CmakeLists.txt (stored in .github/workflows/utils) and installing required libraries with apt-get. It probably would be possible to make parameterized cmakelists that would handle all cases.