Skip to content

Commit c92c3ca

Browse files
committed
Setup project
0 parents  commit c92c3ca

File tree

8 files changed

+220
-0
lines changed

8 files changed

+220
-0
lines changed

.clang-format

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: LLVM
4+
AlwaysBreakTemplateDeclarations: Yes
5+
BreakBeforeBraces: Attach
6+
ColumnLimit: 160
7+
SpaceAfterTemplateKeyword: true
8+
Standard: c++20
9+
TabWidth: 4
10+
IndentWidth: 4
11+
IndentRequires: true
12+
UseTab: Always
13+
AllowShortEnumsOnASingleLine: true
14+
AllowShortCaseLabelsOnASingleLine: true
15+
AllowShortFunctionsOnASingleLine: All
16+
AllowShortLambdasOnASingleLine: All
17+
AllowShortBlocksOnASingleLine: Always
18+
AllowShortIfStatementsOnASingleLine: Always
19+
AllowShortLoopsOnASingleLine: true
20+
IncludeCategories:
21+
# Headers in <> with .hpp extension.
22+
- Regex: '<([A-Za-z0-9\/-_])+\.hpp>'
23+
Priority: 1
24+
# Headers in <> with .h extension.
25+
- Regex: '<([A-Za-z0-9\/-_])+\.h>'
26+
Priority: 10
27+
# Headers in <> without extension.
28+
- Regex: '<([A-Za-z0-9\/-_])+>'
29+
Priority: 20
30+
PointerAlignment: Left
31+
...

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[*]
2+
insert_final_newline = true
3+
charset = utf-8
4+
indent_size = 4
5+
indent_style = tab
6+
# Optional: git will commit as lf, this will only affect local files
7+
end_of_line = lf
8+
9+
[*.{py,md,yml,sh,cmake,txt}]
10+
indent_style = space
11+
indent_size = 2
12+
13+
[*.{py,md,yml,sh,cmake,txt}.in]
14+
indent_style = space
15+
indent_size = 2

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
**/.vs/*
2+
**/.vscode/*
3+
**/.idea/*
4+
build/*
5+
out/*
6+
.cache
7+
.DS_Store
8+
9+
CMakeSettings.json
10+
compile_commands.json
11+
/CMakeUserPresets.json
12+
13+
wiki

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.18)
2+
3+
enable_language(CXX)
4+
5+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
6+
set(CMAKE_DEBUG_POSTFIX "-d")
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
set(CMAKE_CXX_STANDARD 20)
9+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
11+
12+
project(tray)
13+
14+
add_subdirectory(tray)

CMakePresets.json

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"version": 2,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 20,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "default",
11+
"description": "Build configuration using Ninja Multi-config",
12+
"generator": "Ninja Multi-Config",
13+
"binaryDir": "${sourceDir}/out/default",
14+
"cacheVariables": {
15+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
16+
}
17+
},
18+
{
19+
"name": "ninja-clang",
20+
"description": "Build configuration using Ninja Multi-config / clang",
21+
"inherits": "default",
22+
"binaryDir": "${sourceDir}/out/clang",
23+
"cacheVariables": {
24+
"CMAKE_C_COMPILER": "clang",
25+
"CMAKE_CXX_COMPILER": "clang++"
26+
}
27+
},
28+
{
29+
"name": "ninja-ubsan",
30+
"description": "UBSan build configuration using Ninja Multi-config",
31+
"inherits": "default",
32+
"binaryDir": "${sourceDir}/out/ubsan",
33+
"cacheVariables": {
34+
"CMAKE_CXX_FLAGS": "-fsanitize=undefined"
35+
}
36+
},
37+
{
38+
"name": "vs19",
39+
"description": "Build configuration using Visual Studio 16 (2019)",
40+
"generator": "Visual Studio 16 2019",
41+
"binaryDir": "${sourceDir}/out/vs",
42+
"architecture": {
43+
"value": "x64",
44+
"strategy": "external"
45+
}
46+
},
47+
{
48+
"name": "vs22",
49+
"description": "Build configuration using Visual Studio 17 (2022)",
50+
"inherits": "vs19",
51+
"generator": "Visual Studio 17 2022"
52+
},
53+
{
54+
"name": "pre-install",
55+
"description": "Debug build using Ninja Multi-config and install prefix",
56+
"inherits": "default",
57+
"binaryDir": "${sourceDir}/out/pre",
58+
"cacheVariables": {
59+
"CMAKE_PREFIX_PATH": "${sourceDir}/out/install",
60+
"RR_PREINSTALLED": "ON"
61+
}
62+
}
63+
],
64+
"buildPresets": [
65+
{
66+
"name": "Debug",
67+
"configurePreset": "default",
68+
"configuration": "Debug"
69+
},
70+
{
71+
"name": "Release",
72+
"configurePreset": "default",
73+
"configuration": "Release"
74+
},
75+
{
76+
"name": "RelWithDebInfo",
77+
"configurePreset": "default",
78+
"configuration": "RelWithDebInfo"
79+
}
80+
],
81+
"testPresets": [
82+
{
83+
"name": "Debug",
84+
"configurePreset": "default",
85+
"configuration": "Debug"
86+
},
87+
{
88+
"name": "Release",
89+
"configurePreset": "default",
90+
"configuration": "Release"
91+
},
92+
{
93+
"name": "RelWithDebInfo",
94+
"configurePreset": "default",
95+
"configuration": "RelWithDebInfo"
96+
}
97+
]
98+
}

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# tray
2+
3+
**Basic offline CPU ray-tracer using (only) C++20**
4+
5+
`tray` is a "tutorial project", structured such that it progresses linearly and is easy to follow along, but is also fully runnable at any tag / commit (on `main`). The wiki has chapters corresponding to a tag / branch each, which can be checked out as a "snapshot" to follow along / experiment with.
6+
7+
## Requriements
8+
9+
1. CMake 3.18+
10+
1. C++20 compiler and standard library / runtime
11+
12+
## Development
13+
14+
The project is developed on Linux using VSCode with the CMake Tools extension, though it is designed to be agnostic to individual workflows. Regardless of OS / IDE / editor of choice, make sure the debugger works once the build has been setup, that you can set breakpoints, watch/change variables, etc.
15+
16+
### Linux
17+
18+
If using VSCode and CMake Tools, just open the root directory, select `CMake: Configure` from the command palette, pick a preset (`default` or `ninja-ubsan` are best for debugging), and get started. Use `CMake: Build` and `CMake: Debug` / `Ctrl + F5` subsequently as needed.
19+
20+
For other IDEs / workflows, use CMake to configure a preset and/or a custom a build directory and then use that.
21+
22+
### Windows
23+
24+
The most straightforward approach would be to use Visual Studio in CMake mode: install the appropriate tools, then simply open the root folder in the IDE, it should detect the CMake script and switch to that mode. Configure, build, debug as usual.
25+
26+
Alternatively, use CMake to generate a Visual Studio solution offline, then open and use that. You'll have to regenerate the solution every time the CMake script changes - since VS would be unaware of its existence.
27+
28+
Using VSCode etc with Ninja / clang++ is also an option: follow the same steps as in the [Linux](#Linux) section.
29+
30+
### CLI
31+
32+
Use CMake:
33+
34+
```
35+
cmake -S . --list-presets # list all configure presets
36+
cmake -S . --preset=<preset> # configure using desired configure preset
37+
cmake --build --list-presets # list all build presets
38+
cmake --build --preset=<preset> # build the desired build preset
39+
```
40+

tray/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_executable(${PROJECT_NAME})
2+
target_sources(${PROJECT_NAME} PRIVATE src/main.cpp)
3+
4+
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang OR CMAKE_CXX_COMPILER_ID STREQUAL GNU)
5+
target_compile_options(${PROJECT_NAME} PRIVATE
6+
-Wall -Wextra -Wpedantic -Wconversion -Werror=return-type -Wunused
7+
)
8+
endif()

tray/src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int main() {}

0 commit comments

Comments
 (0)