forked from SICKAG/sick_visionary_cpp_base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
266 lines (234 loc) · 8.05 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
#
# Copyright (c) 2023,2024 SICK AG, Waldkirch
#
# SPDX-License-Identifier: Unlicense
cmake_minimum_required(VERSION 3.16)
message(STATUS sick_visionary_cpp_base)
project(sick_visionary_cpp_base
VERSION 1.0.0
DESCRIPTION "Visionary access via network"
HOMEPAGE_URL "https://github.com/SICKAG/sick_visionary_cpp_base"
LANGUAGES CXX)
### Options
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
option(VISIONARY_BASE_ENABLE_AUTOIP "Enables the SOPAS Auto-IP device scan code (needs boost's ptree)" ON)
option(VISIONARY_BASE_ENABLE_UNITTESTS "Enables google-test based unit tests" OFF)
option(VISIONARY_BASE_INTERNAL_USE_CONAN "(internal) Build using Conan package manager" OFF)
option(VISIONARY_BASE_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_BASE_PRIVATE_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/3pp/md5
${CMAKE_CURRENT_SOURCE_DIR}/3pp/sha256)
set(VISIONARY_BASE_LINK_LIBRARIES)
if (VISIONARY_BASE_ENABLE_AUTOIP)
if (VISIONARY_BASE_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_BASE_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_BASE_LINK_LIBRARIES
${CMAKE_THREAD_LIBS_INIT})
if(WIN32)
list(APPEND VISIONARY_BASE_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_BASE_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
src/CoLaError.cpp
3pp/md5/MD5.cpp 3pp/sha256/SHA256.cpp
src/VisionaryType.cpp
src/VisionaryControl.cpp src/ControlSession.cpp
src/VisionaryDataStream.cpp src/FrameGrabberBase.cpp
src/VisionaryData.cpp src/VisionarySData.cpp src/VisionaryTMiniData.cpp
src/PointCloudPlyWriter.cpp src/NetLink.cpp)
set(VISIONARY_BASE_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/VisionaryType.h
src/ControlSession.h src/VisionaryControl.h
src/FrameGrabberBase.h src/FrameGrabber.h src/VisionaryDataStream.h
src/VisionaryData.h src/VisionarySData.h src/VisionaryTMiniData.h
src/PointCloudPlyWriter.h src/PointXYZ.h src/NetLink.h)
if(VISIONARY_BASE_ENABLE_AUTOIP)
message(STATUS "SOPAS AutoIP support is built")
list(APPEND VISIONARY_BASE_SRCS src/VisionaryAutoIP.cpp)
list(APPEND VISIONARY_BASE_PUBLIC_HEADERS src/VisionaryAutoIP.h)
endif()
target_sources(${TARGET_NAME}
PUBLIC
PRIVATE
${VISIONARY_BASE_SRCS} ${VISIONARY_BASE_PUBLIC_HEADERS})
target_include_directories(${TARGET_NAME}
PUBLIC
"$<INSTALL_INTERFACE:include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
PRIVATE
${VISIONARY_BASE_PRIVATE_INCLUDE_DIRS}
)
target_link_libraries(${TARGET_NAME} ${VISIONARY_BASE_LINK_LIBRARIES})
# configure warnings
if (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") AND (NOT DEFINED VISIONARY_BASE_CFLAGS))
set(VISIONARY_BASE_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_BASE_CFLAGS))
set(VISIONARY_BASE_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_BASE_ENABLE_CODE_COVERAGE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(STATUS "Enabling coverage instrumentation")
list(APPEND VISIONARY_BASE_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_BASE_CFLAGS})
# Installation
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
COMPATIBILITY SameMajorVersion)
install(TARGETS ${TARGET_NAME}
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(
EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
install(FILES ${VISIONARY_BASE_PUBLIC_HEADERS} DESTINATION include/${PROJECT_NAME})
# Unit tests
# find GoogleTest, using 'non-standard' form of e.g. CONAN packages
if(VISIONARY_BASE_ENABLE_UNITTESTS)
message(STATUS "Enabling unit tests")
if(VISIONARY_BASE_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()