-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
235 lines (193 loc) · 5.62 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
cmake_minimum_required(VERSION 3.15...3.18 FATAL_ERROR)
list(PREPEND CMAKE_PREFIX_PATH
${CMAKE_BINARY_DIR})
list(PREPEND CMAKE_MODULE_PATH
${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(default_build_type "Release")
include(cmake/BuildType.cmake)
project(polhemus
VERSION 1.0.0
DESCRIPTION "Library to interface with polhemus sensors")
option(FORCE_COLORED_OUTPUT
"Always produce ANSI-colored output (GNU/Clang only)"
OFF)
option(STATIC_ANALYSIS
"Enable static analysis tools"
OFF)
option(C_BINDINGS
"Enable C bindings"
ON)
if(FORCE_COLORED_OUTPUT OR CMAKE_GENERATOR STREQUAL "Ninja")
add_compile_options(
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-fcolor-diagnostics>)
endif()
set(default_compile_commands_export ON)
include(cmake/ExportCompileCommands.cmake)
find_package(libusb REQUIRED CONFIG)
find_package(fmt REQUIRED CONFIG)
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/polhemus)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set(BUILD_OPTS
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wshadow
-Warray-bounds
-Wstringop-overflow
-Wduplicated-cond
-Wlogical-op
-Wduplicated-branches
-Wnull-dereference
-Wold-style-cast
-Wuseless-cast
-Wformat=2
-Wall
-Wextra
-Wconversion
-Wpedantic
-pipe
$<$<CONFIG:Debug>:
-fsanitize=address
-fsanitize=undefined
>
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>,$<CONFIG:MinSizeRel>>:
-flto
>
>
$<$<CXX_COMPILER_ID:MSVC>:
/W4
>)
################################################################################
### C++ Library
################################################################################
file(GLOB CXX_SRCS
LIST_DIRECTORIES false
CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/cxx/*.cpp")
add_library(polhemus_cxx SHARED ${CXX_SRCS})
add_library(polhemus::polhemus_cxx ALIAS polhemus_cxx)
target_include_directories(polhemus_cxx
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_compile_options(polhemus_cxx PRIVATE ${BUILD_OPTS})
target_compile_features(polhemus_cxx PUBLIC cxx_std_17)
set_target_properties(polhemus_cxx PROPERTIES
EXPORT_NAME
polhemus_cxx
$<STATIC_ANALYSIS:
CXX_CLANG_TIDY
"clang-tidy;-checks=*;-header-filter=.*"
CXX_CPPCHECK
"cppcheck;--std=c++11"
>)
target_link_libraries(polhemus_cxx
PRIVATE
debug "$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:asan;ubsan>"
fmt::fmt
libusb::libusb)
################
## Installation
################
install(TARGETS polhemus_cxx
EXPORT
polhemus-targets
LIBRARY DESTINATION
${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION
${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR})
install(
FILES
include/polhemus.hpp
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR})
################################################################################
### C Bindings
################################################################################
if(C_BINDINGS)
file(GLOB C_SRCS
LIST_DIRECTORIES
false
CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/src/capi/*.cpp")
add_library(polhemus_c SHARED ${C_SRCS})
add_library(polhemus::polhemus_c ALIAS polhemus_c)
target_include_directories(polhemus_c
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_compile_options(polhemus_c PRIVATE ${BUILD_OPTS})
target_compile_features(polhemus_c PUBLIC c_function_prototypes PRIVATE cxx_std_17)
set_target_properties(polhemus_c PROPERTIES
EXPORT_NAME
polhemus_c
$<STATIC_ANALYSIS:
CXX_CLANG_TIDY
"clang-tidy;-checks=*;-header-filter=.*"
CXX_CPPCHECK
"cppcheck;--std=c++11"
>)
target_link_libraries(polhemus_c
PUBLIC
polhemus_cxx
PRIVATE
fmt::fmt
libusb::libusb
debug "$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:asan;ubsan>")
################
## Installation
################
install(TARGETS polhemus_c
EXPORT
polhemus-targets
LIBRARY DESTINATION
${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION
${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR})
install(
FILES
include/polhemus.h
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR})
endif()
################################################################################
### Installation
################################################################################
install(EXPORT polhemus-targets
FILE
polhemusTargets.cmake
NAMESPACE
polhemus::
DESTINATION
${INSTALL_CONFIGDIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/polhemusConfigVersion.cmake
VERSION
${PROJECT_VERSION}
COMPATIBILITY
AnyNewerVersion)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/polhemusConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/polhemusConfig.cmake
INSTALL_DESTINATION
${INSTALL_CONFIGDIR})
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/polhemusConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/polhemusConfigVersion.cmake
DESTINATION
${INSTALL_CONFIGDIR})
export(EXPORT polhemus-targets
FILE
${CMAKE_CURRENT_BINARY_DIR}/polhemusTargets.cmake
NAMESPACE
polhemus::)
export(PACKAGE polhemus)