-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
331 lines (289 loc) · 11.6 KB
/
CMakeLists.txt
File metadata and controls
331 lines (289 loc) · 11.6 KB
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# SPDX-License-Identifier: AGPL-3.0
# Copyright (c) 2026 motcpp contributors
cmake_minimum_required(VERSION 3.20)
# Extract version from version.hpp
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/include/motcpp/version.hpp" VERSION_FILE)
string(REGEX MATCH "MOTCPP_VERSION_MAJOR ([0-9]+)" _ ${VERSION_FILE})
set(VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "MOTCPP_VERSION_MINOR ([0-9]+)" _ ${VERSION_FILE})
set(VERSION_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "MOTCPP_VERSION_PATCH ([0-9]+)" _ ${VERSION_FILE})
set(VERSION_PATCH ${CMAKE_MATCH_1})
project(motcpp
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
DESCRIPTION "Modern C++ Multi-Object Tracking Library"
HOMEPAGE_URL "https://github.com/Geekgineer/motcpp"
LANGUAGES CXX
)
# ============================================================================
# Build Options
# ============================================================================
option(MOTCPP_BUILD_TESTS "Build unit tests" ON)
option(MOTCPP_BUILD_BENCHMARKS "Build benchmarks" OFF)
option(MOTCPP_BUILD_EXAMPLES "Build examples" ON)
option(MOTCPP_BUILD_TOOLS "Build command-line tools" ON)
option(MOTCPP_ENABLE_ONNX "Enable ONNX Runtime for ReID" ON)
option(MOTCPP_INSTALL "Generate install target" ON)
option(MOTCPP_COVERAGE "Enable code coverage" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
# ============================================================================
# C++ Standard
# ============================================================================
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Build type
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
message(STATUS "")
message(STATUS "========================================")
message(STATUS " motcpp v${PROJECT_VERSION}")
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "========================================")
message(STATUS "")
# ============================================================================
# Dependencies
# ============================================================================
find_package(OpenCV REQUIRED)
# Eigen3 - accept version 3.3+ or 5.x (Eigen changed versioning scheme)
find_package(Eigen3 CONFIG REQUIRED)
if(NOT Eigen3_FOUND)
find_package(Eigen3 REQUIRED NO_MODULE)
endif()
# yaml-cpp - try new target first, fallback to old
find_package(yaml-cpp REQUIRED)
if(TARGET yaml-cpp::yaml-cpp)
set(YAML_CPP_TARGET yaml-cpp::yaml-cpp)
elseif(TARGET yaml-cpp)
set(YAML_CPP_TARGET yaml-cpp)
else()
message(FATAL_ERROR "yaml-cpp target not found")
endif()
# Optional: ONNX Runtime for ReID models
if(MOTCPP_ENABLE_ONNX)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadONNXRuntime.cmake)
endif()
# Optional: spdlog for logging
find_package(spdlog QUIET)
if(spdlog_FOUND)
message(STATUS "Found spdlog: logging enabled")
else()
message(STATUS "spdlog not found: logging disabled")
endif()
# ============================================================================
# Source Files
# ============================================================================
set(MOTCPP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(MOTCPP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(MOTCPP_SOURCES
# Core
${MOTCPP_SOURCE_DIR}/config.cpp
${MOTCPP_SOURCE_DIR}/tracker.cpp
# Utils
${MOTCPP_SOURCE_DIR}/utils/ops.cpp
${MOTCPP_SOURCE_DIR}/utils/iou.cpp
${MOTCPP_SOURCE_DIR}/utils/association.cpp
${MOTCPP_SOURCE_DIR}/utils/matching.cpp
# Motion models
${MOTCPP_SOURCE_DIR}/motion/kalman_filter.cpp
${MOTCPP_SOURCE_DIR}/motion/kalman_filters/xyah_kf.cpp
${MOTCPP_SOURCE_DIR}/motion/kalman_filters/xysr_kf.cpp
${MOTCPP_SOURCE_DIR}/motion/cmc/cmc.cpp
${MOTCPP_SOURCE_DIR}/motion/cmc/sof.cpp
${MOTCPP_SOURCE_DIR}/motion/cmc/ecc.cpp
# Appearance (ReID)
${MOTCPP_SOURCE_DIR}/appearance/reid_backend.cpp
${MOTCPP_SOURCE_DIR}/appearance/onnx_backend.cpp
# Trackers
${MOTCPP_SOURCE_DIR}/trackers/sort.cpp
${MOTCPP_SOURCE_DIR}/trackers/bytetrack.cpp
${MOTCPP_SOURCE_DIR}/trackers/ocsort.cpp
${MOTCPP_SOURCE_DIR}/trackers/deepocsort.cpp
${MOTCPP_SOURCE_DIR}/trackers/strongsort.cpp
${MOTCPP_SOURCE_DIR}/trackers/botsort.cpp
${MOTCPP_SOURCE_DIR}/trackers/boosttrack.cpp
${MOTCPP_SOURCE_DIR}/trackers/hybridsort.cpp
${MOTCPP_SOURCE_DIR}/trackers/ucmc.cpp
${MOTCPP_SOURCE_DIR}/trackers/oracletrack.cpp
# Data
${MOTCPP_SOURCE_DIR}/data/mot17_dataset.cpp
)
set(MOTCPP_HEADERS
${MOTCPP_INCLUDE_DIR}/motcpp/motcpp.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/version.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/tracker.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/config.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/utils/ops.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/utils/iou.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/utils/association.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/utils/matching.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/utils/mot_format.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/motion/kalman_filter.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/motion/kalman_filters/xyah_kf.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/motion/kalman_filters/xysr_kf.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/motion/kalman_filters/xywh_kf.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/motion/cmc/cmc.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/motion/cmc/sof.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/motion/cmc/ecc.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/appearance/reid_backend.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/appearance/onnx_backend.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/trackers/sort.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/trackers/bytetrack.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/trackers/ocsort.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/trackers/deepocsort.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/trackers/strongsort.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/trackers/botsort.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/trackers/boosttrack.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/trackers/hybridsort.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/trackers/ucmc.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/trackers/oracletrack.hpp
${MOTCPP_INCLUDE_DIR}/motcpp/data/mot17_dataset.hpp
)
# ============================================================================
# Library Target
# ============================================================================
add_library(motcpp ${MOTCPP_SOURCES} ${MOTCPP_HEADERS})
add_library(motcpp::motcpp ALIAS motcpp)
target_include_directories(motcpp
PUBLIC
$<BUILD_INTERFACE:${MOTCPP_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>
)
# Link dependencies
# OpenCV must be PUBLIC as it's used in public headers
# Eigen3 must be PUBLIC as it's used in public headers
# Use OpenCV target if available (handles paths correctly), otherwise use legacy variables
if(TARGET opencv_core)
# Check if opencv_video and opencv_calib3d targets exist before linking
set(OPENCV_LINK_LIBS opencv_core opencv_imgproc opencv_imgcodecs)
if(TARGET opencv_video)
list(APPEND OPENCV_LINK_LIBS opencv_video)
endif()
if(TARGET opencv_calib3d)
list(APPEND OPENCV_LINK_LIBS opencv_calib3d)
endif()
target_link_libraries(motcpp
PUBLIC
${OPENCV_LINK_LIBS}
Eigen3::Eigen
${YAML_CPP_TARGET}
)
else()
target_link_libraries(motcpp
PUBLIC
${OpenCV_LIBS}
Eigen3::Eigen
${YAML_CPP_TARGET}
)
endif()
# ONNX Runtime (optional)
if(MOTCPP_ENABLE_ONNX AND ONNXRUNTIME_FOUND)
target_compile_definitions(motcpp PUBLIC MOTCPP_HAS_ONNX=1)
target_link_libraries(motcpp PRIVATE ${ONNXRUNTIME_LIBRARY})
target_include_directories(motcpp PRIVATE ${ONNXRUNTIME_INCLUDE_DIR})
# RPATH for runtime linking
if(NOT WIN32)
get_filename_component(ONNXRUNTIME_LIB_DIR "${ONNXRUNTIME_LIBRARY}" DIRECTORY)
set_target_properties(motcpp PROPERTIES
INSTALL_RPATH "${ONNXRUNTIME_LIB_DIR}"
BUILD_WITH_INSTALL_RPATH TRUE
)
endif()
endif()
# spdlog (optional)
if(spdlog_FOUND)
target_link_libraries(motcpp PUBLIC spdlog::spdlog)
target_compile_definitions(motcpp PUBLIC MOTCPP_HAS_SPDLOG=1)
endif()
# Compiler options
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(motcpp PRIVATE
-Wall -Wextra -Wpedantic
$<$<CONFIG:Release>:-O2>
$<$<CONFIG:Debug>:-g -O0>
)
if(MOTCPP_COVERAGE)
target_compile_options(motcpp PRIVATE --coverage)
target_link_options(motcpp PRIVATE --coverage)
# Explicitly link gcov library for coverage support
target_link_libraries(motcpp PRIVATE gcov)
endif()
elseif(MSVC)
target_compile_options(motcpp PRIVATE /W4 /permissive-)
endif()
# ============================================================================
# Tools
# ============================================================================
if(MOTCPP_BUILD_TOOLS)
add_subdirectory(tools)
endif()
# ============================================================================
# Examples
# ============================================================================
if(MOTCPP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# ============================================================================
# Testing
# ============================================================================
if(MOTCPP_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
# ============================================================================
# Installation
# ============================================================================
if(MOTCPP_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# Install library
install(TARGETS motcpp
EXPORT motcppTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# Install headers
install(DIRECTORY ${MOTCPP_INCLUDE_DIR}/motcpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# Export targets
install(EXPORT motcppTargets
FILE motcppTargets.cmake
NAMESPACE motcpp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/motcpp
)
# Package config
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/motcppConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/motcppConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/motcpp
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/motcppConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/motcppConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/motcppConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/motcpp
)
endif()
# ============================================================================
# Summary
# ============================================================================
message(STATUS "")
message(STATUS "Configuration Summary:")
message(STATUS " Build tests: ${MOTCPP_BUILD_TESTS}")
message(STATUS " Build benchmarks: ${MOTCPP_BUILD_BENCHMARKS}")
message(STATUS " Build examples: ${MOTCPP_BUILD_EXAMPLES}")
message(STATUS " Build tools: ${MOTCPP_BUILD_TOOLS}")
message(STATUS " ONNX Runtime: ${MOTCPP_ENABLE_ONNX}")
message(STATUS " OpenCV: ${OpenCV_VERSION}")
message(STATUS " Eigen3: ${Eigen3_VERSION}")
message(STATUS "")