Skip to content

Latest commit

 

History

History
339 lines (242 loc) · 8.72 KB

31_exercises.md

File metadata and controls

339 lines (242 loc) · 8.72 KB

< Back

31. Introduction

Exercise 310

Set up development environment

Quick install

Windows: Chocolatey

PowerShell run as Admin

iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/mod-cpp/ms-pacman/main/dev/windows.ps1'))
Windows: WinGet

PowerShell run as Admin

iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/mod-cpp/ms-pacman/main/dev/windows_winget.ps1'))
Ubuntu: apt

In case you are missing curl

sudo apt install curl

The run the this script, either from the checked out repo or from GitHub:

DEBIAN_FRONTEND=noninteractive bash <(curl -s https://raw.githubusercontent.com/mod-cpp/ms-pacman/main/dev/ubuntu.sh)

Manual install

Windows
MacOS
  • Install clang by typing xcode-select --install in a terminal and following the instructions
  • Install brew if you haven't already
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Install the build tools
brew install cmake ninja pkg-config
Ubuntu 22.04 or newer

Update:

sudo apt update
sudo apt -y upgrade

General tools:

sudo apt install -y curl git tar unzip zip

Dev tools:

sudo apt install -y autoconf build-essential cmake gdb libtool make ninja-build pkg-config

CMake: For older Ubuntu versions (like 20.04) you probably need to run the up_to_date_cmake.sh script:

bash <(curl -s https://raw.githubusercontent.com/mod-cpp/ms-pacman/main/dev/up_to_date_cmake.sh)

Check CMake version, should be higher than cmake_minimum_required in CMakeLists.txt

cmake --version
cmake version 3.28.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).

Dev dependencies:

sudo apt install -y libfreetype6-dev libgl1-mesa-dev libglu1-mesa-dev libopenal-dev libsndfile1-dev libudev-dev libx11-dev libxcursor-dev libxi-dev libxrandr-dev mesa-common-dev

Compilers

sudo apt install -y clang-12 g++-10

Install Visual Studio Code

You can either download the package for VS Code from the official website or by adding the vscode repository to your distribution's package manager.

Fedora 33 or newer
sudo dnf install ninja-build SFML-devel libXi-devel libX11-devel libXrandr-devel mesa-libGL-devel systemd-devel

Install Visual Studio Code

You can either download the package for VS Code from the official website or by [adding the vscode repository][7] to your distribution's package manager.

FreeBSD 12 or newer
sudo pkg install catch cmake libfmt ninja sfml

Install VS Code

sudo pkg install vscode

Build

VS Code
git clone https://github.com/mod-cpp/ms-pacman.git
cd ms-pacman
code .
  • A dialog will appear saying "Do you trust the authors of the files in this folder?", select "Yes, I trust the authors".
  • You will get a popup in the lower right hand corner asking "Do you want to install the recommended extensions for C++?" - click Install.
  • Click on "No Configure Preset Selected" on the bottom status bar
  • In the dropdown that appears select
    • x64-windows on Windows
    • linux-gcc on Linux
    • macos on MacOS
  • Build by clicking on "Build" button on the bottom status bar.
  • Wait until build is finished, it might take a while the first time because it is downloading and building the dependencies as well.
  • Click on flask icon on the left vertical bar to open the test panel
  • Run the tests by clicking on the run button on top of the test panel
  • Run the game by clicking on the play button on the bottom status bar
  • Select ms_pacman in the dropdown
  • To debug, click on the play button with a bug on it on the left vertical bar to open the debug panel
  • Then click the play button on the top of the panel to run in the debugger.
Commandline

Example for Ubuntu using the preset linux-gcc, for other platforms use the appropriate preset, see CMakePresets.json.

git clone https://github.com/mod-cpp/ms-pacman.git
cd ms-pacman
cmake --preset linux-gcc -DCMAKE_BUILD_TYPE=Debug # configure
cmake --build --preset linux-gcc-build --config Debug # build
ctest --preset linux-gcc-test -C Debug # run tests

Example for Windows using the preset x64-windows:

git clone https://github.com/mod-cpp/ms-pacman.git
cd ms-pacman
cmake --preset x64-windows -DCMAKE_BUILD_TYPE=Debug # configure
cmake --build --preset x64-windows-build --config Debug # build
ctest --preset x64-windows-test -C Debug # run tests
CLion
  • Clone project through "Get from VCS": https://github.com/mod-cpp/ms-pacman.git
  • In the "Open Project Wizard" unselect "Enable profile" for the "Debug" profile
  • Select the profile(s) appropriate for your platform, example x64-windows-build for Windows 64 bit
  • Enable the profile by checking the checkbox "Enable profile"
  • Check the checkbox at the top of the dialog "Reload CMake project on editing CMakeLists.txt or other CMake configuration files"
  • Click "OK"
  • (If CLion created a cmake-build-debug folder you can safely delete it, we will be using the build directory)
  • If you need to get back to this dialog, open Settings and go to: Build, Execution, Deployment > CMake
  • On the bottom of the CLion window you will see a tab called CMake
  • To reload CMake fully, click on it and click on the cog wheel and select "Reset Cache and Reload Project"
  • To run ms_pacman press the green play button at the top right of the window
  • To run in debug press the bug button to its right
  • To run the tests click on the dropdown to its left and select All CTest and then either the run or the debug button.

Troubleshoot

All

After installing the build tools, you may have to reboot your IDE and/or your Linux session if you encounter any errors such as Ninja not being found by VSCode.

Ubuntu 18.04

Get g++-10 on Ubuntu 18.04

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt install g++-10
Ubuntu 22.04 on WSL

There seems to be a bug in gzip under WSL: https://askubuntu.com/questions/1417255/trying-to-unzip-a-tgz-in-wsl-but-get-elf-not-found-error

Arch Linux

If there are opengl driver errors, try running in software mode

Windows
  • If you have issues with using VSCode, start it from the "Developer Command Prompt for VS 2022"
  • (Windows Defender dialog for VSCode: "Allow access")

Enable a test and make it green

Solution
TEST_CASE("Exercise 311 : Enable a test and make it green", "[31]") {
  REQUIRE(true == true);
}

Make both asserts run (distinguish between REQUIRE and CHECK in Catch2)

Solution
TEST_CASE("Exercise 312 : Make both asserts run (distinguish between REQUIRE and CHECK in Catch2)", "[31]") {
  CHECK(true == true);
  CHECK(true == true);
}