-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
277 lines (228 loc) · 8.98 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#
# Copyright (c) 2017 Leon Mlakar.
# Copyright (c) 2017 Digiverse d.o.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. The
# license should be included in the source distribution of the Software;
# if not, you may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# The above copyright notice and licensing terms shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
project (cool.ng)
cmake_minimum_required(VERSION 3.5)
# ### ##################################################
# ###
# ### Build control variables that may get set from
# ### outside to integrate into larger projects
# ###
# ### ##################################################
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# ### ##################################################
# ###
# ### Platform identification and compiler setup
# ###
# ### ##################################################
if( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
# --- Apple OS/X
set( OSX true)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -fPIC -fbracket-depth=10000" )
set( CMAKE_EXE_LINKER_FLAGS "-w" )
elseif( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
# --- Linux
set( LINUX true )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -fPIC" )
elseif (MSVC)
# --- Windows
set( WINDOWS true )
# CMake incorrectly appends "/machine:X86" to all linker flags when static
# libraries are used, resulting in invalid builds:
# > fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
# (ref. https://public.kitware.com/Bug/view.php?id=15496)
if (CMAKE_GENERATOR MATCHES "Win64")
set( CMAKE_EXE_LINKER_FLAGS "/machine:X64" )
set( CMAKE_MODULE_LINKER_FLAGS "/machine:X64" )
set( CMAKE_SHARED_LINKER_FLAGS "/machine:X64" )
endif()
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /bigobj /Zm750 -D_SCL_SECURE_NO_WARNINGS")
else()
# --- unknown target
message( FATAL "unsupported platform" )
endif()
include( Component.cmake )
# ### ##################################################
# ###
# ### Doxygen documentation
# ###
# ### ##################################################
if (COOL_NG_BUILD_DOC)
find_package(Doxygen)
if (NOT Doxygen_FOUND)
message(WARNING "Doxygen package not found, will not generate documentation")
else ()
make_directory (${COOL_NG_DOC_DIR})
configure_file(
${COOL_NG_HOME}/cool.ng.dox.in
${COOL_NG_DOC_DIR}/cool.ng.dox
@ONLY
)
add_custom_command(
OUTPUT ${COOL_NG_DOC_DIR}/doc/html/index.html
COMMAND ${DOXYGEN_EXECUTABLE} ${COOL_NG_DOC_DIR}/cool.ng.dox
DEPENDS ${COOL_NG_API_HEADERS} ${COOL_NG_HOME}/mainpage.dox
WORKING_DIRECTORY ${COOL_NG_DOC_DIR}
)
add_custom_target(doc ALL DEPENDS ${COOL_NG_DOC_DIR}/doc/html/index.html)
endif()
endif()
# ### ##################################################
# ###
# ### Unit tests
# ###
# ### ##################################################
set( HEADER_ONLY_UNIT_TESTS
traits
task-traits
)
# unit tests for library internals, require static lib owing to MS dll export/import
set( LIBRARY_UNIT_TESTS
executor
)
# api level unit tests, will use dynamic library
set( API_UNIT_TESTS
simple_task
sequential_task
intercept_task
conditional_task
repeat_task
loop_task
ip_address
es_reader
es_timer
)
set( traits_SRCS tests/unit/traits/traits.cpp )
set( task-traits_SRCS tests/unit/traits/task_traits.cpp )
set( executor_SRCS tests/unit/executor/executor.cpp )
set( simple_task_SRCS tests/unit/task/simple_task.cpp )
set( sequential_task_SRCS tests/unit/task/sequential_task.cpp )
set( intercept_task_SRCS tests/unit/task/intercept_task.cpp )
set( conditional_task_SRCS tests/unit/task/conditional_task.cpp )
set( repeat_task_SRCS tests/unit/task/repeat_task.cpp )
set( loop_task_SRCS tests/unit/task/loop_task.cpp )
set( ip_address_SRCS tests/unit/net/ip_address.cpp )
set( es_reader_SRCS tests/unit/event_sources/es_reader.cpp )
set( es_timer_SRCS tests/unit/event_sources/es_timer.cpp )
macro(header_unit_test TestName)
add_executable( ${TestName}-test ${ARGN} )
target_link_libraries( ${TestName}-test ${Boost_LIBRARIES} ${COOL_NG_PLATFORM_LIBRARIES} )
set_target_properties( ${TestName}-test PROPERTIES
COMPILE_FLAGS -DBOOST_TEST_DYN_LINK
RUNTIME_OUTPUT_DIRECTORY ${COOL_NG_TEST_DIR}
FOLDER "Unit Tests/Header"
)
target_include_directories( ${TestName}-test PUBLIC ${COOL_NG_COMPONENT_INCLUDE_DIRECTORIES})
add_test( NAME ${TestName} COMMAND ${TestName}-test )
endmacro()
macro(internal_unit_test TestName)
add_executable( ${TestName}-test ${ARGN} )
target_link_libraries( ${TestName}-test cool.ng-dev ${Boost_LIBRARIES} ${COOL_NG_PLATFORM_LIBRARIES} )
set_target_properties( ${TestName}-test PROPERTIES
COMPILE_FLAGS -DBOOST_TEST_DYN_LINK
RUNTIME_OUTPUT_DIRECTORY ${COOL_NG_TEST_DIR}
FOLDER "Unit Tests/Internal"
)
target_compile_definitions(${TestName}-test PUBLIC "-DCOOL_NG_STATIC_LIBRARY")
add_test( NAME ${TestName} COMMAND ${TestName}-test )
endmacro()
macro(api_unit_test TestName)
add_executable( ${TestName}-test ${ARGN} )
target_link_libraries( ${TestName}-test cool.ng-dyn-dev ${Boost_LIBRARIES} ${COOL_NG_PLATFORM_LIBRARIES} )
set_target_properties( ${TestName}-test PROPERTIES
COMPILE_FLAGS -DBOOST_TEST_DYN_LINK
RUNTIME_OUTPUT_DIRECTORY ${COOL_NG_TEST_DIR}
FOLDER "Unit Tests/API"
)
add_test( NAME ${TestName} COMMAND ${TestName}-test )
endmacro()
if( COOL_NG_UNIT_TESTS )
if ( WINDOWS )
if (NOT DEFINED BOOST_ROOT AND WINDOWS)
set( BOOST_ROOT "c:/local/boost/boost_1_62_0" )
endif()
if ( MSVC_VERSION EQUAL "1800" )
set( BOOST_LIBRARYDIR "${BOOST_ROOT}/lib64-msvc-12.0")
else()
set( BOOST_LIBRARYDIR "${BOOST_ROOT}/lib64-msvc-14.0")
endif()
endif()
# unit tests require Boost.Test library
set( Boost_USE_STATIC_LIBS OFF )
set( Boost_USE_MULTITHREADED ON )
set( Boost_USE_STATIC_RUNTIME OFF )
find_package( Boost 1.58.0 COMPONENTS unit_test_framework)
if( NOT Boost_FOUND )
message( WARNING "Boost.Test package is required to build unit tests. Will disable unit tests compilation and proceed without Boost.Test" )
set( COOL_NG_UNIT_TESTS false )
else()
message("-- Boost found, version ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}.")
message(" Include directory: ${Boost_INCLUDE_DIR}")
message(" Library directory: ${Boost_LIBRARY_DIRS}")
endif()
endif()
if( COOL_NG_UNIT_TESTS )
include_directories( SYSTEM ${Boost_INCLUDE_DIR} )
link_directories( ${Boost_LIBRARY_DIRS} )
enable_testing()
# --- unit tests for internal header stuff
foreach( ut ${HEADER_ONLY_UNIT_TESTS} )
header_unit_test( ${ut} ${${ut}_SRCS} )
set( HEADER_ONLY_UNIT_TESTS_SOURCES ${HEADER_ONLY_UNIT_TESTS_SOURCES} ${${ut}_SRCS} )
endforeach()
# --- unit tests for internal stuff using static library
foreach( ut ${LIBRARY_UNIT_TESTS} )
internal_unit_test( ${ut} ${${ut}_SRCS} )
set( LIBRARY_UNIT_TESTS_SOURCES ${LIBRARY_UNIT_TESTS_SOURCES} ${${ut}_SRCS} )
endforeach()
# --- API unit tests using dynamic library
foreach( ut ${API_UNIT_TESTS} )
api_unit_test( ${ut} ${${ut}_SRCS} )
set( LIBRARY_UNIT_TESTS_SOURCES ${LIBRARY_UNIT_TESTS_SOURCES} ${${ut}_SRCS} )
endforeach()
endif()
# ### ##################################################
# ###
# ### Source organization for IDEs
# ###
# ### ##################################################
source_group( "API Header Files" FILES ${COOL_NG_API_HEADERS} )
source_group( "Impl Header Files" FILES ${COOL_NG_IMPL_HEADERS} )
source_group( "Header Unit Tests" FILES ${HEADER_ONLY_UNIT_TESTS_SOURCES} )
source_group( "Library Unit Tests" FILES ${LIBRARY_UNIT_TESTS_SOURCES} )
source_group( "GCD Specific Files" FILES ${COOL_NG_GCD_IMPL_HEADERS} ${COOL_NG_GCD_IMPL_SRCS} )
source_group( "Windows Specific Files" FILES ${COOL_NG_WINCP_IMPL_HEADERS} ${COOL_NG_WINCP_IMPL_SRCS} )
source_group( "Library Files" FILES ${COOL_NG_LIB_HEADERS} ${COOL_NG_LIB_SRCS} )
source_group( "Documentation" FILES ${COOL_NG_HOME}/mainpage.dox )
# --- custom target listing all source files (for IDEs only)
add_custom_target("All-Sources" SOURCES
${COOL_NG_API_HEADERS}
${COOL_NG_IMPL_HEADERS}
${COOL_NG_GCD_IMPL_HEADERS}
${COOL_NG_GCD_IMPL_SRCS}
${COOL_NG_WINCP_IMPL_HEADERS}
${COOL_NG_WINCP_IMPL_SRCS}
${COOL_NG_LIB_HEADERS}
${COOL_NG_LIB_SRCS}
${HEADER_ONLY_UNIT_TESTS_SOURCES}
${LIBRARY_UNIT_TESTS_SOURCES}
${COOL_NG_HOME}/mainpage.dox
)