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:
Shaun Reed 2022-01-07 11:26:00 -05:00
parent 9243ded17b
commit 2845b020ae
23 changed files with 105 additions and 32 deletions

View File

@ -17,6 +17,8 @@ project(
LANGUAGES CXX LANGUAGES CXX
) )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(algorithms) add_subdirectory(algorithms)
add_subdirectory(cmake) add_subdirectory(cmake)
add_subdirectory(cryptography) add_subdirectory(cryptography)

View File

@ -1,6 +1,6 @@
# Cpp # Cpp
``` ```bash
shaunrd0/klips/cpp/ shaunrd0/klips/cpp/
├── algorithms # Examples of various algorithms written in C++ ├── algorithms # Examples of various algorithms written in C++
├── cmake # Example of using cmake to build and organize larger projects ├── cmake # Example of using cmake to build and organize larger projects
@ -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, project within your preferred IDE. From there, all nested examples can be built,
debugged, and ran. debugged, and ran.
In general, if a `CMakeLists.txt` is included in the project's root directory, Some of the more recent projects in this repository requires the latest CMake LTS.
we can build the example with the following commands 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 mkdir build && cd build
cmake .. && cmake --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 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 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.

View File

@ -15,6 +15,8 @@ project (
LANGUAGES CXX LANGUAGES CXX
) )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(graphs) add_subdirectory(graphs)
add_subdirectory(sorting) add_subdirectory(sorting)
add_subdirectory(trees) add_subdirectory(trees)

View File

@ -15,6 +15,8 @@ project (
LANGUAGES CXX LANGUAGES CXX
) )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(object) add_subdirectory(object)
add_subdirectory(simple) add_subdirectory(simple)
add_subdirectory(templated) add_subdirectory(templated)

View File

@ -15,6 +15,8 @@ project (
LANGUAGES CXX LANGUAGES CXX
) )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(bubble) add_subdirectory(bubble)
add_subdirectory(bucket) add_subdirectory(bucket)
add_subdirectory(count) add_subdirectory(count)

View File

