Skip to content

Commit 4f7b487

Browse files
committed
feat: tooling description
1 parent 2e0e054 commit 4f7b487

10 files changed

Lines changed: 363 additions & 19 deletions

File tree

.clang-format

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
BasedOnStyle: Google
3+
AccessModifierOffset: '-2'
4+
AlignTrailingComments: 'true'
5+
AllowAllParametersOfDeclarationOnNextLine: 'false'
6+
AlwaysBreakTemplateDeclarations: 'No'
7+
BreakBeforeBraces: Attach
8+
ColumnLimit: '100'
9+
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
10+
IncludeBlocks: Regroup
11+
IndentPPDirectives: AfterHash
12+
IndentWidth: '2'
13+
NamespaceIndentation: All
14+
BreakBeforeBinaryOperators: All
15+
BreakBeforeTernaryOperators: 'true'
16+
Standard: c++20
17+
...

.cmake-format

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
format:
2+
tab_size: 2
3+
line_width: 100
4+
dangle_parens: true
5+
6+
parse:
7+
additional_commands:
8+
cpmaddpackage:
9+
pargs:
10+
nargs: '*'
11+
flags: []
12+
spelling: CPMAddPackage
13+
kwargs: &cpmaddpackagekwargs
14+
NAME: 1
15+
FORCE: 1
16+
VERSION: 1
17+
GIT_TAG: 1
18+
DOWNLOAD_ONLY: 1
19+
GITHUB_REPOSITORY: 1
20+
GITLAB_REPOSITORY: 1
21+
GIT_REPOSITORY: 1
22+
SVN_REPOSITORY: 1
23+
SVN_REVISION: 1
24+
SOURCE_DIR: 1
25+
DOWNLOAD_COMMAND: 1
26+
FIND_PACKAGE_ARGUMENTS: 1
27+
NO_CACHE: 1
28+
GIT_SHALLOW: 1
29+
URL: 1
30+
URL_HASH: 1
31+
URL_MD5: 1
32+
DOWNLOAD_NAME: 1
33+
DOWNLOAD_NO_EXTRACT: 1
34+
HTTP_USERNAME: 1
35+
HTTP_PASSWORD: 1
36+
OPTIONS: +
37+
cpmfindpackage:
38+
pargs:
39+
nargs: '*'
40+
flags: []
41+
spelling: CPMFindPackage
42+
kwargs: *cpmaddpackagekwargs
43+
packageproject:
44+
pargs:
45+
nargs: '*'
46+
flags: []
47+
spelling: packageProject
48+
kwargs:
49+
NAME: 1
50+
VERSION: 1
51+
NAMESPACE: 1
52+
INCLUDE_DIR: 1
53+
INCLUDE_DESTINATION: 1
54+
BINARY_DIR: 1
55+
COMPATIBILITY: 1
56+
VERSION_HEADER: 1
57+
DEPENDENCIES: +

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@
3636
.vs/
3737
cmake-*/
3838
out/
39+
build*/

.releaserc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"branches": ["master", "main"],
3+
"repositoryUrl": "https://github.com/InfiniBrains/Introduction-to-Game-Programming-With-CPP"
4+
}

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
1616
# see https://github.com/TheLartians/CPM.cmake for more info
1717
include(cmake/get_cpm.cmake)
1818

19+
# include sanitizers
20+
include(cmake/tools.cmake)
21+
1922
# check if we are target compiling to web
2023
if(EMSCRIPTEN)
2124
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Oz -s WASM=2")

