forked from sowson/darknet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·333 lines (300 loc) · 8.65 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
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
332
333
cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR)
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
project(darknet LANGUAGES C CXX)
option(DARKNET_CPU "Enable cpu support" OFF)
option(DARKNET_OPENCV "Enable OpenCV support" ON)
option(DARKNET_OPENMP "Enable OpenMP support" OFF)
option(DARKNET_GPU "Enable OpenCL support" ON)
option(DARKNET_GPU_FAST "Enable OpenCL fast kernels support" ON)
option(DARKNET_GPU_MULTI "Enable OpenCL Multi-GPU support" OFF) # it is still experimental
option(DARKNET_RPI "Enable Raspberry PI support" OFF)
option(DARKNET_BENCHMARK "Some Benchmark Stats" OFF)
option(DARKNET_TESTING "Build the unit tests" OFF)
option(DARKNET_DEBUG "Enable debug mode" OFF)
option(DARKNET_STATIC "Build static library" ON)
option(DARKNET_SHARED "Build shared library" ON)
option(DARKNET_NO_BINARY "Do not build binary" OFF)
include(GNUInstallDirs)
include_directories("include" "src")
set (DARKNET_DEFINITIONS "")
set (DARKNET_BINARY bindarknet)
set (DARKNET_LIBRARY libdarknet)
set (DARKNET_LIBRARY_STATIC libdarknet_s)
if (DARKNET_DEBUG OR DARKNET_TESTING)
list (APPEND DARKNET_CFLAGS "-g")
else()
if (DARKNET_OPENMP)
list (APPEND DARKNET_CFLAGS "-fopenmp")
endif()
list (APPEND DARKNET_CFLAGS "-Wfatal-errors")
list (APPEND DARKNET_CFLAGS "-Wno-unused-variable")
list (APPEND DARKNET_CFLAGS "-O2")
endif()
# Find OpenCV
if (DARKNET_OPENCV)
find_package(OpenCV REQUIRED)
add_library(opencv INTERFACE IMPORTED)
set_property(TARGET opencv PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${OpenCV_INCLUDE_DIRS})
set_property(TARGET opencv PROPERTY
INTERFACE_LINK_LIBRARIES ${OpenCV_LIBRARIES})
list (APPEND DARKNET_DEFINITIONS OPENCV)
endif()
# Find OpenCL
if (DARKNET_GPU)
find_package(OpenCL REQUIRED)
add_library(opencl INTERFACE IMPORTED)
set_property(TARGET opencl PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${OpenCL_INCLUDE_DIRS})
set_property(TARGET opencl PROPERTY
INTERFACE_LINK_LIBRARIES ${OpenCL_LIBRARY})
list (APPEND DARKNET_DEFINITIONS GPU)
# Raspberry PI
if (DARKNET_RPI)
list (APPEND DARKNET_DEFINITIONS RPI)
else()
find_package(clBLAS REQUIRED)
add_library(clblas INTERFACE IMPORTED)
set_property(TARGET clblas PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${CLBLAS_INCLUDE_DIRS})
set_property(TARGET clblas PROPERTY
INTERFACE_LINK_LIBRARIES ${CLBLAS_LIBRARIES})
endif()
endif()
# Fast Training
if (DARKNET_GPU_FAST)
list (APPEND DARKNET_DEFINITIONS GPU_FAST)
endif()
# Multi-GPU Training
if (DARKNET_GPU_MULTI)
list (APPEND DARKNET_DEFINITIONS GPU_MULTI)
endif()
# Benchmark Stats
if (DARKNET_BENCHMARK)
list (APPEND DARKNET_DEFINITIONS BENCHMARK)
endif()
# Find Catch
if (DARKNET_UNIT)
set (DARKNET_CPU OFF)
find_package(Catch REQUIRED)
add_library(catch INTERFACE IMPORTED)
set_property(TARGET catch PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${Catch_INCLUDE_DIRS})
endif()
set (DARKNET_SOURCES
"src/activation_layer.c"
"src/activations.c"
"examples/art.c"
"examples/attention.c"
"src/avgpool_layer.c"
"src/batchnorm_layer.c"
"src/blas.c"
"src/box.c"
"examples/captcha.c"
"examples/cifar.c"
"examples/classifier.c"
"examples/coco.c"
"src/col2im.c"
"src/compare.c"
"src/connected_layer.c"
"src/convolutional_layer.c"
"src/cost_layer.c"
"src/crnn_layer.c"
"src/crop_layer.c"
"src/data.c"
"src/deconvolutional_layer.c"
"src/demo.c"
"src/detection_layer.c"
"examples/detector.c"
"examples/dice.c"
"src/dropout_layer.c"
"src/gemm.c"
"examples/go.c"
"src/gru_layer.c"
"src/im2col.c"
"src/image.c"
"src/iseg_layer.c"
"examples/instance-segmenter.c"
"src/layer.c"
"src/list.c"
"src/local_layer.c"
"src/lstm_layer.c"
"examples/lsd.c"
"src/matrix.c"
"src/maxpool_layer.c"
"src/network.c"
"examples/nightmare.c"
"src/normalization_layer.c"
"src/option_list.c"
"src/parser.c"
"src/region_layer.c"
"examples/regressor.c"
"src/reorg_layer.c"
"examples/rnn.c"
"src/rnn_layer.c"
"examples/rnn_vid.c"
"src/route_layer.c"
"src/shortcut_layer.c"
"src/softmax_layer.c"
"examples/segmenter.c"
"examples/super.c"
"examples/swag.c"
"examples/tag.c"
"src/tree.c"
"src/utils.c"
"examples/voxel.c"
"examples/writing.c"
"examples/yolo.c"
"src/yolo_layer.c"
"src/upsample_layer.c"
"src/logistic_layer.c"
"src/l2norm_layer.c"
)
set (DARKNET_PUBLIC_HEADERS
"include/darknet.h"
"src/activation_layer.h"
"src/activations.h"
"src/avgpool_layer.h"
"src/batchnorm_layer.h"
"src/blas.h"
"src/box.h"
"src/bugfixes.h"
"src/classifier.h"
"src/col2im.h"
"src/connected_layer.h"
"src/convolutional_layer.h"
"src/cost_layer.h"
"src/crnn_layer.h"
"src/crop_layer.h"
"src/opencl.h"
"src/data.h"
"src/deconvolutional_layer.h"
"src/demo.h"
"src/detection_layer.h"
"src/dropout_layer.h"
"src/gemm.h"
"src/gru_layer.h"
"src/im2col.h"
"src/image.h"
"src/iseg_layer.h"
"src/layer.h"
"src/list.h"
"src/local_layer.h"
"src/lstm_layer.h"
"src/matrix.h"
"src/maxpool_layer.h"
"src/network.h"
"src/normalization_layer.h"
"src/option_list.h"
"src/parser.h"
"src/region_layer.h"
"src/reorg_layer.h"
"src/rnn_layer.h"
"src/route_layer.h"
"src/shortcut_layer.h"
"src/softmax_layer.h"
"src/stb_image.h"
"src/stb_image_write.h"
"src/tree.h"
"src/unit.h"
"src/utils.h"
"src/opencl.h"
"src/yolo_layer.h"
"src/upsample_layer.h"
"src/logistic_layer.h"
"src/l2norm_layer.h"
)
set (DARKNET_MAIN_SOURCE
"examples/darknet.c"
)
if (DARKNET_CPU)
set (DARKNET_CPU_SOURCES
"src/cpu.c"
)
endif()
if (DARKNET_GPU)
set (DARKNET_GPU_SOURCES
"src/activation_kernels.c"
"src/activation_kernels.cl"
"src/avgpool_layer_kernels.c"
"src/avgpool_layer_kernels.cl"
"src/blas_kernels.c"
"src/blas_kernels.cl"
"src/col2im_kernels.c"
"src/col2im_kernels.cl"
"src/convolutional_kernels.c"
"src/convolutional_kernels.cl"
"src/crop_layer_kernels.c"
"src/crop_layer_kernels.cl"
"src/deconvolutional_kernels.c"
"src/dropout_layer_kernels.c"
"src/dropout_layer_kernels.cl"
"src/im2col_kernels.c"
"src/im2col_kernels.cl"
"src/maxpool_layer_kernels.c"
"src/maxpool_layer_kernels.cl"
"src/opencl.c"
)
endif()
if (DARKNET_UNIT)
set (DARKNET_UNIT_SOURCES
"src/unit.c"
"src/unit.h"
"src/blas_unit.c"
"src/col2im_unit.c"
"src/convolutional_unit.c"
"src/gemm_unit.c"
"src/maxpool_unit.c"
"src/network_unit.c"
"src/region_unit.c"
)
endif()
function (ConfigureBinary target)
set_target_properties(${target} PROPERTIES OUTPUT_NAME "darknet")
target_compile_definitions(${target} PUBLIC ${DARKNET_DEFINITIONS})
target_compile_options(${target} PRIVATE ${DARKNET_CFLAGS})
if (DARKNET_GPU)
target_link_libraries(${target} opencl clblas)
endif()
if (DARKNET_OPENCV)
target_link_libraries(${target} opencv)
endif()
# if (DARKNET_TESTING)
# target_link_libraries(${target} catch)
# endif()
target_link_libraries(${target} "m" "pthread")
endfunction()
function (ConfigureLibrary target)
target_include_directories(${target} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>
)
install(TARGETS ${target} EXPORT ${CMAKE_PROJECT_NAME}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endfunction()
if (DARKNET_SHARED)
add_library(${DARKNET_LIBRARY} SHARED ${DARKNET_SOURCES} ${DARKNET_CPU_SOURCES}
${DARKNET_GPU_SOURCES} ${DARKNET_WINDOWS_SOURCES})
ConfigureBinary(${DARKNET_LIBRARY})
ConfigureLibrary(${DARKNET_LIBRARY})
endif()
if (DARKNET_STATIC)
add_library(${DARKNET_LIBRARY_STATIC} STATIC ${DARKNET_SOURCES} ${DARKNET_CPU_SOURCES}
${DARKNET_GPU_SOURCES} ${DARKNET_WINDOWS_SOURCES})
ConfigureBinary(${DARKNET_LIBRARY_STATIC})
ConfigureLibrary(${DARKNET_LIBRARY_STATIC})
endif()
if (NOT DARKNET_NO_BINARY)
add_executable(${DARKNET_BINARY} ${DARKNET_SOURCES} ${DARKNET_CPU_SOURCES}
${DARKNET_GPU_SOURCES} ${DARKNET_WINDOWS_SOURCES}
${DARKNET_MAIN_SOURCE})
ConfigureBinary(${DARKNET_BINARY})
endif()
install(FILES ${DARKNET_PUBLIC_HEADERS} ${DARKNET_WINDOWS_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME})
install(EXPORT ${CMAKE_PROJECT_NAME} DESTINATION share/${CMAKE_PROJECT_NAME}/cmake)
if (DARKNET_SHARED)
export(TARGETS ${DARKNET_LIBRARY} FILE darknetConfig.cmake)
endif()