forked from sowson/darknet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·495 lines (452 loc) · 15.1 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
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)
option(DARKNET_ARM "Enable ARM support" OFF)
option(DARKNET_BENCHMARK "Some Benchmark Stats" OFF)
option(DARKNET_LOSS_ONLY "Loss Only Stats" OFF)
option(DARKNET_TESTING "Build the unit tests" OFF)
option(DARKNET_DEBUG "Enable debug mode" ON)
option(DARKNET_STATIC "Build static library" ON)
option(DARKNET_SHARED "Build shared library" ON)
option(DARKNET_NO_BINARY "Do not build binary" OFF)
if (WIN32)
cmake_policy(SET CMP0074 OLD)
set(PROJECTNAME_ARCHITECTURE x64)
set(CMAKE_SYSTEM_PROCESSOR x64)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 99)
include(cmake/cable/bootstrap.cmake)
include(CableBuildInfo)
include(CableBuildType)
include(CableToolchains)
include(defaults/HunterCacheServers)
include(HunterGate)
cable_configure_toolchain(DEFAULT cxx14)
HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.23.317.tar.gz"
SHA1 "fbdd94b1966d351384e27b02c8d134915b1131d6"
)
cable_set_build_type(DEFAULT Release CONFIGURATION_TYPES Release RelWithDebInfo)
project(darknet LANGUAGES C CXX)
set(PROJECT_VERSION 1.0.0)
include(GNUInstallDirs)
if (${PROJECT_SOURCE_DIR} MATCHES "")
set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()
#set(HUNTER_BUILD_SHARED_LIBS YES)
set(HUNTER_ROOT "${CMAKE_SOURCE_DIR}/3rdparty")
set(CMAKE_INSTALL_LIBDIR "${PROJECT_SOURCE_DIR}/3rdparty")
set(CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/3rdparty")
set(HUNTER_ROOT "${PROJECT_SOURCE_DIR}/3rdparty" CACHE PATH "Path to Hunter root directory.")
set(HUNTER_CONFIGURATION_TYPES Release CACHE STRING "Build type of Hunter packages")
set(HUNTER_JOBS_NUMBER 6 CACHE STRING "Number of parallel builds used by Hunter")
hunter_add_package(Boost COMPONENTS system filesystem thread)
find_package(Boost CONFIG REQUIRED COMPONENTS system filesystem thread)
add_library(Boost INTERFACE IMPORTED)
else()
project(darknet LANGUAGES C CXX)
set(PROJECT_VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_C_STANDARD 99)
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
include(GNUInstallDirs)
endif()
if (WIN32)
set (CMAKE_SYSTEM_NAME "Windows")
endif()
include_directories("include" "src")
set (DARKNET_DEFINITIONS "")
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set (DARKNET_BINARY darknet)
set (DARKNET_LIBRARY libdarknet)
set (DARKNET_LIBRARY_STATIC libdarknet_s)
else()
set (DARKNET_BINARY darknet)
set (DARKNET_LIBRARY darknet_l)
set (DARKNET_LIBRARY_STATIC darknet_s)
endif()
message(STATUS ${CMAKE_SYSTEM_NAME})
if (DARKNET_DEBUG OR DARKNET_TESTING)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
list (APPEND DARKNET_DEFINITIONS "WIN32")
else ()
list (APPEND DARKNET_CFLAGS "-g")
endif()
endif()
if (DARKNET_OPENMP)
list (APPEND DARKNET_CFLAGS "-openmp")
endif()
if (WIN32)
add_library(POSIX INTERFACE IMPORTED)
set_property(TARGET POSIX PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/3rdparty/unistd/unistd")
set_property(TARGET POSIX PROPERTY INTERFACE_LINK_DIRECTORIES "${PROJECT_SOURCE_DIR}/3rdparty/unistd/unistd")
set_property(TARGET POSIX PROPERTY INTERFACE_LINK_LIBRARIES "${PROJECT_SOURCE_DIR}/3rdparty/unistd/unistd/lib/libunistd.lib")
add_library(pthread INTERFACE IMPORTED)
set_property(TARGET pthread PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/3rdparty/pthreads")
set_property(TARGET pthread PROPERTY INTERFACE_LINK_DIRECTORIES "${PROJECT_SOURCE_DIR}/3rdparty/pthreads")
set_property(TARGET pthread PROPERTY INTERFACE_LINK_LIBRARIES "pthreads.lib")
add_library(stb INTERFACE IMPORTED)
set_property(TARGET stb PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/3rdparty/stb")
add_library(clblas INTERFACE IMPORTED)
set_property(TARGET clblas PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${PROJECT_SOURCE_DIR}/3rdparty/clBLAS")
set_property(TARGET clblas PROPERTY INTERFACE_LINK_DIRECTORIES "${PROJECT_SOURCE_DIR}/3rdparty/clBLAS")
set_property(TARGET clblas PROPERTY INTERFACE_LINK_LIBRARIES "clBLAS.lib")
else()
list (APPEND DARKNET_CFLAGS "-O3")
list (APPEND DARKNET_CFLAGS "-Wfatal-errors")
list (APPEND DARKNET_CFLAGS "-Wno-unused-variable")
list (APPEND DARKNET_CFLAGS "-Wno-unused-result")
list (APPEND DARKNET_CFLAGS "-Wno-unknown-pragmas")
list (APPEND DARKNET_CFLAGS "-Wno-deprecated-declarations")
endif()
if (DARKNET_GPU)
# Find OpenCL
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
hunter_add_package(OpenCL)
find_package(OpenCL CONFIG REQUIRED)
endif()
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 CL_TARGET_OPENCL_VERSION=120)
# Find OpenCV
if (DARKNET_OPENCV)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
hunter_add_package(OpenCV)
find_package(OpenCV CONFIG REQUIRED)
endif()
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()
# Raspberry PI
if (DARKNET_ARM)
list (APPEND DARKNET_DEFINITIONS ARM)
else()
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
#hunter_add_package(GTest)
#find_package(GTest CONFIG REQUIRED)
#hunter_add_package(clBLAS)
#find_package(clBLAS CONFIG REQUIRED)
else()
find_package(clBLAS REQUIRED PATHS ${clBLAS_DIR})
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()
endif()
# GPU Training
if (DARKNET_GPU)
list (APPEND DARKNET_DEFINITIONS GPU)
endif()
# OpenCV Training
if (DARKNET_OPENCV)
list (APPEND DARKNET_DEFINITIONS OPENCV)
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()
# Loss Stats
if (DARKNET_LOSS_ONLY)
list (APPEND DARKNET_DEFINITIONS LOSS_ONLY)
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"
"examples/cgan.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"
"src/system.c"
"examples/tag.c"
"src/tree.c"
"src/utils.c"
"examples/voxel.c"
"examples/writing.c"
"examples/yolo.c"
"src/yolo_layer.c"
"src/yolo4_layer.c"
"src/upsample_layer.c"
"src/logistic_layer.c"
"src/l2norm_layer.c"
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set_source_files_properties(${DARKNET_SOURCES} PROPERTIES LANGUAGE "CXX")
endif()
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/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/system.h"
"src/tree.h"
"src/utils.h"
"src/opencl.h"
"src/yolo_layer.h"
"src/yolo4_layer.h"
"src/upsample_layer.h"
"src/logistic_layer.h"
"src/l2norm_layer.h"
)
set (DARKNET_MAIN_SOURCE
"examples/darknet.c"
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set_source_files_properties(${DARKNET_MAIN_SOURCE} PROPERTIES LANGUAGE "CXX")
endif()
set (DARKNET_SOURCES_CXX
"src/image_opencv.cpp"
)
if (DARKNET_CPU)
set (DARKNET_CPU_SOURCES
"src/cpu.c"
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set_source_files_properties(${DARKNET_CPU} PROPERTIES LANGUAGE "CXX")
endif()
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_1.cl"
#"src/blas_kernels_2.cl"
#"src/blas_kernels_3.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"
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set_source_files_properties(${DARKNET_GPU_SOURCES} PROPERTIES LANGUAGE "CXX")
endif()
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)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR "Linux")
set_target_properties(${target} PROPERTIES OUTPUT_NAME "darknet")
endif()
target_compile_definitions(${target} PUBLIC ${DARKNET_DEFINITIONS})
target_compile_options(${target} PRIVATE ${DARKNET_CFLAGS})
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_link_options(${target} PRIVATE ${DARKNET_LINK_CFLAGS})#debug
target_link_libraries(${target} POSIX)
target_link_libraries(${target} pthread)
target_link_libraries(${target} stb)
endif()
if (DARKNET_ARM)
if (DARKNET_GPU)
target_link_libraries(${target} opencl)
endif()
elseif (DARKNET_GPU)
target_link_libraries(${target} opencl clblas)
endif()
if (DARKNET_OPENCV)
target_link_libraries(${target} opencv)
endif()
if (DARKNET_OPENMP)
find_package(OpenMP)
#!#target_link_libraries(${target} OpenMP)
endif()
# if (DARKNET_TESTING)
# target_link_libraries(${target} catch)
# endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR "Linux")
target_link_libraries(${target} "m" "pthread")
endif()
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})
if (DARKNET_OPENMP)
find_package(OpenMP)
#!#target_link_libraries(${target} OpenMP)
endif()
endfunction()
if (DARKNET_SHARED)
add_library(${DARKNET_LIBRARY} SHARED ${DARKNET_SOURCES} ${DARKNET_CPU_SOURCES}
${DARKNET_GPU_SOURCES} ${DARKNET_WINDOWS_SOURCES} ${DARKNET_SOURCES_CXX} ${DARKNET_PUBLIC_HEADERS})
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set_target_properties(${DARKNET_LIBRARY} PROPERTIES OUTPUT_NAME "darknet_d")
endif()
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} ${DARKNET_SOURCES_CXX})
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set_target_properties(${DARKNET_LIBRARY_STATIC} PROPERTIES OUTPUT_NAME "darknet_s")
endif()
ConfigureBinary(${DARKNET_LIBRARY_STATIC})
ConfigureLibrary(${DARKNET_LIBRARY_STATIC})
endif()
if (NOT DARKNET_NO_BINARY)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(CMAKE_EXE_LINKER_FLAGS "-static")
endif()
add_executable(${DARKNET_BINARY} ${DARKNET_SOURCES} ${DARKNET_CPU_SOURCES}
${DARKNET_GPU_SOURCES} ${DARKNET_WINDOWS_SOURCES} ${DARKNET_SOURCES_CXX}
${DARKNET_MAIN_SOURCE} ${DARKNET_PUBLIC_HEADERS})
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()