Update README instructions
+ Fix incorrect library name for `algorithms/trees/BST` example + Update root CMakeLists.txt for major directories to set binary path + Add instructions to install CMake LTS with pip
This commit is contained in:
parent
9243ded17b
commit
2845b020ae
|
@ -17,6 +17,8 @@ project(
|
|||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_subdirectory(algorithms)
|
||||
add_subdirectory(cmake)
|
||||
add_subdirectory(cryptography)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
# Cpp
|
||||
|
||||
```
|
||||
```bash
|
||||
shaunrd0/klips/cpp/
|
||||
├── algorithms # Examples of various algorithms written in C++
|
||||
├── cmake # Example of using cmake to build and organize larger projects
|
||||
├── cryptography# Examples of encrypting / decrypting using ciphers in C++
|
||||
├── datastructs # Collection of useful datastructures written in C++
|
||||
├── graphics # Examples of graphics projects written in C++
|
||||
├── patterns # Examples of various design patterns written in C++
|
||||
├── algorithms # Examples of various algorithms written in C++
|
||||
├── cmake # Example of using cmake to build and organize larger projects
|
||||
├── cryptography # Examples of encrypting / decrypting using ciphers in C++
|
||||
├── datastructs # Collection of useful datastructures written in C++
|
||||
├── graphics # Examples of graphics projects written in C++
|
||||
├── patterns # Examples of various design patterns written in C++
|
||||
└── README.md
|
||||
```
|
||||
|
||||
|
@ -15,15 +15,68 @@ This directory contains a `CMakeLists.txt`, which can be selected to open as a
|
|||
project within your preferred IDE. From there, all nested examples can be built,
|
||||
debugged, and ran.
|
||||
|
||||
In general, if a `CMakeLists.txt` is included in the project's root directory,
|
||||
we can build the example with the following commands
|
||||
Some of the more recent projects in this repository requires the latest CMake LTS.
|
||||
To install `cmake` LTS with `apt` we can follow [official instructions from kitware](https://apt.kitware.com/)
|
||||
Alternatively, we can install the LTS with python's `pip`.
|
||||
```bash
|
||||
sudo apt install python3.9 python3-pip
|
||||
sudo apt purge cmake
|
||||
python3.9 -m pip install -U pip
|
||||
python3.9 -m pip install --upgrade cmake
|
||||
# The command below is optional if you have added the python binary path to your PATH environment variable
|
||||
sudo ln -s /usr/local/lib/python3.9/dist-packages/cmake/data/bin/cmake /usr/bin/
|
||||
cmake --version
|
||||
|
||||
cmake version 3.22.1
|
||||
```
|
||||
|
||||
Once cmake is installed, dependencies for all examples can be installed with the command below.
|
||||
```bash
|
||||
sudo apt install libsdl2-dev freeglut3-dev
|
||||
```
|
||||
|
||||
If we build from this directory, we build all C++ projects and examples
|
||||
```bash
|
||||
cd /path/to/klips/cpp/
|
||||
mkdir build && cd build
|
||||
cmake .. && cmake --build .
|
||||
```
|
||||
|
||||
We can see the binaries output in the `build/bin/` folder
|
||||
```bash
|
||||
~/Code/klips/cpp/build$ ls bin/
|
||||
abstract-factory-test graph-test-templated SingleListDriver
|
||||
adapter-test graph-test-weighted singleton-test
|
||||
bridge-test HeapDriver StackDriver
|
||||
bubble-sort heap-sort state-test
|
||||
bucket-sort insertion-sort TemplatedDoubleListDriver
|
||||
CircleDoubleDriver merge-sort TemplatedQueueDriver
|
||||
CircleSingleDriver observer-test TemplatedStackDriver
|
||||
columnar-transposition-test opengl-test TemplatedVectorDriver
|
||||
counting-sort prototype-test test-bst
|
||||
DoubleListDriver QueueDriver test-bst-algo
|
||||
execute-hello quick-sort test-redblack
|
||||
factory-test radix-sort VectorDriver
|
||||
graph-test-object sdl-test visitor-test
|
||||
graph-test-simple select-sort
|
||||
```
|
||||
|
||||
We can also build from subdirectories.
|
||||
To only build projects related to design patterns we build from the `patterns/` subdirectory, for example
|
||||
```bash
|
||||
cd /path/to/klips/cpp/patterns
|
||||
mkdir build && cd build
|
||||
cmake .. && cmake --build .
|
||||
```
|
||||
|
||||
And we can again see the binaries output in the `build/bin/` folder
|
||||
```bash
|
||||
~/Code/klips/cpp/patterns/build$ ls bin/
|
||||
abstract-factory-test bridge-test observer-test singleton-test visitor-test
|
||||
adapter-test factory-test prototype-test state-test
|
||||
```
|
||||
|
||||
If cmake is not being used in a project, it can be built with `g++` manually using
|
||||
the commands outlined in `*/.vscode/tasks.json`, or by using VSCode to open the example
|
||||
and running the build task.
|
||||
|
||||
and running the build task.
|
||||
Check the header comments in the main source file for the example for instructions.
|
||||
|
|
|
@ -15,6 +15,8 @@ project (
|
|||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_subdirectory(graphs)
|
||||
add_subdirectory(sorting)
|
||||
add_subdirectory(trees)
|
||||
|
|
|
@ -15,6 +15,8 @@ project (
|
|||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_subdirectory(object)
|
||||
add_subdirectory(simple)
|
||||
add_subdirectory(templated)
|
||||
|
|
|
@ -15,6 +15,8 @@ project (
|
|||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_subdirectory(bubble)
|
||||
add_subdirectory(bucket)
|
||||
add_subdirectory(count)
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(BubbleSort LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_executable(bubble-sort "bubble-sort.cpp")
|
||||
|
||||
add_library(lib-bubble "lib-bubble.cpp")
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(BucketSort LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_executable(bucket-sort "bucket-sort.cpp")
|
||||
|
||||
add_library(lib-bucket "lib-bucket.cpp")
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(CountingSort LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_executable(counting-sort "counting-sort.cpp")
|
||||
|
||||
add_library(lib-counting "lib-counting.cpp")
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(HeapSort LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_executable(heap-sort "heap-sort.cpp")
|
||||
|
||||
add_library(lib-heap "lib-heap.cpp")
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(InsertionSort LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_executable(insertion-sort "insertion-sort.cpp")
|
||||
|
||||
add_library(lib-insertion "lib-insertion.cpp")
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
cmake_minimum_required(VERSION 3.17)
|
||||
project(MergeSort LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
add_executable(merge-sort "merge-sort.cpp")
|
||||
|
||||
add_library(lib-merge "lib-merge.cpp")
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(QuickSort LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_executable(quick-sort "quick-sort.cpp")
|
||||
|
||||
add_library(lib-quick "lib-quick.cpp")
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(RadixSort LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_executable(radix-sort "radix-sort.cpp")
|
||||
|
||||
add_library(lib-radix-counting "lib-counting.cpp")
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(SelectionSort LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_executable(select-sort "select-sort.cpp")
|
||||
|
||||
add_library(lib-select "lib-select.cpp")
|
||||
|
|
|
@ -15,5 +15,7 @@ project (
|
|||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_subdirectory(binary)
|
||||
add_subdirectory(redblack)
|
||||
|
|
|
@ -18,4 +18,4 @@ project (
|
|||
add_library(lib-bst-algo "bst.cpp")
|
||||
|
||||
add_executable(test-bst-algo "driver.cpp")
|
||||
target_link_libraries(test-bst-algo lib-bst)
|
||||
target_link_libraries(test-bst-algo lib-bst-algo)
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
# Define the version of CMake
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
# Define the your project name
|
||||
project(cmake-template)
|
||||
|
||||
|
|
|
@ -15,4 +15,6 @@ project (
|
|||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_subdirectory(columnar-transposition)
|
||||
|
|
|
@ -15,6 +15,8 @@ project (
|
|||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_subdirectory(binarysearchtree)
|
||||
add_subdirectory(circledoublelist)
|
||||
add_subdirectory(circlesinglelist)
|
||||
|
|
|
@ -17,5 +17,7 @@ project(
|
|||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_subdirectory(opengl-cmake)
|
||||
add_subdirectory(sdl-cmake)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# Graphics
|
||||
|
||||
Example graphics programming projects written in C++
|
||||
Example graphics programming projects written in C++.
|
||||
For a more complete example of a graphics application, see [shaunrd0/qtk](https://gitlab.com/shaunrd0/qtk)
|
||||
|
||||
```
|
||||
klips/cpp/graphics
|
||||
|
@ -10,3 +11,21 @@ klips/cpp/graphics
|
|||
├── sdl-cmake # Barebones sdl application written in C++ built with cmake
|
||||
└── sdl # Barebones sdl application written in C++ built with gcc
|
||||
```
|
||||
|
||||
Install dependencies for these examples with the following command
|
||||
|
||||
```bash
|
||||
sudo apt install libsdl2-dev freeglut3-dev
|
||||
```
|
||||
|
||||
Then we can build the examples that have `CMakeLists.txt` configured.
|
||||
If the example does not use CMake, the commands to build and run are found within the header comments of the main source file.
|
||||
|
||||
```bash
|
||||
cd /path/to/klips/cpp/graphics/
|
||||
mkdir build && cd build
|
||||
cmake .. && cmake --build .
|
||||
ls bin/
|
||||
|
||||
opengl-test sdl-test
|
||||
```
|
||||
|
|
|
@ -24,7 +24,6 @@ if (OPENGL_FOUND)
|
|||
# Link opengl-test executable to OpenGL
|
||||
target_include_directories(lib-opengl-test PUBLIC ${OPENGL_INCLUDE_DIR})
|
||||
target_link_libraries(lib-opengl-test PUBLIC ${OPENGL_LIBRARIES})
|
||||
|
||||
else()
|
||||
message(
|
||||
"Error: CMake was unable to find the OpenGL package\n"
|
||||
|
@ -38,7 +37,6 @@ if (GLUT_FOUND)
|
|||
# Link lib-opengl-test executable to GLUT
|
||||
target_include_directories(lib-opengl-test PUBLIC ${GLUT_INCLUDE_DIR})
|
||||
target_link_libraries(lib-opengl-test PUBLIC ${GLUT_LIBRARIES})
|
||||
|
||||
else()
|
||||
message(
|
||||
"Error: CMake was unable to find the GLUT package\n"
|
||||
|
|
|
@ -15,6 +15,8 @@ project(
|
|||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
add_subdirectory(singleton)
|
||||
add_subdirectory(adapter)
|
||||
add_subdirectory(bridge)
|
||||
|
|
Loading…
Reference in New Issue