Setting Up Dev Environment
#
Setting Up DependenciesIt is highly recommended that the development be done on Linux.
We test all of our builds using Ubuntu 20.04, though any recent linux based OS should work.
This guide will give instructions based on Ubuntu 20.04.
To follow this guide on setting up a dev environment you will need:
- A modern C++ compiler (gcc/clang)
- Ninja Build
- Conan
- LLVM 10.0.1
#
Install CompilerMost systems should already have gcc installed, but just in case, these commands can be used to install gcc.
#
Install ConanConan is used to automatically manage OpenRace's dependencies (except for LLVM). Here are two ways to install Conan.
The easiest way is through python and pip if you already have them installed:
If installing through pip, make sure you have added the install directory to your path.
By default, python installs conan to $HOME/.local/bin/
.
Alternatively, you can also obtain the package binary and install Conan from there:
For more information or examples on installing Conan, see their installation instructions.
#
Install LLVM 10.0.1LLVM will need to be built from source.
There are a lot of CMake options to customize the LLVM build. See LLVM's page on CMake for more options.
The important ones used above are:
LLVM_TARGETS_TO_BUILD="X86"
We only build for the X86 platform to save timeCMAKE_CXX_STANDARD="17"
OpenRace is also using C++17CMAKE_BUILD_TYPE=Release
Builds LLVM in Release mode; use Debug instead to make debugging easierLLVM_ENABLE_PROJECTS='clang;openmp'
Builds clang-10.0.1 and OpenMP together with LLVM; they are required for building test cases-G Ninja
Building using Ninja Build
The rest are just some options set to save time/space when building.
The location LLVM 10.0.1 was installed to will be needed to build OpenRace.
In this guide we saved the install location to an environment variable named LLVM_INSTALL
.
#
Building OpenRaceAs a backup, you may also build from the shell using the following:
The cmake options do the following:
CMAKE_EXPORT_COMPILE_COMMANDS=ON
Produces acompile_commands.json
file in the build directory. Most IDEs can be set up to use this file for neat IDE features.CMAKE_BUILD_TYPE=Debug
Builds the project in debug mode. This makes it is easier to debug if/when issues occur.LLVM_INSTALL=$LLVM_INSTALL
Should point to a directory that LLVM was installed to. See the "Install LLVM 10.0.1" section above.ENABLE_WARNING=ON
Enable compiler warnings while building the project. The enabled warnings can be found here.
#
Running TestsFrom the build directory, run ctest
. This should automatically handle running tests from the correct directory.
Tests can also be executed manually using thebin/tester
executable.
Many of the tests read IR files and are expected to be run from the /tests/data
directory. Keep this in mind if running tests manually.
We use Catch2 for testing. See their documentation for more options on running their tests.
It is expected that all tests will always pass in the main branch of the project.
#
Using clang-formatAll code should be formatted according to the .clang-format
file at the project root.
Coderrect OpenRace adopts Google's C++ Style Guide with some small customizations.
Most IDEs can be set to run clang-format automatically. Check the settings for your IDE on how to set this up.
Worst case, clang format can be run manually on an individual file
Or on the entire project directory (careful to run this from within this project's directory as it will recursively overwrite all files ending in .h or .cpp in this directory and all subdirectories).
#
VSCodeVSCode can be configured to automatically run clang format each time a file is saved if the C/C++ extension installed.
In VSCode's preferences/settings, make sure the following two are set:
- Text Editor -> Formatting -> Format on Save (should be checked)
- Extensions -> C/C++ -> clang_format_path (needs to be set to the path of clang format)
This should ensure clang format is run automatically each time a file is saved.