diff --git a/README.md b/README.md index 30b3c29..4a7e9c3 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,22 @@ Coders School -## [Moduł 1](module1/) +## [Moduł 1](module1/index.pl.html) -### [`make`](module1/presentation_make.md) +### [`make`](module1/01_make.pl.md) -### [`cmake`](module1/presentation_cmake.md) +### [`cmake`](module1/02_cmake.pl.md) -### [homework](module1/presentation_homework.md) +### [Zadania domowe](module1/03_homework.pl.md) + +___ + +# Build systems + +## [Module 1](module1/index.en.html) + +### [`make`](module1/01_make.en.md) + +### [`cmake`](module1/02_cmake.en.md) + +### [homework](module1/03_homework.en.md) \ No newline at end of file diff --git a/module1/01_make.en.md b/module1/01_make.en.md new file mode 100644 index 0000000..982a9a7 --- /dev/null +++ b/module1/01_make.en.md @@ -0,0 +1,108 @@ + + +# `make` + + + Coders School + + +___ + +## Makefiles + +### The structure of the Makefile + +```Makefile +VARIABLE = value + +targetA: dependencyA1 dependencyA2 +[TAB] command $(VARIABLE) + +targetB: dependencyB1 +[TAB] command +``` + +___ + +## Example - generating a presentation in LaTeX + +```Makefile +TEX = pdflatex -shell-escape -interaction=nonstopmode -file-line-error +MAKE = make +CODE_DIR = src + +.PHONY: all view + +all: calculator pdf + +view: + evince ContractProgramming.pdf + +pdf: ContractProgramming.tex + $(TEX) ContractProgramming.tex + +calculator: + $(MAKE) -C $(CODE_DIR) +``` + +___ + +## Compilation in C ++ + +### Do you remember the build phases? + + +```Makefile +SOURCES=$(wildcard src/*.cpp) +OBJECTS=$(patsubst %.cpp, %.o, $(SOURCES)) + +main: $(OBJECTS) + g++ $^ -o $@ + +$(OBJECTS): src/%.o : src/%.cpp src/%.hpp + g++ -c $< -o $@ +``` + + +### Variables remembering the context + + +* $@ - the name of the target file in the currently running rule +* $< - first dependency name +* $^ - list of all dependencies (includes any duplicates) +* $? - a list of all dependencies that are newer than target + +___ + +## Exercise + +In the greeter directory you will find a small program. Familiarize yourself with its code. + +* Compile the program from the command line and run it. +* Write a simple Makefile for this program. Build it with `make` and run it. + +### Spell of building + +```bash +g++ -std=c++17 -Wall -Werror -Wextra -pedantic *.cpp -o greeter +./greeter +``` + +___ + +## `make` command + +* by default it looks for a Makefile in the current directory +* automates activities by executing recipes saved in Makefile files +* executes the first recipe by default +* allows for conditional performance of activities +* allows defining many dependencies +* by default, it takes into account dependency modification dates and on this basis decides whether to execute a given recipe + +___ + +## Q&A + +### links + +[cpp-polska.pl](https://cpp-polska.pl/post/potwor-przeszlosci-makefile-cz-2) diff --git a/module1/presentation_make.md b/module1/01_make.pl.md similarity index 100% rename from module1/presentation_make.md rename to module1/01_make.pl.md diff --git a/module1/02_cmake.en.md b/module1/02_cmake.en.md new file mode 100644 index 0000000..43f89db --- /dev/null +++ b/module1/02_cmake.en.md @@ -0,0 +1,321 @@ + + +# `cmake` + + + Coders School + + +___ + +## CMake + +* automates the build process for C/C++ +* supports generating projects for multiple IDEs +* can consists of many modules that are combined (equivalent of #include) +* platform independent (if well written) +* build configuration in CMakeLists.txt file +* generate a build systems (e.g. Makefiles) + +___ + +## Minimal `CMakeLists.txt` + +```cmake +cmake_minimum_required(VERSION 3.10) +project(ProjectName) + +add_executable(execName main.cpp file.cpp) +``` + +___ + +## Building with CMake'a + +```bash +mkdir build # create a directory with the results of the building +cd build # enter this directory +cmake .. # generate the build system by specifying the path to the CMakeLists.txt file +cmake --build . # build a project +``` + +`cmake --build` can be changed for `make` if we're sure, that we're generating Makefile. + + +`cmake --build` is universal. + + +___ + +## Exercise + +Write simple CMakeLists.txt for program from `greeter` directory, build it with `cmake` and run. + +Notice that there is also a tests. Write additional target for tests. + +___ + +## Q&A + +___ + +## CMake - variables + +Variables are created with `set` command + + +```cmake +set(VARIABLE value) # Convention - UPPERCASE_WITH_UNDERSCORE +``` + + +For example + + +```cmake +set(NAME TheGreatestProject) +``` + + +We refer to them later by enclosing them in `{}` parentheses and preceding them with the `$` sign + + +```cmake +add_executable(${NAME} main.cpp) +``` + + +That will create a target `TheGreatestProject` in which `main.cpp` file will be compiled + + +___ + +## CMake - predefined variables + +CMake supplies several variables by default. Referring to them directly or modifying them is usually not considered good practice. + + +We can use the `$ {PROJECT_NAME}` variable without any problems. It contains the project name defined by the `project ()` command + + +```cmake +project(vectorFunctions) +add_executable(${PROJECT_NAME} main.cpp vectorFunctions.cpp) +``` + + +___ + +## Create applications and libraries + +[CMake manual](https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html#id4) + +You can treat the following commands as "constructors". They form "targets" + +```cmake +add_executable( [source1] [source2 ...]) +``` + +```cmake +add_library( [STATIC | SHARED | MODULE] [source1] [source2 ...]) +``` + +```cmake +add_library(${PROJECT_NAME}-lib STATIC functions.cpp modules.cpp) +add_executable(${PROJECT_NAME} main.cpp functions.cpp modules.cpp) +add_executable(${PROJECT_NAME}-ut test.cpp functions.cpp modules.cpp) +``` + + +### Problem + + +Duplicated list of files in different "targets" + + +___ + +### Problem #1 + +Duplicated list of files in different "targets" + +### Solution + + +Putting a list of files into a variable + + +## Exercise + + +Put a list of files into a variable and use it + + +___ + +### Problem #2 + +Minor differences in files between targets + + +### Solution + + +Creating a library + + +___ + +## Libraries + +My library definition - a cluster of multiple cpp files without the `main ()` function. Therefore, the library cannot be run. + + +### Analogy to object oriented programming + + +* Library = class (base) + * fields, methods = cpp files +* Binary = derived class + * final, cannot be inherited from it +* Linking = inheritance + * linking a binary to a library means adding code from the library to it + * libraries can be linked with each other + +___ + +## Linking libraries + +```cmake +target_link_libraries( ... ... ...) +``` + + +```cmake +add_library(lib STATIC functions.cpp modules.cpp) +add_executable(main main.cpp) +add_executable(ut tests.cpp) +target_link_libraries(main lib) +target_link_libraries(ut lib) +``` + + +### Exercise + + +Create a library that will contain duplicate cpp files and link to it with the targets that used them. + + +___ + +## Build flags + +```cmake +target_compile_options( [BEFORE] + [items1...] + [ [items2...] + ...]) +``` + + +```cmake +add_executable(${PROJECT_NAME} main.cpp) +target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror) +``` + + +### Exercise + + +Add build flags `-Wall -Wextra -Werror -pedantic -Wconversion -O3` to the greeter project + + +___ + +## Enabling the C ++ 17 standard + +```cmake +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +``` + + +The above may not work for MSVC. + + +```cmake +set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED ON) +``` + + +```cmake +add_executable(${PROJECT_NAME} main.cpp) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) +``` + + +### Exercise + + +Enable the C++17 standard in the greeter project + + +___ + +## Adding tests to `ctest` + +```cmake +enable_testing() +add_test(NAME COMMAND [...]) +``` + + +```cmake +enable_testing() +add_test(NAME someTests COMMAND ${PROJECT_NAME}-ut) +``` + + +### Exercise + + +Add a test binary that should be run with `ctest` + + +___ + +## Build in debug mode + +By default, the "Release" mode is built (no debugging symbols) + + +```cmake +cmake -DCMAKE_BUILD_TYPE=Debug .. +``` + + +If we want to support building in Debug and Release modes, we should have separate directories with build results + + +```bash +mkdir buildDebug +cd buildDebug +cmake -DCMAKE_BUILD_TYPE=Debug .. +cmake --build +``` + + +___ + +## Links for learning more + +* [CMake - from zero to something - prezentacja z Wro.cpp](https://muttleyxd.github.io) +* [19 reasons why CMake is actually awesome](https://kubasejdak.com/19-reasons-why-cmake-is-actually-awesome) +* [Modern CMake is like inheritance](https://kubasejdak.com/modern-cmake-is-like-inheritance) +* [CMake basics](https://www.siliceum.com/en/blog/post/cmake_01_cmake-basics) + +___ + +## Q&A diff --git a/module1/presentation_cmake.md b/module1/02_cmake.pl.md similarity index 100% rename from module1/presentation_cmake.md rename to module1/02_cmake.pl.md diff --git a/module1/03_homework.en.md b/module1/03_homework.en.md new file mode 100644 index 0000000..205bc09 --- /dev/null +++ b/module1/03_homework.en.md @@ -0,0 +1,57 @@ + + +# Tools #3 + +## Summary + + + Coders School + + +___ + +## What do you remember from today? + +### Write as many topics as possible in the chat + + +___ + +### Pre-work + +* Read about the SOLID rules for writing good object-oriented code +* Read about the principles of good code in C ++ at [CppCoreGuidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md) +* Find out what the diamond problem is on Object Orientation #4 + +___ + +### Post-work + +* Add the `cmake` building system to the SHM project (10 points, 2 for each subtask) +* Prepare SHM for testing (10 points, 2 for each subtask) + +#### Bonus + +* Delivery before Sunday 05.07.2020 23:59 (2 points per task, 4 in total) + +___ + +### `cmake` in SHM + +* Use the variable `${PROJECT_NAME}` +* List of cpp files in the variable +* Everything except `main.cpp` should compile to a static library +* Binary (main.cpp) should be linked with the above library. +* Write an appropriate file `.github/workflows/main.yml` which will cause GitHub to automatically run a project build for each new commit. + +___ + +### The foundations for testing in SHM + +On the basis of reading CMakeLists.txt files from homework, deduce how the `gtest` library is added to tests + +* Create simple tests for SHM project (at least 1 test with Copy&Paste method from other homework) +* Copy the appropriate files that will allow the use of `gtest` +* Add the test binary to CMakeLists.txt. Name it `${PROJECT_NAME}-ut` +* Add test run with `ctest` +* Modify the file `.github/workflows/main.yml` so GitHub will also run tests diff --git a/module1/presentation_homework.md b/module1/03_homework.pl.md similarity index 100% rename from module1/presentation_homework.md rename to module1/03_homework.pl.md diff --git a/module1/index.en.html b/module1/index.en.html new file mode 100644 index 0000000..cb3c8d9 --- /dev/null +++ b/module1/index.en.html @@ -0,0 +1,153 @@ + + + + + + + Object Oriented Programming - Coders School + + + + + + + + + + + + + + + +
+
+
+
+ +

Tools #3

+

Build Systems

+ + Coders School + +

Mateusz Adamski

+

Łukasz Ziobroń

+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+ +

Coders School

+ Coders School + +
+
+
+ + + + + + diff --git a/module1/index.html b/module1/index.pl.html similarity index 97% rename from module1/index.html rename to module1/index.pl.html index 758c51e..356d48d 100644 --- a/module1/index.html +++ b/module1/index.pl.html @@ -107,15 +107,15 @@

Łukasz Ziobroń

You can change the port by using npm start -- --port=8001. --> -
-
-