-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
131 lines (110 loc) · 4.3 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# \file CMakeLists.txt
# \author https://github.com/infojg9
# \brief CMake cross platform friendly build script
# \copyright MIT/BSD Redistributable License
# Minimum 3.1 since using Threads::Threads imported target
cmake_minimum_required(VERSION 3.1)
project(CDesignPatterns)
string(TIMESTAMP TS "%Y-%m-%d %H:%M:%S")
file (STRINGS "${PROJECT_SOURCE_DIR}/VERSION" PACKAGE_VERSION)
message(STATUS "CDesignPatterns package version: ${PACKAGE_VERSION}")
set(CMAKE_CXX_STANDARD 14)
# Select pthread over other options
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
# Enabled Threading support
find_package(Threads REQUIRED)
# Enabled Boost build support
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
#Bind to minimum version: find_package(Boost 1.58.0 COMPONENTS date_time filesystem system)
find_package(Boost COMPONENTS system filesystem REQUIRED)
if(NOT MSVC_IDE)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None Debug Release" FORCE)
endif()
endif()
if (CMAKE_BUILD_TYPE STREQUAL "")
set( CMAKE_BUILD_TYPE "RelWithDebInfo" )
endif()
macro(force_static_build)
if(MSVC)
message(STATUS "CDesignPatterns build compiler: MSVC")
set(MSVC_RUNTIME "static")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "/MP")
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
elseif(${CMAKE_GENERATOR} MATCHES "Unix Makefiles")
message(STATUS "CDesignPatterns build compiler: Unix Makefiles")
#When custom build script required: set(CMAKE_MAKE_PROGRAM "${PROJECT_BINARY_DIR}/Multibuild.sh")
function(CountCpuCore N)
if(NOT N EQUAL 0)
set(CTEST_BUILD_FLAGS -j${N})
set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N})
message(STATUS "CDesignPatterns build: ctest_test_args: ${ctest_test_args} PARALLEL_LEVEL: ${N}")
endif()
endfunction(CountCpuCore)
SET(CpuCore 4)
CountCpuCore(${CpuCore})
else()
message(STATUS "CDesignPatterns build compiler: ${CMAKE_GENERATOR}")
endif()
endmacro()
force_static_build()
set(SOURCE_FILES
# Added Pimple::V1 source
Pimple/CPointerToImplementation.h
Pimple/CPointerToImplementation.cpp
# Added CSingleton::V1 source
Singleton/CSingleton.h
Singleton/CSingleton.cpp
# Added Factory::V1 source
Factory/IFactoryInterface.h
Factory/CFactoryMaker.h
Factory/CFactoryMaker.cpp
Factory/CFactoryMakerConsumer.cpp
# Added Observer::V1 source
Observer/IObserverInterface.h
Observer/CObserverEventGenerator.h
Observer/CObserverEventGenerator.cpp
Observer/CObserverConsumer.cpp
Observer/CObserverEventCollector.cpp
# Added SignalSlotV1::V1 source
SignalSlotV1/CSignalSlotType1.h
SignalSlotV1/CSignalSlotImpl.cpp
# Added SignalSlotV1::V2 source
SignalSlotV2/CSignalSlotType2.h
# Added Facade
Facade/CMakeFacade.h
Facade/CCollectionClasses.cpp
Facade/CMakeFacade.cpp
# Test code: Gtest build support would be ideal
main.cpp
)
add_executable(CDesignPatterns ${SOURCE_FILES})
list(APPEND CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v -pipe -Wchkp -Wdouble-promotion -Wformat -ftest-coverage -fprofile-arcs -funroll-loops")
target_compile_options(CDesignPatterns PUBLIC -Wall -Wextra -Werror -pedantic -O0 -g3 -ggdb3)
# Alternative: Append -DGENERIC_DELEGATE_ON with CMAKE_CXX_FLAGS
target_compile_definitions(CDesignPatterns PUBLIC GENERIC_DELEGATE_ON)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(CDesignPatterns PUBLIC ${Boost_LIBRARIES} Threads::Threads)
endif()
# Alternatively: target_link_libraries(CDesignPatterns ${CMAKE_THREAD_LIBS_INIT} )
target_compile_features(CDesignPatterns PUBLIC cxx_auto_type cxx_noexcept cxx_nullptr cxx_range_for)
# Support for older compilers: set_target_properties(CDesignPatterns PROPERTIES CXX_STANDARD 14)