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:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user