-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
260 lines (227 loc) · 7.46 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
#
# Copyright (c) 2023 SICK AG, Waldkirch
#
# SPDX-License-Identifier: Unlicense
cmake_minimum_required(VERSION 3.16)
project(sick_visionary_cpp_shared
VERSION 2.5.0
DESCRIPTION "Visionary access via network"
HOMEPAGE_URL "https://github.com/SICKAG/sick_visionary_cpp_shared"
LANGUAGES CXX)
### Options
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
option(VISIONARY_SHARED_ENABLE_AUTOIP "Enables the SOPAS Auto-IP device scan code (needs boost's ptree)" ON)
option(VISIONARY_SHARED_ENABLE_UNITTESTS "Enables google-test based unit tests" OFF)
option(VISIONARY_SHARED_ENABLE_AUTOIP "Enables the SOPAS Auto-IP device scan code (needs boost's ptree)" ON)
option(VISIONARY_SHARED_INTERNAL_USE_CONAN "(internal) Build using Conan package manager" OFF)
option(VISIONARY_SHARED_USE_BUNDLED_BOOST "Uses the bundled Boost implementation" ON)
### COMPILER FLAGS ###
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
### create the target
set(TARGET_NAME ${PROJECT_NAME})
add_library(${TARGET_NAME})
### Dependencies
set(VISIONARY_SHARED_PRIVATE_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/3pp/md5
${CMAKE_CURRENT_SOURCE_DIR}/3pp/sha256)
set(VISIONARY_SHARED_LINK_LIBRARIES)
if (VISIONARY_SHARED_ENABLE_AUTOIP)
if (VISIONARY_SHARED_USE_BUNDLED_BOOST)
message(STATUS "Using bundled Boost")
# include path must must be set explicitely, otherwise when using find_package with 3pp a previous outside find_package(Boost) would take precendence
list(APPEND
VISIONARY_SHARED_PRIVATE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/3pp)
else()
# require minimum version when property_tree was introduced - 1.41 (foreach is even older)
find_package(Boost 1.41 REQUIRED)
target_link_libraries(${TARGET_NAME} Boost::boost)
endif()
endif()
find_package(Threads)
list(APPEND VISIONARY_SHARED_LINK_LIBRARIES
${CMAKE_THREAD_LIBS_INIT})
if(WIN32)
list(APPEND VISIONARY_SHARED_LINK_LIBRARIES
wsock32 ws2_32)
endif()
### BUILD ###
if (BUILD_SHARED_LIBS)
message(STATUS "A shared library will be generated")
endif()
set_target_properties(${TARGET_NAME} PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS OFF)
set (VISIONARY_SHARED_SRCS
src/UdpSocket.cpp src/TcpSocket.cpp
src/CoLaBProtocolHandler.cpp src/CoLa2ProtocolHandler.cpp
src/AuthenticationLegacy.cpp src/AuthenticationSecure.cpp
src/CoLaParameterReader.cpp src/CoLaParameterWriter.cpp
src/CoLaCommand.cpp src/CoLaParameterReader.cpp src/CoLaParameterWriter.cpp
3pp/md5/MD5.cpp 3pp/sha256/SHA256.cpp
src/VisionaryControl.cpp src/ControlSession.cpp
src/VisionaryDataStream.cpp src/FrameGrabberBase.cpp
src/VisionaryData.cpp src/VisionarySData.cpp src/VisionaryTData.cpp src/VisionaryTMiniData.cpp
src/PointCloudPlyWriter.cpp)
set(VISIONARY_SHARED_PUBLIC_HEADERS
src/UdpSocket.h src/TcpSocket.h src/ITransport.h
src/CoLaBProtocolHandler.h src/CoLa2ProtocolHandler.h src/IProtocolHandler.h
src/AuthenticationLegacy.h src/AuthenticationSecure.h src/IAuthentication.h
src/CoLaParameterReader.h src/CoLaParameterWriter.h
src/CoLaCommand.h src/CoLaCommandType.h src/CoLaError.h
src/ControlSession.h src/VisionaryControl.h
src/FrameGrabberBase.h src/FrameGrabber.h src/VisionaryDataStream.h
src/VisionaryData.h src/VisionarySData.h src/VisionaryTData.h src/VisionaryTMiniData.h
src/PointCloudPlyWriter.h src/PointXYZ.h)
if(VISIONARY_SHARED_ENABLE_AUTOIP)
message(STATUS "SOPAS AutoIP support is built")
list(APPEND VISIONARY_SHARED_SRCS src/VisionaryAutoIPScan.cpp)
list(APPEND VISIONARY_SHARED_PUBLIC_HEADERS src/VisionaryAutoIPScan.h)
endif()
target_sources(${TARGET_NAME}
PUBLIC
PRIVATE
${VISIONARY_SHARED_SRCS} )
target_include_directories(${TARGET_NAME}
PUBLIC
"$<INSTALL_INTERFACE:include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
PRIVATE
${VISIONARY_SHARED_PRIVATE_INCLUDE_DIRS}
)
target_link_libraries(${TARGET_NAME} ${VISIONARY_SHARED_LINK_LIBRARIES})
# configure warnings
if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") AND (NOT DEFINED VISIONARY_SHARED_CFLAGS))
set(VISIONARY_SHARED_CFLAGS
-Werror
-Wall
-Wextra
-Wsign-conversion
-Wsign-compare
-Wfloat-equal
-Wunused-value
-Wunused-but-set-variable
-Wtype-limits
-Wshadow
-Wconversion-null
-pedantic
-Wcast-align
-Wcast-qual
-Wformat
-Wformat-nonliteral
-Wformat-security
-Winit-self
-Wuninitialized
-Wmissing-declarations
-Wlogical-op
-Wmissing-include-dirs
-Wold-style-cast
-Wpointer-arith
-Wunreachable-code
-Wnormalized=nfc
-Wwrite-strings
-Wvla
-fstrict-aliasing
-Wstrict-overflow=2
-Woverloaded-virtual
-Wsign-promo
-ffunction-sections
-fdata-sections
)
elseif (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") AND (NOT DEFINED VISIONARY_SHARED_CFLAGS))
set(VISIONARY_SHARED_CFLAGS
/W4
/WX
/w44060
/w44063
/w44065
/w45204
/w45205
/w44181
/w44203
/w44301
/w44303
/w44318
/w44327
/w44328
/w44413
/w44482
/w44854
/w45054
/w45055
/w45056
/w45062
/w45219
)
endif() # compilers
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set_source_files_properties(3pp/md5/MD5.cpp PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast -Wno-sign-conversion")
set_source_files_properties(3pp/sha256/SHA256.cpp PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast -Wno-cast-qual")
set_source_files_properties(src/CoLaBProtocolHandler.cpp PROPERTIES COMPILE_FLAGS "-Wno-stringop-overflow")
set_source_files_properties(src/CoLa2ProtocolHandler.cpp PROPERTIES COMPILE_FLAGS "-Wno-stringop-overflow")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set_source_files_properties(3pp/md5/MD5.cpp PROPERTIES COMPILE_FLAGS "-D _CRT_SECURE_NO_WARNINGS /wd4267")
endif() # compilers
# coverage
if(VISIONARY_SHARED_ENABLE_CODE_COVERAGE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(STATUS "Enabling coverage instrumentation")
list(APPEND VISIONARY_SHARED_CFLAGS -fprofile-arcs -ftest-coverage)
target_link_libraries(${TARGET_NAME} gcov)
else()
message(ERROR "Coverage can be only enabled for gcc")
endif()
endif()
# apply options
target_compile_options(${TARGET_NAME} PRIVATE ${VISIONARY_SHARED_CFLAGS})
# Installation
include(GNUInstallDirs)
install(TARGETS ${TARGET_NAME}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT
Development
)
install(
FILES
${VISIONARY_SHARED_PUBLIC_HEADERS}
TYPE
INCLUDE
)
# Unit tests
# find GoogleTest, using 'non-standard' form of e.g. CONAN packages
if(VISIONARY_SHARED_ENABLE_UNITTESTS)
message(STATUS "Enabling unit tests")
if(VISIONARY_SHARED_INTERNAL_USE_CONAN)
find_package(GoogleTest)
if (GoogleTest_FOUND)
message(STATUS "CONAN GoogleTest package found")
set(GTest_FOUND ON)
set(GTest_target GoogleTest::GoogleTest)
endif()
else()
# now try the standard form we unify it to "GTest"
find_package(GTest)
if(GTest_FOUND)
message(STATUS "GTest found")
set(GTest_target GTest::gtest)
endif()
endif()
if(GTest_FOUND)
enable_testing()
add_subdirectory(${PROJECT_SOURCE_DIR}/tests)
message(STATUS "Building unit tests")
else()
message(STATUS "GTest not found. Tests are not built")
endif()
endif()