@ -9,8 +9,6 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(BubbleSort LANGUAGES CXX) project(BubbleSort LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(bubble-sort "bubble-sort.cpp") add_executable(bubble-sort "bubble-sort.cpp")
add_library(lib-bubble "lib-bubble.cpp") add_library(lib-bubble "lib-bubble.cpp")

View File

@ -9,8 +9,6 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(BucketSort LANGUAGES CXX) project(BucketSort LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(bucket-sort "bucket-sort.cpp") add_executable(bucket-sort "bucket-sort.cpp")
add_library(lib-bucket "lib-bucket.cpp") add_library(lib-bucket "lib-bucket.cpp")

View File

@ -9,8 +9,6 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(CountingSort LANGUAGES CXX) project(CountingSort LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(counting-sort "counting-sort.cpp") add_executable(counting-sort "counting-sort.cpp")
add_library(lib-counting "lib-counting.cpp") add_library(lib-counting "lib-counting.cpp")

View File

@ -9,8 +9,6 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(HeapSort LANGUAGES CXX) project(HeapSort LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(heap-sort "heap-sort.cpp") add_executable(heap-sort "heap-sort.cpp")
add_library(lib-heap "lib-heap.cpp") add_library(lib-heap "lib-heap.cpp")

View File

@ -9,8 +9,6 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(InsertionSort LANGUAGES CXX) project(InsertionSort LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(insertion-sort "insertion-sort.cpp") add_executable(insertion-sort "insertion-sort.cpp")
add_library(lib-insertion "lib-insertion.cpp") add_library(lib-insertion "lib-insertion.cpp")

View File

@ -9,7 +9,6 @@
cmake_minimum_required(VERSION 3.17) cmake_minimum_required(VERSION 3.17)
project(MergeSort LANGUAGES CXX) project(MergeSort LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(merge-sort "merge-sort.cpp") add_executable(merge-sort "merge-sort.cpp")
add_library(lib-merge "lib-merge.cpp") add_library(lib-merge "lib-merge.cpp")

View File

@ -9,8 +9,6 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(QuickSort LANGUAGES CXX) project(QuickSort LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(quick-sort "quick-sort.cpp") add_executable(quick-sort "quick-sort.cpp")
add_library(lib-quick "lib-quick.cpp") add_library(lib-quick "lib-quick.cpp")

View File

@ -9,8 +9,6 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(RadixSort LANGUAGES CXX) project(RadixSort LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(radix-sort "radix-sort.cpp") add_executable(radix-sort "radix-sort.cpp")
add_library(lib-radix-counting "lib-counting.cpp") add_library(lib-radix-counting "lib-counting.cpp")

View File

@ -9,8 +9,6 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(SelectionSort LANGUAGES CXX) project(SelectionSort LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(select-sort "select-sort.cpp") add_executable(select-sort "select-sort.cpp")
add_library(lib-select "lib-select.cpp") add_library(lib-select "lib-select.cpp")

View File

@ -15,5 +15,7 @@ project (
LANGUAGES CXX LANGUAGES CXX
) )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(binary) add_subdirectory(binary)
add_subdirectory(redblack) add_subdirectory(redblack)

View File

@ -18,4 +18,4 @@ project (
add_library(lib-bst-algo "bst.cpp") add_library(lib-bst-algo "bst.cpp")
add_executable(test-bst-algo "driver.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)

View File

@ -10,6 +10,8 @@
# Define the version of CMake # Define the version of CMake
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Define the your project name # Define the your project name
project(cmake-template) project(cmake-template)

View File

@ -15,4 +15,6 @@ project (
LANGUAGES CXX LANGUAGES CXX
) )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(columnar-transposition) add_subdirectory(columnar-transposition)

View File

@ -15,6 +15,8 @@ project (
LANGUAGES CXX LANGUAGES CXX
) )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(binarysearchtree) add_subdirectory(binarysearchtree)
add_subdirectory(circledoublelist) add_subdirectory(circledoublelist)
add_subdirectory(circlesinglelist) add_subdirectory(circlesinglelist)

View File

@ -17,5 +17,7 @@ project(
LANGUAGES CXX LANGUAGES CXX
) )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(opengl-cmake) add_subdirectory(opengl-cmake)
add_subdirectory(sdl-cmake) add_subdirectory(sdl-cmake)

View File

@ -1,6 +1,7 @@
# Graphics # 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 klips/cpp/graphics
@ -10,3 +11,21 @@ klips/cpp/graphics
├── sdl-cmake # Barebones sdl application written in C++ built with cmake ├── sdl-cmake # Barebones sdl application written in C++ built with cmake
└── sdl # Barebones sdl application written in C++ built with gcc └── 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
```

View File

@ -24,7 +24,6 @@ if (OPENGL_FOUND)
# Link opengl-test executable to OpenGL # Link opengl-test executable to OpenGL
target_include_directories(lib-opengl-test PUBLIC ${OPENGL_INCLUDE_DIR}) target_include_directories(lib-opengl-test PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(lib-opengl-test PUBLIC ${OPENGL_LIBRARIES}) target_link_libraries(lib-opengl-test PUBLIC ${OPENGL_LIBRARIES})
else() else()
message( message(
"Error: CMake was unable to find the OpenGL package\n" "Error: CMake was unable to find the OpenGL package\n"
@ -38,7 +37,6 @@ if (GLUT_FOUND)
# Link lib-opengl-test executable to GLUT # Link lib-opengl-test executable to GLUT
target_include_directories(lib-opengl-test PUBLIC ${GLUT_INCLUDE_DIR}) target_include_directories(lib-opengl-test PUBLIC ${GLUT_INCLUDE_DIR})
target_link_libraries(lib-opengl-test PUBLIC ${GLUT_LIBRARIES}) target_link_libraries(lib-opengl-test PUBLIC ${GLUT_LIBRARIES})
else() else()
message( message(
"Error: CMake was unable to find the GLUT package\n" "Error: CMake was unable to find the GLUT package\n"

View File

@ -15,6 +15,8 @@ project(
LANGUAGES CXX LANGUAGES CXX
) )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(singleton) add_subdirectory(singleton)
add_subdirectory(adapter) add_subdirectory(adapter)
add_subdirectory(bridge) add_subdirectory(bridge)