cmake/tools.cmake

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# this file contains a list of tools that can be activated and downloaded on-demand each tool is
2+
# enabled during configuration by passing an additional `-DUSE_<TOOL>=<VALUE>` argument to CMake
3+
4+
# only activate tools for top level project
5+
if(NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
6+
return()
7+
endif()
8+
9+
# enables sanitizers support using the the `USE_SANITIZER` flag available values are: Address,
10+
# Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined'
11+
if(USE_SANITIZER OR USE_STATIC_ANALYZER)
12+
CPMAddPackage("gh:StableCoder/cmake-scripts#1f822d1fc87c8d7720c074cde8a278b44963c354")
13+
14+
if(USE_SANITIZER)
15+
include(${cmake-scripts_SOURCE_DIR}/sanitizers.cmake)
16+
endif()
17+
18+
if(USE_STATIC_ANALYZER)
19+
if("clang-tidy" IN_LIST USE_STATIC_ANALYZER)
20+
set(CLANG_TIDY
21+
ON
22+
CACHE INTERNAL ""
23+
)
24+
else()
25+
set(CLANG_TIDY
26+
OFF
27+
CACHE INTERNAL ""
28+
)
29+
endif()
30+
if("iwyu" IN_LIST USE_STATIC_ANALYZER)
31+
set(IWYU
32+
ON
33+
CACHE INTERNAL ""
34+
)
35+
else()
36+
set(IWYU
37+
OFF
38+
CACHE INTERNAL ""
39+
)
40+
endif()
41+
if("cppcheck" IN_LIST USE_STATIC_ANALYZER)
42+
set(CPPCHECK
43+
ON
44+
CACHE INTERNAL ""
45+
)
46+
else()
47+
set(CPPCHECK
48+
OFF
49+
CACHE INTERNAL ""
50+
)
51+
endif()
52+
53+
include(${cmake-scripts_SOURCE_DIR}/tools.cmake)
54+
55+
clang_tidy(${CLANG_TIDY_ARGS})
56+
include_what_you_use(${IWYU_ARGS})
57+
cppcheck(${CPPCHECK_ARGS})
58+
endif()
59+
endif()
60+
61+
# enables CCACHE support through the USE_CCACHE flag possible values are: YES, NO or equivalent
62+
if(USE_CCACHE)
63+
CPMAddPackage("gh:TheLartians/Ccache.cmake@1.2.3")
64+
endif()

codecov.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
codecov:
2+
require_ci_to_pass: no
3+
4+
coverage:
5+
precision: 2
6+
round: down
7+
range: "80...100"
8+
status:
9+
project:
10+
default:
11+
threshold: 0.1%

intro/01-introduction/README.md

Whitespace-only changes.

intro/02-tooling/README.md

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# Tools for C++ development
2+
3+
In order to effectively code in C++ you will need some tools.
4+
5+
## Version Control - GIT
6+
7+
> [Git](https://git-scm.com/downloads) is a version control system that is used to track changes to files, including
8+
source code, documents, and other types of files. It allows multiple people to work on the same files concurrently,
9+
and it keeps track of all changes made to the files, making it easy to go back to previous versions or merge changes
10+
made by different people. Git is widely used by developers for managing source code, but it can be used to track changes
11+
to any type of file. It is particularly useful for coordinating work on projects that involve multiple
12+
people, as it allows everyone to see and track changes made by others. [Reference](https://chat.openai.com/).
13+
14+
> [Github](https://github.com) is a web-based platform for version control and collaboration on software
15+
projects. It is a popular platform for developers to share and collaborate on code, as well as to track and manage
16+
software development projects. GitHub provides version control using Git, a version control system that allows
17+
developers to track changes to their codebase and collaborate with other developers on the same codebase. It also
18+
includes a range of features such as bug tracking, project management, and team communication tools. In addition to
19+
being a platform for software development, GitHub is also a community of developers and a marketplace for buying and
20+
selling software development services. [Reference](https://chat.openai.com/).
21+
22+
In this course we are going to extensively use GITHUB functionalities. So create an account now with your
23+
personal account. Use a meaningful username. Avoid names that hard to associate with you. If you have a educational
24+
email or student id, apply for the [Github Student Pack](https://education.github.com/pack), so you will have access
25+
to lots of free tools.
26+
27+
> [GitKraken](https://www.gitkraken.com/) GitKraken is a Git client for Windows, Mac, and Linux that provides a
28+
graphical interface for working with Git repositories. It allows users to manage Git repositories, create and review
29+
changes to code, and collaborate with other developers. Some features of GitKraken include a visual representation
30+
of the repository's commit history, the ability to stage and discard changes, and support for popular version
31+
control systems like GitHub and GitLab. GitKraken is designed to be user-friendly and to make it easier for
32+
developers to work with Git, particularly for those who may be new to version control systems.
33+
[Reference](https://chat.openai.com/).
34+
35+
Gitkraken is a paid software, and it is free for public repositories, but you can have all enterprise and premium
36+
functionalities enabled for free with the student pack and described before.
37+
38+
## Compiler
39+
> A compiler is a type of computer program that translates source code written in a programming language into machine
40+
code that can be executed by a computer. The machine code is a sequence of instructions that are specific to a
41+
particular computer architecture and operating system. The source code is written in a high-level programming
42+
language, such as C++, Java, or Python, which is easier for humans to read and write. The compiler converts the
43+
source code into machine code that can be run on a computer. There are different types of compilers, including
44+
cross-compilers, which can compile code for one type of computer to run on another type of computer, and
45+
just-in-time (JIT) compilers, which compile code at runtime. Compilers are an important part of the software
46+
development process, as they allow developers to write code in a high-level language that is then translated into
47+
machine code that can be run on a specific platform. [Reference](https://chat.openai.com/)
48+
49+
This where things get tricky, C++ compiles the code into a binary that runs directly on the processor and interacts
50+
with the operating system. So we can have multiple combinations here. Most compilers are cross-platform, but there
51+
is exceptions. And to worsen it, some Compilers are tightly coupled with some IDEs(see below, next item).
52+
53+
I personally prefer to use CLang to be my target because it is the one that is most reliable cross-platform
54+
compiler. Which means the code will work as expected in most of the scenarios, the feature support table is the same
55+
across all platforms. But GCC is the more bleeding edge, which means usually it is the first to support all new
56+
fancy features C++ introduces.
57+
58+
No need to download anything here.
59+
60+
## CMake
61+
> [CMake](https://cmake.org/) CMake is a cross-platform free and open-source software tool for managing the build
62+
process of software using a compiler-independent method. It is designed to support directory hierarchies and
63+
applications that depend on multiple libraries. It is used to control the software compilation process using simple
64+
platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice. [Reference](https://chat.openai.com/).
65+
66+
If you use a good IDE(see next topic), you won't need to download anything here.
67+
68+
<details>
69+
CMake is typically used in conjunction with native build environments such as Make, Ninja, or Visual Studio. It can
70+
also generate project files for IDEs such as Eclipse, Xcode, and Visual Studio.
71+
72+
Here is a simple example of a CMakeLists.txt file that can be used to build a program called "myproject" that consists of a single source file called "main.cpp":
73+
74+
```cmake
75+
cmake_minimum_required(VERSION 3.10)
76+
project(myproject)
77+
add_executable(myproject main.cpp)
78+
```
79+
80+
To build the project, you would first generate a build directory, and then run CMake to build the files using the
81+
detected compiler or IDE:
82+
```bash
83+
cmake -S. -Bbuild
84+
cmake --build build -j20
85+
```
86+
This will create a Makefile or a Visual Studio solution file in the build directory, depending on your platform and compiler. You can then use the native build tools to build the project by running "make" or opening the solution file in Visual Studio.
87+
88+
CMake provides many options and variables that can be used to customize the build process, such as setting compiler flags, specifying dependencies, and configuring installation targets. You can learn more about CMake by reading the documentation at https://cmake.org/.
89+
</details>
90+
91+
## IDE
92+
93+
> An integrated development environment (IDE) is a software application that provides comprehensive facilities to
94+
computer programmers for software development. An IDE typically integrates a source code editor, build automation
95+
tools, and a debugger. Some IDEs also include additional tools, such as a version control system, a class browser,
96+
and a support for literate programming. IDEs are designed to maximize programmer productivity by providing tight-knit
97+
components with similar user interfaces. This can be achieved through features such as auto-complete, syntax
98+
highlighting, and code refactoring. Many IDEs also provide a code debugger, which allows the programmer to step through
99+
code execution and find and fix errors. Some examples of popular IDEs include Eclipse, NetBeans, Visual Studio, and
100+
Xcode. Each of these IDEs has its own set of features and capabilities, and developers may choose one based on their
101+
specific needs and preferences. [Reference](https://chat.openai.com/).
102+
103+
In this course, it is strongly suggested to use an IDE in order to achieve higher quality of deliveries, a good IDE
104+
effectively flatten the C++ learning curve. You can opt out and use everything by hand, of course, and it will deepen
105+
your knowledge on how things work but be assured it can slow down your learning process. Given this course is result
106+
oriented, it is not recommended to not use an IDE here. So use one.
107+
108+
OPINION: The most pervasive C++ IDE is [CLion](https://www.jetbrains.com/clion/) and this the one I am going to use. If
109+
you use it too, it would be easier to follow my recorded videos. It works on all platforms Windows, Linux and Mac. I
110+
recommend downloading it via [Jetbrains Toolbox](https://www.jetbrains.com/toolbox-app/). If you are a student, apply
111+
for student pack [for free here](https://www.jetbrains.com/community/education/#students). On Windows, CLion embeds
112+
a GCC compiler or optionally can use visual studio, while on Macs it requires the xcode command line tools, and on
113+
Linux, uses GCC from the system installation.
114+
115+
The other options I suggest are:
116+
117+
### On all platforms
118+
119+
[REPLIT](https://replit.com/) - an online and real-time multiplayer IDE. It is slow and lack many functionalities,
120+
but can be used for small scoped activities or work with a friend.
121+
122+
[VSCode](https://code.visualstudio.com/) - a small and highly modularized code editor, it have lots of extensions,
123+
but it can be complex to set up everything needed: git, cmake, compiler and other stuff.
124+
125+
### On Windows:
126+
[Visual Studio](https://visualstudio.microsoft.com/) - mostly for Windows. When installing, mark C++ development AND
127+
search and install additional tools "CMake". Otherwise, this repo won't work smoothly for you.
128+
129+
[DevC++](https://www.bloodshed.net/) - an outdated and small IDE. Lacks lots of functionalities, but if you don't
130+
have HD space or use an old machine, this can be your option. In long term, this choice would be bad for you for the
131+
lack of functionalities. It is better to use REPLIT than this tool, in my opinion.
132+
133+
### On OSX
134+
135+
[XCode](https://developer.apple.com/xcode/) - for OSX and Apple devices. It is required at least to have the Command
136+
Line Tools. CLion on Macs depends on that.
137+
<details>
138+
Xcode Command Line Tools is a small suite of software development tools that are installed on your Mac along with Xcode. These tools include the GCC compiler, which is used to compile C and C++ programs, as well as other tools such as Make and GDB, which are used for debugging and development. The Xcode Command Line Tools are necessary for working with projects from the command line, as well as for using certain software development tools such as Homebrew.
139+
140+
To install the Xcode Command Line Tools, you need to have Xcode installed on your Mac. To check if Xcode is already installed, open a Terminal window and type:
141+
142+
```xcode-select -p```
143+
144+
If Xcode is already installed, this command will print the path to the Xcode developer directory. If Xcode is not installed, you will see a message saying "xcode-select: error: command line tools are not installed, use xcode-select --install to install."
145+
146+
To install the Xcode Command Line Tools, open a Terminal window and type:
147+
148+
```xcode-select --install```
149+
150+
This will open a window that prompts you to install the Xcode Command Line Tools. Follow the prompts to complete the installation.
151+
152+
Once the Xcode Command Line Tools are installed, you can use them from the command line by typing commands such as gcc, make, and gdb. You can also use them to install and manage software packages with tools like Homebrew.
153+
</details>
154+
155+
### On Linux
156+
157+
If you are using Linux, you know the drill. No need for further explanations here, you are ahead of the others.
158+
<details>
159+
If you are using an Ubuntu distro, you can try this to install most of the tools you will need here:
160+
161+
```console
162+
sudo apt-get update && sudo apt-get install -y build-essential git cmake lcov xcb libx11-dev libx11-xcb-dev
163+
libxcb-randr0-dev
164+
```
165+
166+
You will have a plethora of editors and IDEs. The one I can suggest is the VSCode, Code::Blocks or KDevelop. But I
167+
really prefer CLion.
168+
</details>
169+
170+
# Homework
171+
172+
1. Setup your environment for your needs. If you are unsure, use CLion.
173+
2. Fork this repo privately. You will have to do your assignments there. Go to the home repo and hit
174+
[fork](https://github.com/InfiniBrains/Introduction-to-Game-Programming-With-CPP/fork).
175+
3. Clone this repo to your machine. [gitkraken + github](https://www.youtube.com/watch?v=5nhNfMcczlQ)
176+
[gitkraken clone](https://www.youtube.com/watch?v=Mxd-0dO2uyI)
177+
[gitkraken big tutorial](https://www.youtube.com/watch?v=ceT3pm5hYvs)
178+
4. Make sure the CMake option "ENABLE_INTRO" is set as ON in CMakeLists.txt file in the root directory in order to see
179+
and enable all activities.
180+
5. (enrolled students) If you are enrolled in a class with me, share your repo with me, so I can track your evolution.
181+
And do the activities described there.
182+
6(optional) star the repo :-)
183+
184+
# Troubleshooting
185+
If you have problems here, start a
186+
[discussion](https://github.com/InfiniBrains/Introduction-to-Game-Programming-With-CPP/discussions) this is publicly
187+
visible and not FERPA compliant. Use discussions in Canvas if you are enrolled in a class with me.

0 commit comments

Comments
 (0)