-
Notifications
You must be signed in to change notification settings - Fork 14
/
CMakeLists.txt
249 lines (198 loc) · 11 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# cmake version
# Note: Some of the functions need at least 3.5
cmake_minimum_required(VERSION 3.5.0)
#set(CMAKE_VERBOSE_MAKEFILE ON)
################################################################################
# Using own CMake Modules
# Add this to your cmake modules path to find the SDCLib Finder
################################################################################
get_filename_component(PROJECT_CMAKE_MODULES ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules REALPATH)
message(STATUS "Adding ${PROJECT_CMAKE_MODULES} to Modules Path...")
list(APPEND CMAKE_MODULE_PATH ${PROJECT_CMAKE_MODULES})
################################################################################
################################################################################
# RPATH Settings
# NOTE: Set the RPath to the "Current Directory". (Portability)
################################################################################
set(CMAKE_INSTALL_RPATH ".")
################################################################################
################################################################
# C++ standard
################################################################################
message(STATUS "Setting CXX_STANDARD...")
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ Standard" FORCE)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_EXTENSIONS OFF)
################################################################################
################################################################################
# Main Project
################################################################################
set( PROJECT_NAME "SDCLibrary") # in case you need it in a config file
project(${PROJECT_NAME} "CXX")
# Version numbers -> Will be written to the config file
set (SDCLibrary_VERSION_FIRST 4)
set (SDCLibrary_VERSION_MIDDLE 5)
set (SDCLibrary_VERSION_LAST 1)
set (SDCLibrary_C_YEAR 2020)
set (SDCLibrary_SurgiTAIX "SurgiTAIX AG")
################################################################################
# Check Compiler Version
################################################################################
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.1)
message(FATAL_ERROR "GCC version must be at least 4.8.1!")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3)
message(FATAL_ERROR "Clang version must be at least 3.3!")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
message(FATAL_ERROR "MSVC version must be at least 18.0!")
endif()
else()
message(FATAL_ERROR "No supported Compiler detected. Checked for GCC(4.8.1+), Clang(3.3+) or MSVC(18.0+).")
endif()
################################################################################
################################################################################
# What to enable?
################################################################################
# Tests - Default to ON
set (SDC_TESTS ON CACHE STRING "Enable Building Tests")
set_property(CACHE SDC_TESTS PROPERTY STRINGS "ON" "OFF")
# Examples - Default to ON
set (SDC_EXAMPLES ON CACHE STRING "Enable Building Examples")
set_property(CACHE SDC_EXAMPLES PROPERTY STRINGS "ON" "OFF")
# Advanced Examples - Default to OFF
set (SDC_ADVANCED_EXAMPLES OFF CACHE STRING "Enable Building Advance Example")
set_property(CACHE SDC_ADVANCED_EXAMPLES PROPERTY STRINGS "ON" "OFF")
# CPPCHECK - WIP (OFF for now)
set (SDC_CPPCHECK OFF CACHE STRING "Enable CPPCHECK (only available for CMAKE 3.10 or higher).")
set_property(CACHE SDC_CPPCHECK PROPERTY STRINGS "ON" "OFF")
# STATIC OR DYNAMIC LINKING - Default to ON
set(SDCLib_DYNAMIC_LINKING ON CACHE STRING "Enable dynamic Linking")
set_property(CACHE SDCLib_DYNAMIC_LINKING PROPERTY STRINGS "ON" "OFF")
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(SDCLib_DYNAMIC_LINKING OFF CACHE STRING "Enable dynamic Linking (Disabled on windows by default)" FORCE)
endif()
################################################################################
################################################################################
# Enable to make Poco and SDCLib work when build as static/shared
################################################################################
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
################################################################################
################################################################################
# Bin and Install prefix
################################################################################
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message(STATUS "Default install prefix init to default, manually setting one...")
set (CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE STRING "Where to install the binaries?" FORCE)
endif()
# Note: https://cmake.org/cmake/help/latest/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.html
# "Multi-configuration generators (VS, Xcode) append a per-configuration
# subdirectory to the specified directory unless a generator expression is used."
# -> Append empty generator expression.
#
# Use the _ROOT Version for all processes during "configure" phase (like configure_file)
# Use the other Version for all processes during "generator" phase
set(PATH_RUNTIME_OUTPUT_ROOT ${CMAKE_BINARY_DIR}/bin)
set(PATH_LIBRARY_OUTPUT_ROOT ${CMAKE_BINARY_DIR}/bin)
set(PATH_ARCHIVE_OUTPUT_ROOT ${CMAKE_BINARY_DIR}/lib)
set(PATH_RUNTIME_OUTPUT ${PATH_RUNTIME_OUTPUT_ROOT}/$<0:>)
set(PATH_LIBRARY_OUTPUT ${PATH_LIBRARY_OUTPUT_ROOT}/$<0:>)
set(PATH_ARCHIVE_OUTPUT ${PATH_ARCHIVE_OUTPUT_ROOT}/$<0:>)
set(CMAKE_DEBUG_POSTFIX _d) # Force the Debug Postfix
# by "default" take the install prefix
set(PATH_INSTALL_RUNTIME bin/$<0:>)
set(PATH_INSTALL_LIBRARY bin/$<0:>)
set(PATH_INSTALL_ARCHIVE lib/$<0:>)
set(PATH_INSTALL_INCLUDE include/$<0:>)
################################################################################
################################################################################
# Targets
# Overwrite
################################################################################
set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING "Config Types" FORCE)
# None specified?
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type specified, setting to Debug.")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Debug as default" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug")
endif()
################################################################################
################################################################################
# Firewall - Allowed Ports
# Note: For the UnitTests and Examples to work, make sure in- and outbound
# traffic on this portrange is allowed
# With ufw just run: sudo ufw allow <startport>:<endport>/tcp (or udp)
################################################################################
# Note: Just randomly took a port range that is not densly occupied from:
# https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
# NOTE: CURRENTLY NOT IN USE!
set(SDC_ALLOWED_PORT_START 14000 CACHE STRING "Start Port of allowed port range. [Make sure your firewall settings match these value]" FORCE)
set(SDC_ALLOWED_PORT_RANGE 2000 CACHE STRING "Port Range of allowed ports as offset from the Start Port. [Make sure your firewall settings match these value]" FORCE)
set(SDC_DEFAULT_PORT_RANGE 1000 CACHE STRING "Passed default Port Range if none is specified in configuration." FORCE)
mark_as_advanced(SDC_ALLOWED_PORT_START)
mark_as_advanced(SDC_ALLOWED_PORT_RANGE)
mark_as_advanced(SDC_DEFAULT_PORT_RANGE)
set(SDC_DISCOVERY_TIMEOUT_MS 5000 CACHE STRING "Time in milliseconds a Discovery until timeout." FORCE)
mark_as_advanced(SDC_DISCOVERY_TIMEOUT_MS)
set(SDC_CONNECTION_TIMEOUT_MS 2000 CACHE STRING "Time in milliseconds the SDCLib will check if the connection is lost." FORCE)
mark_as_advanced(SDC_CONNECTION_TIMEOUT_MS)
set(SDC_MAX_KNOWN_MESSAGE_IDS 200 CACHE STRING "Limits the maximum number of MessageIDs a Messaging Context caches. Be careful with this value!" FORCE)
mark_as_advanced(SDC_MAX_KNOWN_MESSAGE_IDS)
set(SDC_IP_V4_ENABLED true CACHE STRING "Enable IPv4 by default or not." FORCE)
set(SDC_IP_V6_ENABLED false CACHE STRING "Enable IPv6 by default or not." FORCE)
mark_as_advanced(SDC_IP_V4_ENABLED)
mark_as_advanced(SDC_IP_V6_ENABLED)
################################################################################
################################################################################
# Some more paths - cleaned from symlinks
# Note: Use these in the other CMakeLists for easier handling
################################################################################
get_filename_component(PATH_SRC_ROOT ${CMAKE_CURRENT_LIST_DIR}/src/ REALPATH)
get_filename_component(PATH_INCLUDE_ROOT ${CMAKE_CURRENT_LIST_DIR}/include/ REALPATH)
get_filename_component(PATH_DATAMODEL_ROOT ${CMAKE_CURRENT_LIST_DIR}/datamodel/ REALPATH)
get_filename_component(PATH_EXAMPLES_ROOT ${CMAKE_CURRENT_LIST_DIR}/Examples/ REALPATH)
get_filename_component(PATH_TESTS_ROOT ${CMAKE_CURRENT_LIST_DIR}/Tests/ REALPATH)
get_filename_component(PATH_SDCTESTS_ROOT ${PATH_TESTS_ROOT}/SDCTests/ REALPATH)
################################################################################
################################################################################
# config
# Note: Make sure all values are set before doing this!
################################################################################
set(CONFIG_DIR ${CMAKE_CURRENT_LIST_DIR}/include/config)
# configure
message(STATUS "Configuring ${PROJECT_NAME}...")
configure_file (${CONFIG_DIR}/config.h.in ${CONFIG_DIR}/config.h)
################################################################################
################################################################################
# Doxygen config
# Note: Make sure all values are set before doing this!
################################################################################
# configure
message(STATUS "Configuring Doxygen files...")
get_filename_component(SDC_PATH_DOXYGEN ${CMAKE_CURRENT_LIST_DIR}/doc/Doxygen REALPATH)
configure_file(${SDC_PATH_DOXYGEN}/Doxyfile.in ${SDC_PATH_DOXYGEN}/Doxyfile)
configure_file(${SDC_PATH_DOXYGEN}/Mainpage.h.in ${SDC_PATH_DOXYGEN}/Mainpage.h)
################################################################################
################################################################################
# Configuration Done
# Now add the subdirs
# Note: Inside the subdirs only work by including. See other files
message(STATUS "Adding Targets...")
################################################################################
find_package(SDCLib)
# datamodel
add_subdirectory(${PATH_DATAMODEL_ROOT})
# src folder
add_subdirectory(${PATH_SRC_ROOT})
# Examples
if(SDC_EXAMPLES)
add_subdirectory(${PATH_EXAMPLES_ROOT})
endif()
# Tests
if(SDC_TESTS)
add_subdirectory(${PATH_TESTS_ROOT})
ENDIF()
#...