My go-to setup for a C++ project (after Hanno Hildenbrandt and Richel Bilderbeek). It has two important features:
- It uses CMake to be able to build on multiple platforms
- It comes into two flavors, user and developer. The user-configuration does the minimum to give the user a working program. The developer-configuration also builds all the tests and downloads (with vcpkg) the necessary libraries (here Boost.Test) to do so.
Important: Replace setupp
with the name of your project wherever needed.
Here are instructions to build with CMake, but you can compile the source code with the tools of your choice. Here we are building as user. All of the build details should be saved in the ./build/
folder during the building process.
(Click here to build as developer.)
In the terminal:
git clone git@github.com:rscherrer/setupp.git
cd setupp
cp CMakeLists_user.txt CMakeLists.txt # user configuration
mkdir build && cd build
cmake ..
cmake --build .
The executable setupp
is built in ../bin/
.
In the command prompt:
git clone git@github.com:rscherrer/setupp.git
cd setupp
copy CMakeLists_user.txt CMakeLists.txt :: user configuration
mkdir build
cd build
cmake ..
cmake --build . --config Release
The executable setupp.exe
is built in ../bin/
.
(Click here to build on the Peregrine cluster --- replaced by Habrok in 2023.)
(Click here to build on the Habrok cluster.)
Many IDEs such as VisualStudio or XCode support CMake out of the box. "Open folder" should do the trick... You can use CMake to generate the input files for your favorite IDE too (here a MacOS example):
git clone git@github.com:rscherrer/setupp.git
cd setupp
cp CMakeLists_user.txt CMakeLists.txt # user configuration
mkdir build
cd build
# Generate VisualStudio project files
cmake -G "Visual Studio 17 2022" -A x64 ..
# Generate Xcode project files (Xcode must be installed)
cmake -G Xcode
This will place the project files in ../build
.
In all the examples above you will notice that we specify:
cp CMakeLists_user.txt CMakeLists.txt
This is to make sure to build the fast, optimized, release version of the program. This is important as the developer (debug) version is not optimized and requires extra libraries to run all the tests, so it should not be used by the user.