Clean up CMakeLists in all C++ examples

+ Rename output executables to match directory structure
+ Remove libraries for small examples
+ Supress -Wreturn-type warnings for singleton that is intentionally not copyable
This commit is contained in:
2022-03-31 16:01:08 -04:00
parent 573fc4e1e8
commit a97dfbe34b
98 changed files with 695 additions and 598 deletions

View File

@@ -1,11 +1,11 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A project for practicing C++ design patterns ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: A project for practicing C++ design patterns ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(

View File

@@ -15,7 +15,8 @@ project(
)
add_compile_options("-Wall")
add_library(abstract-parts "parts.cpp")
add_library(abstract-factory "factory.cpp")
add_executable(abstract-factory-test "main.cpp")
target_link_libraries(abstract-factory-test abstract-factory abstract-parts)
add_executable(
patterns-abstract-factory main.cpp
parts.cpp parts.hpp
abstract-factory.cpp abstract-factory.hpp
)

View File

@@ -1,12 +1,13 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A project for practicing the adapter C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: A project for practicing the adapter C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Adapter
VERSION 1.0
@@ -15,6 +16,7 @@ project(
)
add_compile_options("-Wall")
add_library(adapter "adapter.cpp")
add_executable(adapter-test "main.cpp")
target_link_libraries(adapter-test adapter)
add_executable(
patterns-adapter main.cpp
adapter.cpp adapter.hpp
)

View File

@@ -1,12 +1,13 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A project for practicing the bridge C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: A project for practicing the bridge C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Bridge
VERSION 1.0
@@ -15,7 +16,8 @@ project(
)
add_compile_options("-Wall")
add_library(abstraction "abstraction.cpp")
add_library(implementation "implementation.cpp")
add_executable(bridge-test "main.cpp")
target_link_libraries(bridge-test abstraction implementation)
add_executable(
patterns-bridge main.cpp
abstraction.cpp abstraction.hpp
implementation.cpp implementation.hpp
)

View File

@@ -1,12 +1,13 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A project for practicing the factory C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: A project for practicing the factory C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Factory
VERSION 1.0
@@ -15,7 +16,8 @@ project(
)
add_compile_options("-Wall")
add_library(parts "parts.cpp")
add_library(factory "factory.cpp")
add_executable(factory-test "main.cpp")
target_link_libraries(factory-test factory parts)
add_executable(
patterns-factory main.cpp
parts.cpp parts.hpp
factory.cpp abstract-factory.hpp
)

View File

@@ -1,7 +1,7 @@
#include <iostream>
#include "factory.hpp"
#include "abstract-factory.hpp"
Part* GearFactory::requestPart() {
// Create a new part

View File

@@ -4,7 +4,7 @@
#include <iostream>
#include <vector>
#include "factory.hpp"
#include "abstract-factory.hpp"
int main(const int argc, const char * argv[]) {
// Testing GearFactory

View File

@@ -1,12 +1,13 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A project for practicing the observer C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: A project for practicing the observer C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Observer
VERSION 1.0
@@ -15,6 +16,7 @@ project(
)
add_compile_options("-Wall")
add_library(observer "observer.cpp")
add_executable(observer-test "main.cpp")
target_link_libraries(observer-test observer)
add_executable(
patterns-observer main.cpp
observer.cpp observer.hpp
)

View File

@@ -1,12 +1,13 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A project for practicing the prototype C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: A project for practicing the prototype C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Prototype
VERSION 1.0
@@ -15,6 +16,7 @@ project(
)
add_compile_options("-Wall")
add_library(prototype "prototype.cpp")
add_executable(prototype-test "main.cpp")
target_link_libraries(prototype-test prototype)
add_executable(
patterns-prototype main.cpp
prototype.cpp prototype.hpp
)

View File

@@ -1,11 +1,11 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A project for practicing the singleton C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: A project for practicing the singleton C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
@@ -15,7 +15,8 @@ project(
LANGUAGES CXX
)
add_library(singleton "singleton.cpp")
add_library(singleton-pointer "singleton-pointer.cpp")
add_executable(singleton-test "main.cpp")
target_link_libraries(singleton-test singleton singleton-pointer)
add_executable(
patterns-singleton main.cpp
singleton-pointer.cpp singleton-pointer.hpp
singleton.cpp singleton.hpp
)

View File

@@ -19,7 +19,13 @@ private:
ClassicSingleton(){ message = "New ClassicSingleton\n";}
// Do not allow copying of this object
ClassicSingleton(const ClassicSingleton&){}
// Ignore -Wreturn-type warnings; It's intentional for this pattern
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type"
ClassicSingleton& operator=(const ClassicSingleton&){}
// Unmatched pop reverts GCC to commandline options
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
// Static pointer to instance of this singleton
static ClassicSingleton* instance;

View File

@@ -17,9 +17,15 @@ private:
std::string message;
// Don't allow copying of this class
// Ignore -Wreturn-type warnings; It's intentional for this pattern
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type"
Singleton() { message = "New singleton\n";}
Singleton(const Singleton &) {}
Singleton &operator=(const Singleton &) {}
// Unmatched pop reverts GCC to commandline options
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
};
#endif // SINGLETON_H

View File

@@ -1,12 +1,13 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A project for practicing the state C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: A project for practicing the state C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] State
VERSION 1.0
@@ -15,6 +16,7 @@ project(
)
add_compile_options("-Wall")
add_library(state "state.cpp")
add_executable(state-test "main.cpp")
target_link_libraries(state-test state)
add_executable(
patterns-state main.cpp
state.cpp state.hpp
)

View File

@@ -1,12 +1,13 @@
###############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2021 Shaun Reed, all rights reserved ##
## About: A project for practicing the visitor C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################
#
################################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
## About: A project for practicing the visitor C++ design pattern ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
################################################################################
cmake_minimum_required(VERSION 3.15)
project(
#[[NAME]] Visitor
VERSION 1.0
@@ -15,6 +16,7 @@ project(
)
add_compile_options("-Wall")
add_library(visitor "visitor.cpp")
add_executable(visitor-test "main.cpp")
target_link_libraries(visitor-test visitor)
add_executable(
patterns-visitor main.cpp
visitor.cpp visitor.hpp
)