-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
617 lines (572 loc) · 24.6 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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
cmake_minimum_required(VERSION 3.9.2)
PROJECT(eddl LANGUAGES CXX)
# SET C++ COMPILER STANDARD
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
# USER OPTIONS *******************************
option(BUILD_PYTHON "Compile python binding" OFF)
option(BUILD_TESTS "Compile tests" OFF)
option(BUILD_EXAMPLES "Compile examples" ON)
SET(BUILD_TARGET "CPU" CACHE STRING "Compile library for {CPU, GPU, FPGA}")
set_property(CACHE BUILD_TARGET PROPERTY STRINGS CPU GPU FPGA)
# PROPERTIES *******************************
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "")
# SET BUILD TYPE (RELEASE/DEBUG)
if(NOT CMAKE_BUILD_TYPE)
#set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Release)
endif()
# SET COMPILER FLAGS
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
#set(CMAKE_CXX_FLAGS "-march=native ${CMAKE_CXX_FLAGS}") // This is a bad idea
set(CMAKE_CXX_FLAGS_DEBUG "-g ${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 ${CMAKE_CXX_FLAGS_RELEASE}")
endif()
# CUDA FLAGS
# Is this the best approach?
#set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr -lcudart -lcublas -lcurand")
# Device specific setup
if(BUILD_TARGET STREQUAL "CPU")
message("Compiling for CPU...")
elseif(BUILD_TARGET STREQUAL "GPU")
message("Compiling for GPU...")
set(EDDL_WITH_CUDA ON CACHE BOOL "Enable CUDA support if checked")
elseif(BUILD_TARGET STREQUAL "FPGA")
message("Compiling for FPGA...")
message(FATAL_ERROR "FPGA not implemented, CMake will exit." )
endif()
# SET STATIC/DYNAMIC RUNTIME
set(EDDL_SHARED OFF CACHE BOOL "Whether to build a static or dynamic library")
# Set default install directories
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if (WIN32)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "Installation Directory" FORCE)
else()
set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Installation Directory" FORCE)
endif()
endif()
# SHOW OPTIONS
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE} )
message(STATUS "Build target: " ${BUILD_TARGET} )
message(STATUS "Build tests: " ${BUILD_TESTS} )
message(STATUS "Build examples: " ${BUILD_EXAMPLES} )
message(STATUS "Build python: " ${BUILD_PYTHON} )
message(STATUS "CUDA Enabled: " ${EDDL_WITH_CUDA} )
message(STATUS "C++ flags: " ${CMAKE_CXX_FLAGS} )
message(STATUS "CUDA flags: " ${CMAKE_CUDA_FLAGS} )
# Add CUDA (if possible)
if(EDDL_WITH_CUDA)
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr -D_MWAITXINTRIN_H_INCLUDED -D_FORCE_INLINES -D__STRICT_ANSI__")
set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
endif()
else()
message(WARNING "No CUDA support")
endif()
endif()
# Microsoft Visual C++ - set static/dynamic runtime
if(MSVC)
if(EDDL_SHARED)
message(STATUS "Setting dinamic runtime for MSVC")
foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}")
endforeach(flag_var)
if (EDDL_WITH_CUDA AND CMAKE_CUDA_COMPILER)
foreach(flag_var CMAKE_CUDA_FLAGS_DEBUG CMAKE_CUDA_FLAGS_RELEASE CMAKE_CUDA_FLAGS_MINSIZEREL CMAKE_CUDA_FLAGS_RELWITHDEBINFO)
string(REGEX REPLACE "-MT" "-MD" ${flag_var} "${${flag_var}}")
endforeach(flag_var)
endif()
else(EDDL_SHARED)
message(STATUS "Setting static runtime for MSVC")
foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endforeach(flag_var)
if (EDDL_WITH_CUDA AND CMAKE_CUDA_COMPILER)
foreach(flag_var CMAKE_CUDA_FLAGS_DEBUG CMAKE_CUDA_FLAGS_RELEASE CMAKE_CUDA_FLAGS_MINSIZEREL CMAKE_CUDA_FLAGS_RELWITHDEBINFO)
string(REGEX REPLACE "-MD" "-MT" ${flag_var} "${${flag_var}}")
endforeach(flag_var)
endif()
endif(EDDL_SHARED)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
# [MACRO] Download submodules
macro(eddl_update_third_party SUBMODULE)
if(GIT_FOUND AND IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git")
# Update submodule as needed
message(STATUS "${SUBMODULE} update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive third_party/${SUBMODULE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout ${SUBMODULE} submodule")
endif()
endif()
endmacro()
# ERROR! ==============================================>
#
# I need this to work in CLion in order to debug
#error: could not lock config file /Users/salvacarrion/Documents/Programming/C++/eddl/.git/modules/third_party/eigen/config: File exists
#fatal: could not set 'core.worktree' to '../../../../third_party/eigen'
#CMake Error at CMakeLists.txt:117 (message):
#git submodule update --init failed with 1, please checkout eigen submodule
#Call Stack (most recent call first):
#CMakeLists.txt:124 (eddl_update_third_party)
#
## UPDATE THIRD_PARTY MANDATORY MODULES
#find_package(Git QUIET)
#eddl_update_third_party(eigen)
#include_directories(third_party/eigen)
#<==============================================
# Add the given directories to those the compiler uses to search for include files
include_directories(src)
include_directories(src/apis)
include_directories(src/hardware/cpu)
include_directories(src/hardware/cpu/nn)
include_directories(src/hardware/gpu)
include_directories(src/hardware/gpu/nn)
include_directories(src/initializers)
include_directories(src/layers)
include_directories(src/layers/conv)
include_directories(src/layers/core)
include_directories(src/layers/merge)
include_directories(src/layers/noise)
include_directories(src/layers/operators)
include_directories(src/layers/pool)
include_directories(src/layers/recurrent)
include_directories(src/losses)
include_directories(src/metrics)
include_directories(src/optimizers)
include_directories(src/regularizers)
include_directories(src/stb)
include_directories(src/tensor)
include_directories(src/descriptors)
# Temp
include_directories(tests)
include_directories(tests/dev)
# SET SOURCES *******************************
SET(SOURCE_DIR "src")
SET(CPP_SOURCES
src/apis/eddl.cpp
src/apis/eddl.h
src/apis/eddlT.cpp
src/apis/eddlT.h
src/hardware/cpu/cpu_hw.h
src/hardware/cpu/cpu_comparison.cpp
src/hardware/cpu/cpu_core.cpp
src/hardware/cpu/cpu_create.cpp
src/hardware/cpu/cpu_da.cpp
src/hardware/cpu/cpu_generator.cpp
src/hardware/cpu/cpu_math.cpp
src/hardware/cpu/cpu_reduction.cpp
src/hardware/cpu/nn/cpu_activations.cpp
src/hardware/cpu/nn/cpu_conv.cpp
src/hardware/cpu/nn/cpu_losses.cpp
src/hardware/cpu/nn/cpu_metrics.cpp
src/hardware/cpu/nn/cpu_pool.cpp
src/hardware/cpu/nn/cpu_tensor_nn.cpp
src/initializers/initializer.cpp
src/initializers/initializer.h
src/initializers/initializer_constant.cpp
src/initializers/initializer_glorot_normal.cpp
src/initializers/initializer_glorot_uniform.cpp
src/initializers/initializer_indentity.cpp
src/initializers/initializer_orthogonal.cpp
src/initializers/initializer_random_normal.cpp
src/initializers/initializer_random_uniform.cpp
src/layers/constraints/constraint.cpp
src/layers/constraints/constraint.h
src/layers/constraints/constraint_max_norm.cpp
src/layers/constraints/constraint_min_max_norm.cpp
src/layers/constraints/constraint_non_neg.cpp
src/layers/constraints/constraint_unit_norm.cpp
src/layers/conv/layer_conv.cpp
src/layers/conv/layer_conv.h
src/layers/conv/layer_transposed_conv.cpp
src/layers/conv/layer_upsampling.cpp
src/layers/core/layer_activation.cpp
src/layers/core/layer_core.h
src/layers/core/layer_dense.cpp
src/layers/core/layer_drop.cpp
src/layers/core/layer_embedding.cpp
src/layers/core/layer_input.cpp
src/layers/core/layer_reshape.cpp
src/layers/core/layer_tensor.cpp
src/layers/core/layer_transpose.cpp
src/layers/da/layer_da.h
src/layers/da/layer_crop.cpp
src/layers/da/layer_crop_scale.cpp
src/layers/da/layer_crop_random.cpp
src/layers/da/layer_crop_scale_random.cpp
src/layers/da/layer_cutout.cpp
src/layers/da/layer_cutout_random.cpp
src/layers/da/layer_flip.cpp
src/layers/da/layer_flip_random.cpp
src/layers/da/layer_rotate.cpp
src/layers/da/layer_rotate_random.cpp
src/layers/da/layer_scale.cpp
src/layers/da/layer_scale_random.cpp
src/layers/da/layer_shift.cpp
src/layers/da/layer_shift_random.cpp
src/layers/normalization/layer_norm.cpp
src/layers/normalization/layer_normmax.cpp
src/layers/normalization/layer_normminmax.cpp
src/layers/normalization/layer_batchnorm.cpp
src/layers/generators/layer_generator.cpp
src/layers/generators/layer_generators.h
src/layers/generators/layer_gauss.cpp
src/layers/generators/layer_uniform.cpp
src/layers/merge/layer_add.cpp
src/layers/merge/layer_average.cpp
src/layers/merge/layer_concat.cpp
src/layers/merge/layer_matmul.cpp
src/layers/merge/layer_maximum.cpp
src/layers/merge/layer_merge.h
src/layers/merge/layer_minimum.cpp
src/layers/merge/layer_subtract.cpp
src/layers/noise/layer_gaussian.cpp
src/layers/noise/layer_noise.h
src/layers/operators/layer_abs.cpp
src/layers/operators/layer_diff.cpp
src/layers/operators/layer_div.cpp
src/layers/operators/layer_exp.cpp
src/layers/operators/layer_log.cpp
src/layers/operators/layer_log10.cpp
src/layers/operators/layer_log2.cpp
src/layers/operators/layer_mult.cpp
src/layers/operators/layer_operator.cpp
src/layers/operators/layer_operators.h
src/layers/operators/layer_pow.cpp
src/layers/operators/layer_sqrt.cpp
src/layers/operators/layer_sum.cpp
src/layers/pool/layer_avgpool.cpp
src/layers/pool/layer_globalavgpool.cpp
src/layers/pool/layer_globalmaxpool.cpp
src/layers/pool/layer_maxpool.cpp
src/layers/pool/layer_pool.cpp
src/layers/pool/layer_pool.h
src/layers/recurrent/layer_lstm.cpp
src/layers/recurrent/layer_recurrent.h
src/layers/recurrent/layer_rnn.cpp
src/layers/reductions/layer_mean.cpp
src/layers/reductions/layer_reduction.cpp
src/layers/reductions/layer_reductions.h
src/layers/reductions/layer_var.cpp
src/layers/reductions/layer_sum.cpp
src/layers/reductions/layer_max.cpp
src/layers/reductions/layer_min.cpp
src/layers/layer.cpp
src/layers/layer.h
src/losses/loss.cpp
src/losses/loss.h
src/losses/loss_cross_entropy.cpp
src/losses/loss_mean_squared_error.cpp
src/losses/loss_soft_cross_entropy.cpp
src/losses/loss_min.cpp
src/metrics/metric.cpp
src/metrics/metric.h
src/metrics/metric_categorical_acc.cpp
src/metrics/metric_mean_squared_error.cpp
src/metrics/metric_mean_absolute_error.cpp
src/metrics/metric_mean_relative_error.cpp
src/metrics/metric_sum.cpp
src/optimizers/optim.cpp
src/optimizers/optim.h
src/optimizers/optim_adadelta.cpp
src/optimizers/optim_adagrad.cpp
src/optimizers/optim_adam.cpp
src/optimizers/optim_adamax.cpp
src/optimizers/optim_nadam.cpp
src/optimizers/optim_rmsprop.cpp
src/optimizers/optim_sgd.cpp
src/descriptors/descriptors.h
src/descriptors/descriptor_conv.cpp
src/descriptors/descriptor_pool.cpp
src/descriptors/descriptor_reduce.cpp
src/regularizers/regularizer.h
src/regularizers/regularizer.cpp
src/regularizers/regularizer_l1.cpp
src/regularizers/regularizer_l1_l2.cpp
src/regularizers/regularizer_l2.cpp
src/stb/stb.h
src/stb/stb_image.h
src/stb/stb_image_write.h
src/tensor/tensor.h
src/tensor/tensor.cpp
src/tensor/tensor_comparison.cpp
src/tensor/tensor_core.cpp
src/tensor/tensor_create.cpp
src/tensor/tensor_da.cpp
src/tensor/tensor_generator.cpp
src/tensor/tensor_math.cpp
src/tensor/tensor_reduction.cpp
src/tensor/tensor_serialization.cpp
src/tensor/nn/tensor_nn.h
src/tensor/nn/tensor_activations.cpp
src/tensor/nn/tensor_conv.cpp
src/tensor/nn/tensor_losses.cpp
src/tensor/nn/tensor_metrics.cpp
src/tensor/nn/tensor_pool.cpp
src/tensor/nn/tensor_core_nn.cpp
src/net/compserv.cpp
src/net/compserv.h
src/net/netloss.cpp
src/net/netloss.h
src/net/net.cpp
src/net/net_build.cpp
src/net/net_api.cpp
src/net/net_func.cpp
src/net/net.h
src/system_info.h
src/utils.cpp
src/utils.h
src/random.cpp
src/random.h
# Temp
tests/test_tensor.cpp
tests/dev/aux_tests.cpp
tests/dev/aux_tests.h
tests/dev/aux_tests.h
)
SET(CUDA_SOURCES
src/hardware/gpu/gpu_hw.h
src/hardware/gpu/gpu_comparison.cu
src/hardware/gpu/gpu_comparison_kernels.cu
src/hardware/gpu/gpu_core.cu
src/hardware/gpu/gpu_core_kernels.cu
src/hardware/gpu/gpu_create.cu
src/hardware/gpu/gpu_create_kernels.cu
src/hardware/gpu/gpu_da.cu
src/hardware/gpu/gpu_da_kernels.cu
src/hardware/gpu/gpu_generator.cu
src/hardware/gpu/gpu_generator_kernels.cu
src/hardware/gpu/gpu_math.cu
src/hardware/gpu/gpu_math_kernels.cu
src/hardware/gpu/gpu_reduction.cu
src/hardware/gpu/gpu_reduction_kernels.cu
src/hardware/gpu/gpu_tensor.cu
src/hardware/gpu/gpu_tensor.h
src/hardware/gpu/gpu_kernels.h
src/hardware/gpu/nn/gpu_nn.h
src/hardware/gpu/nn/gpu_nn_kernels.h
src/hardware/gpu/nn/gpu_activations.cu
src/hardware/gpu/nn/gpu_activations_kernels.cu
src/hardware/gpu/nn/gpu_conv.cu
src/hardware/gpu/nn/gpu_conv_kernels.cu
src/hardware/gpu/nn/gpu_losses.cu
src/hardware/gpu/nn/gpu_losses_kernels.cu
src/hardware/gpu/nn/gpu_metrics.cu
src/hardware/gpu/nn/gpu_metrics_kernels.cu
src/hardware/gpu/nn/gpu_pool.cu
src/hardware/gpu/nn/gpu_pool_kernels.cu
src/hardware/gpu/nn/gpu_tensor_nn.cu
src/hardware/gpu/nn/gpu_tensor_nn_kernels.cu
)
SET(SOURCES ${CPP_SOURCES} ${CUDA_SOURCES})
# SET TESTS ****************************
SET(TEST_DIR "tests")
SET(TESTS
"${TEST_DIR}/test_tensor.cpp"
)
# [LIBRARY] EDDL LIBRARY *********************
if(EDDL_SHARED)
add_library(eddl SHARED "")
else(EDDL_SHARED)
add_library(eddl STATIC "")
endif(EDDL_SHARED)
target_sources(eddl PRIVATE ${CPP_SOURCES})
if(EDDL_WITH_CUDA AND CMAKE_CUDA_COMPILER)
target_sources(eddl PRIVATE ${CUDA_SOURCES})
target_include_directories(eddl PUBLIC ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
add_compile_definitions(cGPU)
endif()
target_include_directories(eddl PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include>
)
target_include_directories(eddl PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party/eigen>
$<INSTALL_INTERFACE:include>
)
#target_compile_features(eddl PUBLIC cxx_std_11)
# Target properties
set_target_properties(eddl PROPERTIES
OUTPUT_NAME_DEBUG "eddld"
OUTPUT_NAME_RELEASE "eddl"
POSITION_INDEPENDENT_CODE ON
CUDA_SEPARABLE_COMPILATION ON
CUDA_RESOLVE_DEVICE_SYMBOLS ON)
# OpenMP
find_package(OpenMP)
if (OPENMP_FOUND)
target_link_libraries(eddl PRIVATE OpenMP::OpenMP_CXX)
endif()
# CUDA
if(EDDL_WITH_CUDA AND CMAKE_CUDA_COMPILER)
target_link_libraries(eddl
PRIVATE cublas
PRIVATE cudart
PRIVATE curand
)
endif()
# pthreads setup for windows os
# The following commands should be removed when pthread linux
# specific calls will be replaced by thread c++ standard calls
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(EDDL_PTHREADS_INSTALL_PATH "$ENV{PTHREADS_ROOT}" CACHE PATH "Path to the installation of pthreads under Windows")
if(EDDL_PTHREADS_INSTALL_PATH STREQUAL "")
message(ERROR ": pthreds install path must be specified under Windows")
endif()
target_link_libraries(eddl PRIVATE debug "${EDDL_PTHREADS_INSTALL_PATH}/lib/libpthreadVC3d.lib"
PRIVATE debug "${EDDL_PTHREADS_INSTALL_PATH}/lib/libpthreadVCE3d.lib"
PRIVATE debug "${EDDL_PTHREADS_INSTALL_PATH}/lib/libpthreadVSE3d.lib")
target_link_libraries(eddl PRIVATE optimized "${EDDL_PTHREADS_INSTALL_PATH}/lib/libpthreadVC3.lib"
PRIVATE optimized "${EDDL_PTHREADS_INSTALL_PATH}/lib/libpthreadVCE3.lib"
PRIVATE optimized "${EDDL_PTHREADS_INSTALL_PATH}/lib/libpthreadVSE3.lib")
target_include_directories(eddl PUBLIC "${EDDL_PTHREADS_INSTALL_PATH}/include")
endif()
# pthreads setup for linux os
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
SET(CMAKE_THREAD_PREFER_PTHREAD TRUE)
SET(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
target_link_libraries(eddl PRIVATE Threads::Threads)
endif()
## [BINDING] Create python binding
#if(BUILD_PYTHON)
# eddl_update_third_party(pybind11)
# set(CMAKE_FOLDER 3party/pybind11)
# add_subdirectory(third_party/pybind11)
# set(CMAKE_FOLDER "")
# SET(C_LIB_NAME "_C")
# pybind11_add_module(${C_LIB_NAME} ${SOURCES} "${SOURCE_DIR}/binding.cpp")
# # can we just link the library instead of adding all the sources and linking pthreads again?
# # target_link_libraries(${C_LIB_NAME} PRIVATE eddl)
# if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
# target_link_libraries(${C_LIB_NAME} PRIVATE "${EDDL_PTHREADS_INSTALL_PATH}/lib/libpthreadVC3.lib")
# target_link_libraries(${C_LIB_NAME} PRIVATE "${EDDL_PTHREADS_INSTALL_PATH}/lib/libpthreadVCE3.lib")
# target_link_libraries(${C_LIB_NAME} PRIVATE "${EDDL_PTHREADS_INSTALL_PATH}/lib/libpthreadVSE3.lib")
# target_include_directories(${C_LIB_NAME} PUBLIC "${EDDL_PTHREADS_INSTALL_PATH}/include")
# endif()
# if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
# target_link_libraries(${C_LIB_NAME} PRIVATE Threads::Threads)
# endif()
#endif(BUILD_PYTHON)
##unset(BUILD_PYTHON CACHE)
# [TESTS] Generate a test executable
if(BUILD_TESTS)
eddl_update_third_party(googletest)
set(CMAKE_FOLDER third_party/googletest)
add_subdirectory(third_party/googletest)
SET(UNITTEST_NAME "${PROJECT_NAME}_tests")
set(CMAKE_FOLDER "")
add_executable(${UNITTEST_NAME} ${TESTS})
target_include_directories(${UNITTEST_NAME} PUBLIC ${gtest_SOURCE_DIR}/include)
target_link_libraries(${UNITTEST_NAME} eddl gtest gtest_main)
add_test(UnitTests ${UNITTEST_NAME}) # To do "make test"
enable_testing()
endif(BUILD_TESTS)
#unset(BUILD_TESTS CACHE)
# [EXAMPLES] Generate a few test executables
if(BUILD_EXAMPLES)
SET(EXAMPLES_DIR "examples")
set(CMAKE_FOLDER examples)
## MNIST EXAMPLES
add_executable(mnist_mlp "${EXAMPLES_DIR}/NN/1_MNIST/1_mnist_mlp.cpp")
add_executable(mnist_mlp_initializers "${EXAMPLES_DIR}/NN/1_MNIST/2_mnist_mlp_initializers.cpp")
add_executable(mnist_mlp_regularizers "${EXAMPLES_DIR}/NN/1_MNIST/3_mnist_mlp_regularizers.cpp")
add_executable(mnist_mlp_da "${EXAMPLES_DIR}/NN/1_MNIST/4_mnist_mlp_da.cpp")
add_executable(mnist_mlp_train_batch "${EXAMPLES_DIR}/NN/1_MNIST/5_mnist_mlp_train_batch.cpp")
add_executable(mnist_auto_encoder "${EXAMPLES_DIR}/NN/1_MNIST/6_mnist_auto_encoder.cpp")
add_executable(mnist_gan "${EXAMPLES_DIR}/NN/1_MNIST/7_mnist_gan.cpp")
add_executable(mnist_wgan "${EXAMPLES_DIR}/NN/1_MNIST/8_mnist_wgan.cpp")
## CIFAR10 EXAMPLES
add_executable(cifar_conv "${EXAMPLES_DIR}/NN/2_CIFAR10/1_cifar_conv.cpp")
add_executable(cifar_conv_da "${EXAMPLES_DIR}/NN/2_CIFAR10/2_cifar_conv_da.cpp")
add_executable(cifar_vgg16 "${EXAMPLES_DIR}/NN/2_CIFAR10/3_cifar_vgg16.cpp")
add_executable(cifar_vgg16_bn "${EXAMPLES_DIR}/NN/2_CIFAR10/4_cifar_vgg16_bn.cpp")
add_executable(cifar_resnet "${EXAMPLES_DIR}/NN/2_CIFAR10/5_cifar_resnet.cpp")
add_executable(cifar_resnet_da_bn "${EXAMPLES_DIR}/NN/2_CIFAR10/6_cifar_resnet_da_bn.cpp")
add_executable(cifar_resnet50 "${EXAMPLES_DIR}/NN/2_CIFAR10/7_cifar_resnet50_da_bn.cpp")
#### OTHER
add_executable(example_ae "${EXAMPLES_DIR}/NN/other/eddl_ae.cpp")
add_executable(example_conv "${EXAMPLES_DIR}/NN/other/eddl_conv.cpp")
add_executable(example_dae "${EXAMPLES_DIR}/NN/other/eddl_dae.cpp")
add_executable(example_dae_class "${EXAMPLES_DIR}/NN/other/eddl_dae_class.cpp")
add_executable(example_load_save "${EXAMPLES_DIR}/NN/other/eddl_load_save.cpp")
add_executable(example_mlp "${EXAMPLES_DIR}/NN/other/eddl_mlp.cpp")
add_executable(example_train_batch "${EXAMPLES_DIR}/NN/other/eddl_train_batch.cpp")
add_executable(example_tensor "${EXAMPLES_DIR}/Tensor/eddl_tensor.cpp")
## MNIST EXAMPLES
target_link_libraries(mnist_mlp eddl)
target_link_libraries(mnist_mlp_initializers eddl)
target_link_libraries(mnist_mlp_regularizers eddl)
target_link_libraries(mnist_mlp_da eddl)
target_link_libraries(mnist_mlp_train_batch eddl)
target_link_libraries(mnist_auto_encoder eddl)
target_link_libraries(mnist_gan eddl)
target_link_libraries(mnist_wgan eddl)
## CIFAR10 EXAMPLES
target_link_libraries(cifar_conv eddl)
target_link_libraries(cifar_conv_da eddl)
target_link_libraries(cifar_vgg16 eddl)
target_link_libraries(cifar_vgg16_bn eddl)
target_link_libraries(cifar_resnet eddl)
target_link_libraries(cifar_resnet_da_bn eddl)
target_link_libraries(cifar_resnet50 eddl)
#### OTHER
target_link_libraries(example_ae eddl)
target_link_libraries(example_conv eddl)
target_link_libraries(example_dae eddl)
target_link_libraries(example_dae_class eddl)
target_link_libraries(example_load_save eddl)
target_link_libraries(example_mlp eddl)
target_link_libraries(example_train_batch eddl)
target_link_libraries(example_tensor eddl)
# Temp
add_executable(test_main "tests/test_main.cpp")
target_link_libraries(test_main eddl)
set(CMAKE_FOLDER "")
endif(BUILD_EXAMPLES)
#unset(BUILD_EXAMPLES CACHE)
# [INSTALL] Install the EDDL library
if (WIN32)
SET(EDDL_CONFIG_INSTALL_PATH ${CMAKE_INSTALL_PREFIX})
else()
SET(EDDL_CONFIG_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/lib/cmake/eddl)
endif()
install(TARGETS eddl
EXPORT eddlTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install(EXPORT eddlTargets DESTINATION ${EDDL_CONFIG_INSTALL_PATH})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/
DESTINATION include/eddl
FILES_MATCHING PATTERN "*.h")
# [INSTALL] Install Eigen files
include("${CMAKE_CURRENT_SOURCE_DIR}/third_party/eigen/cmake/RegexUtils.cmake")
test_escape_string_as_regex()
escape_string_as_regex(ESCAPED_EIGEN_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/eigen/Eigen")
file(GLOB Eigen_directory_files "${ESCAPED_EIGEN_SOURCE_DIR}/*")
#message(STATUS ${Eigen_directory_files})
foreach(f ${Eigen_directory_files})
if(NOT f MATCHES "\\.txt" AND NOT f MATCHES "${ESCAPED_EIGEN_SOURCE_DIR}/[.].+" AND NOT f MATCHES "${ESCAPED_EIGEN_SOURCE_DIR}/src")
list(APPEND Eigen_directory_files_to_install ${f})
endif()
endforeach(f ${Eigen_directory_files})
install(FILES
${Eigen_directory_files_to_install}
DESTINATION "include/Eigen"
)
install(DIRECTORY ${ESCAPED_EIGEN_SOURCE_DIR}/src DESTINATION "include/Eigen" COMPONENT Devel FILES_MATCHING PATTERN "*.h")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/eddlConfig.cmake.in ${CMAKE_BINARY_DIR}/cmake/eddlConfig.cmake @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/cmake/eddlConfig.cmake
DESTINATION ${EDDL_CONFIG_INSTALL_PATH})
message(STATUS "Install path: ${CMAKE_INSTALL_PREFIX}")