summaryrefslogtreecommitdiff
path: root/python/openvino/runtime/CMakeLists.txt
blob: cdc4578539c330b13f0e0e1acf61aa28e8d0953e (plain)
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
###############################################################################
# Build file defining build targets for the PCIe and HPS example design packages
#
# The runtime can be built in two ways which can be selected with the -disable_jit flag
# using the build_runtime.sh script. Adding the flag will build the AOT (ahead of time)
# runtime ONLY (hence disabling jit/just in time). This build flow should be used if you
# wish to build independently of the DLAC and/or want to port the runtime to your own system.
#
# Building without the -disable_jit flag will build a runtime that is dependent on
# DLAC's libraries which also enables both AOT and JIT flow.
#
# Note: HPS builds default to -disable_jit
##############################################################################

cmake_minimum_required(VERSION 3.10)

# CMake policies
# Use <PackageName>_ROOT env. variable as a prefix
if(POLICY CMP0074)
  cmake_policy(SET CMP0074 NEW)
endif()
# MSVC runtime library flags are selected by an abstraction.
#if(POLICY CMP0091)
#  cmake_policy(SET CMP0091 NEW)
#endif()
if(POLICY CMP0092)
  # Disable passing /W3 by default on MSVC
  cmake_policy(SET CMP0092 NEW)
endif()
# Honor visibility properties for all target types.
if(POLICY CMP0063)
  cmake_policy(SET CMP0063 NEW)
endif()
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)

project(coredla_runtime)

if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*|aarch64.*|AARCH64.*)")
  set(ARM ON)
endif()

set (TARGET_NAME coreDlaRuntimePlugin)

if (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
  set(CMAKE_CXX_STANDARD 14)
else()
  set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Checking for COREDLA_ROOT being set should be handled by build_runtime.sh
# We just double-check here
if (NOT DEFINED ENV{COREDLA_ROOT})
  message(FATAL_ERROR "COREDLA_ROOT environment variable not set.")
endif()

if (WIN32)
  set(Protobuf_USE_STATIC_LIBS ON)
  list (APPEND CMAKE_PREFIX_PATH $ENV{PROTOBUF_HOME} $ENV{PROTOBUF_LIBS} )
  include(FindProtobuf)
  find_package(Protobuf REQUIRED)
endif()

#
# Adds compiler flags to C / C++ sources
#
macro(dla_add_compiler_flags)
    foreach(flag ${ARGN})
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
    endforeach()
endmacro()

get_filename_component(CHK1 $ENV{COREDLA_ROOT}/Makefile ABSOLUTE)
get_filename_component(CHK2 ${CMAKE_CURRENT_SOURCE_DIR}/Makefile ABSOLUTE)
####################################################################
## SDL required compiler flags
####################################################################
# Needed for all builds

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if (ARM)
  # Built static library to simplify ED4 files.
  option(BUILD_SHARED_LIBS "Build as a static library" OFF)
else()
  option(BUILD_SHARED_LIBS "Build as a shared library" ON)
endif()

if (WIN32)

  if (CMAKE_BUILD_TYPE STREQUAL "Release")
    if(MSVC)
      dla_add_compiler_flags(/sdl)
    endif()
    dla_add_compiler_flags("/guard:cf")
    if (ENABLE_INTEGRITYCHECK)
      set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /INTEGRITYCHECK")
    endif()
  endif()

  dla_add_compiler_flags(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
  # CMake adds the following default compiler flags when generating projects for Visual Studio:
  # /DWIN32 /D_WINDOWS /W3 /GR /EHsc
  if (MSVC)
    set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
  else()
    dla_add_compiler_flags(/EHsc) # no asynchronous structured exception handling
  endif()
  dla_add_compiler_flags(/Gy) # remove unreferenced functions: function level linking
  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
  # see https://msdn.microsoft.com/en-us/library/fwkeyyhe.aspx for details
  # /ZI = include debug info
  # /Wall = all warnings
  add_compile_options("$<$<CONFIG:RELWITHDEBINFO>:/O2>")
  add_compile_options("$<$<CONFIG:RELWITHDEBINFO>:/ZI>")
  add_compile_options("$<$<CONFIG:RELEASE>:/O2>")
  add_compile_options("$<$<CONFIG:RELEASE>:/D>")
  add_compile_options("$<$<CONFIG:RELEASE>:/NDEBUG>")
  add_compile_options("$<$<CONFIG:DEBUG>:/Od>")
  # buffers security check
  add_compile_options(/GS)

  add_compile_options(/permissive-)

  # Compiler specific flags
  dla_add_compiler_flags(/bigobj)
  dla_add_compiler_flags(/MP)

  # Disable noisy warnings
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4308 /wd4703 /wd4244 /wd4819")
  if (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4146 /wd4996")
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4146 /wd4996")
    # C4251 needs to have dll-interface to be used by clients of class
    dla_add_compiler_flags(/wd4251)
    # C4275 non dll-interface class used as base for dll-interface class
    dla_add_compiler_flags(/wd4275)
    # Because permissive is set
    dla_add_compiler_flags(/wd5208)

    # inline is not a keyword in visual studios old C version, allow its redefinition
    add_definitions("-D_ALLOW_KEYWORD_MACROS")
  endif()

  # Debug information flags, by default CMake adds /Zi option
  # but provides no way to specify CMAKE_COMPILE_PDB_NAME on root level
  # In order to avoid issues with ninja we are replacing default flag instead of having two of them
  # and observing warning D9025 about flag override
  string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
  string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
  string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
  string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
else()
  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat -Wformat-security")

  set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security")

  set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")

  set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fPIE")
  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE")

  # Release build only
  set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2")
  if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
    set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fstack-protector-strong")
    set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -z noexecstack -z relro -z now")

    # These are for 8478-CT158 in the SDL process
    # ( https://sdp-prod.intel.com/bunits/intel/coredla/coredla-ip-20212/tasks/phase/development/8478-CT158/ )
  else()
    set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fstack-protector-all")
  endif()

  # Release build only
  set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2")
  if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
    set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fstack-protector-strong")
    set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -z noexecstack -z relro -z now")
  else()
    set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fstack-protector-all")
  endif()

  # These are for 8478-CT158 in the SDL process
  # ( https://sdp-prod.intel.com/bunits/intel/coredla/coredla-ip-20212/tasks/phase/development/8478-CT158/ )
  set (CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -fno-strict-overflow -fno-delete-null-pointer-checks -fwrapv")
  set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -fno-strict-overflow -fno-delete-null-pointer-checks -fwrapv")
  set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -fno-strict-overflow -fno-delete-null-pointer-checks -fwrapv")

  ####################################################################

  set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")

  set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -ggdb3")
  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ggdb3")

  #### Sanitizer settings ####
  # Address
  set(CMAKE_C_FLAGS_ASAN "-O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")
  set(CMAKE_CXX_FLAGS_ASAN "-O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")

  # Memory
  set(CMAKE_C_FLAGS_MSAN "-O1 -g -fsanitize=memory -fno-omit-frame-pointer -fno-optimize-sibling-calls")
  set(CMAKE_CXX_FLAGS_MSAN "-O1 -g -fsanitize=memory -fno-omit-frame-pointer -fno-optimize-sibling-calls")

  # Thread
  set(CMAKE_C_FLAGS_TSAN "-O1 -g -fsanitize=thread -fno-omit-frame-pointer -fno-optimize-sibling-calls")
  set(CMAKE_CXX_FLAGS_TSAN "-O1 -g -fsanitize=thread -fno-omit-frame-pointer -fno-optimize-sibling-calls")


  set (CMAKE_CXX_STANDARD 11)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  # Enable all warnings except unknown-pragmas.  Wunknown-pragmas must be excluded because
  # it is triggered by header file included from OpenCL runtime
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unknown-pragmas")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unknown-pragmas")

  # Might be too strict for wide deployment, but easy to disable if it causes problems.
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")


  # Edwinzha: With OV 2023.3.0 LTS a warning is thrown everytime old api is used. Suppress for now until we do a full uplift.
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-cpp")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")

  # This is required on Ubuntu 18; the new linker behaviour transforms
  # RPATH into RUNPATH (which can be seen in the output of 'readelf -d').
  # However, RUNPATH does not work recursively, so when OpenVINO reads
  # the plugins.xml file and searches for the specified libcoreDlaRuntimePlugin.so
  # library, it fails.  The --disable-new-dtags option causes the linker
  # to keep RPATH as RPATH (rather than morphing to RUNPATH).
  #
  # References:
  #  https://stackoverflow.com/questions/52018092/how-to-set-rpath-and-runpath-with-gcc-ld
  #  https://stackoverflow.com/questions/59248421/c-secondary-dependency-resolution-with-runpath
  #
  # The solution below seems preferable to setting LD_LIBRARY_PATH, if only barely.
  # For additional motivation, go ahead and throw away part of your day reading either
  # of the screeds:
  #  http://xahlee.info/UnixResource_dir/_/ldpath.html
  #  https://gms.tf/ld_library_path-considered-harmful.html
  # You may find that neither is fully convincing, of course.
  set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--disable-new-dtags")
endif()

# DLA specific modifications made to the MMD
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDLA_MMD")

if (${HW_BUILD_PLATFORM} STREQUAL "SYSTEM_CONSOLE")
  set (SYSTEM_CONSOLE_PLATFORM 1)
  set (MMD_DIR_NAME system_console)
  set (MMD_LIB_NAME system_console_mmd)
elseif (${HW_BUILD_PLATFORM} STREQUAL "DE10_AGILEX")
  set (DE10_AGILEX 1)
  set (MMD_DIR_NAME de10_agilex)
  set (MMD_LIB_NAME de10_agilex_mmd)
elseif(${HW_BUILD_PLATFORM} STREQUAL "HPS_PLATFORM")
  set (HPS_PLATFORM 1)
  set (MMD_DIR_NAME hps_platform)
  set (MMD_LIB_NAME hps_platform_mmd)
elseif(${HW_BUILD_PLATFORM} STREQUAL "DCP_A10_PAC")
  set (PAC_A10 1)
  set (MMD_DIR_NAME dcp_a10_pac)
  set (MMD_LIB_NAME intel_opae_mmd)
elseif(${HW_BUILD_PLATFORM} STREQUAL "AGX7_I_DK")
  set (AGX7_IDK 1)
  set (MMD_DIR_NAME agx7_ofs_pcie)
  set (MMD_LIB_NAME intel_opae_mmd)
elseif(${HW_BUILD_PLATFORM} STREQUAL "AGX7_N6001")
  set (AGX7_N6001 1)
  set (MMD_DIR_NAME agx7_ofs_pcie)
  set (MMD_LIB_NAME intel_opae_mmd)
  add_definitions(-DUSE_N6001_BOARD)
else()
  set (EMULATION 1)
endif()

# Set HPS_AGX7 if building for HPS and Agilex 7 is selected
if ("${HW_BUILD_PLATFORM}" STREQUAL "HPS_PLATFORM" AND "${HPS_BUILD_MACHINE}" STREQUAL "agilex7_dk_si_agi027fa")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHPS_AGX7")
endif()

# Set HPS_PLATFORM if building for HPS
if (HPS_PLATFORM)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHPS_PLATFORM")
endif()

if (NOT HPS_PLATFORM)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_OLD_COREDLA_DEVICE")
endif()

# Flag to disable JIT mode
if (DISABLE_JIT)
  set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISABLE_JIT")
endif()

# Build the runtime variant of the DLA plugin
add_definitions(-DRUNTIME_DLA_PLUGIN)

##########
if (NOT OpenVINO_DIR)
  Set (OpenVINO_DIR $ENV{OpenVINO_DIR})
endif()

find_package(OpenVINO CONFIG REQUIRED)
#########

if (NOT CoreDLA_DIR)
  set(CoreDLA_DIR $ENV{CoreDLA_DIR})
endif()

if (NOT DISABLE_JIT)
  find_package(CoreDLA CONFIG REQUIRED)
endif()

file(TO_CMAKE_PATH $ENV{COREDLA_ROOT} COREDLA_ROOT)

# Gets a build version of {git branch}-{git hash} as an identifier for the plugin build version. Defaults to "Custom Build"
function(get_build_version output_variable)
  # Get branch name
  execute_process(
    COMMAND git rev-parse --abbrev-ref HEAD
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    RESULT_VARIABLE result_var_branch
    OUTPUT_VARIABLE branch_name
    ERROR_QUIET
    OUTPUT_STRIP_TRAILING_WHITESPACE
  )
  # Get hash
  execute_process(
    COMMAND git rev-parse --short=10 HEAD
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    RESULT_VARIABLE result_var_hash
    OUTPUT_VARIABLE git_hash
    ERROR_QUIET
    OUTPUT_STRIP_TRAILING_WHITESPACE
  )
  if(NOT ${result_var_branch} EQUAL 0 OR NOT ${result_var_hash} EQUAL 0)
    set(${output_variable} "Custom build" PARENT_SCOPE)
  else()
    set(${output_variable} "${branch_name}-${git_hash}" PARENT_SCOPE)
  endif()
endfunction()
# Call function to get Git branch name
get_build_version(PLUGIN_BUILD_VERSION)

# Pass PLUGIN_BUILD_VERSION to the source code via a define
add_definitions(-DPLUGIN_BUILD_VERSION="${PLUGIN_BUILD_VERSION}")

if (NOT ARM)
  # ED4 OV is not built with tbb threading
  find_package(TBB REQUIRED tbb)
  if ( NOT DEFINED TBB_IMPORTED_TARGETS)
    set (TBB_IMPORTED_TARGETS TBB::tbb TBB::tbbmalloc TBB::tbbmalloc_proxy)
  endif()
endif()

SET (INFO 0)
SET (WARNING 1)
SET (ERROR 2)
SET (FATAL 3)

if(DEBUG_RUNTIME)
  add_definitions(-DDEBUG_RUNTIME)
endif(DEBUG_RUNTIME)
if(DEBUG_RUNTIME_MEMORY_TEST)
  add_definitions(-DDEBUG_RUNTIME_MEMORY_TEST)
endif(DEBUG_RUNTIME_MEMORY_TEST)
if(RUNTIME_VERBOSITY)
  add_definitions(-DENABLE_LOGGING)
  add_definitions(-DRUNTIME_VERBOSITY=${${RUNTIME_VERBOSITY}})
endif(RUNTIME_VERBOSITY)

if(RUNTIME_POLLING)
  add_definitions(-DCOREDLA_RUNTIME_POLLING)
endif(RUNTIME_POLLING)

# OpenVINO pre-requisites to build hetero & dla plugin
add_subdirectory(${COREDLA_ROOT}/thirdparty/openvino_dev_api thirdparty/openvino_dev_api)
add_subdirectory($ENV{COREDLA_XUTIL_DIR}/transformations ${CMAKE_CURRENT_BINARY_DIR}/transformations)

# CoreDLA ships the hetero plugin shared library. If AOT only runtime, we re-compile from src and
# do not use the shipped library.
if (DISABLE_JIT)
  add_subdirectory(${COREDLA_ROOT}/thirdparty/pugixml ${CMAKE_CURRENT_BINARY_DIR}/thirdparty/pugixml)
  add_subdirectory(${COREDLA_ROOT}/util/hetero_plugin ${CMAKE_CURRENT_BINARY_DIR}/hetero_plugin)
endif()

# Required for dla_benchmark and demos
add_subdirectory(common)

# Build runtime plugin CPU io transforms
add_subdirectory(${COREDLA_ROOT}/dla_plugin/io_transformations ${CMAKE_BINARY_DIR}/dla_plugin/io_transformations)

# Build Runtime plugin (AGX7/A10/HPS/Emulator)
if(NOT EMULATION)
  file(GLOB SOURCES
    ${CMAKE_CURRENT_SOURCE_DIR}/coredla_device/src/*.cpp
    ${COREDLA_ROOT}/dla_plugin/src/*.cpp
  )

  if (SYSTEM_CONSOLE_PLATFORM)
    list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/coredla_device/src/mmd_wrapper.cpp)
  endif()

  # We seem to have a partial copy of the compiled_result_reader_writer.cpp inside
  # of plugin/src/dla_compiled_model.cpp. The duplicate code should probably be removed.
  if (DISABLE_JIT)
  list(APPEND SOURCES
    # Only required if building runtime independently of dla
    $ENV{COREDLA_ROOT}/util/src/dla_numeric_utils.cpp
    $ENV{COREDLA_XUTIL_DIR}/compiled_result/src/compiled_result_reader_writer.cpp
  )
  endif()

  file(GLOB HEADERS
    ${COREDLA_ROOT}/dla_plugin/inc/dlia/*.hpp
    ${COREDLA_ROOT}/dla_plugin/inc/*.hpp
    ${COREDLA_ROOT}/dla_plugin/inc/*.h
    ${CMAKE_CURRENT_SOURCE_DIR}/coredla_device/inc/*.h
  )
  if (WIN32)
    list(APPEND HEADERS ${COREDLA_ROOT}/fpga/dma/rtl/dla_dma_constants.svh)
  endif()
  add_library(${TARGET_NAME} SHARED ${SOURCES} ${HEADERS})

  if (SYSTEM_CONSOLE_PLATFORM)
    target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/coredla_device/mmd/system_console/mmd_wrapper.cpp)
    add_custom_command(
      TARGET ${TARGET_NAME} POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy
      ${CMAKE_SOURCE_DIR}/coredla_device/mmd/system_console/system_console_script.tcl
      ${CMAKE_CURRENT_BINARY_DIR}/system_console_script.tcl
    )
    target_compile_definitions(${TARGET_NAME} PRIVATE DLA_SYSCON_SOURCE_ROOT=${CMAKE_CURRENT_BINARY_DIR})
  else()
    target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/coredla_device/src/mmd_wrapper.cpp)
  endif()
endif()

if (WIN32)
  # Fix warning C4273: inconsistent dll linkage
  target_compile_definitions(${TARGET_NAME} PRIVATE XBYAK_NO_OP_NAMES
    IMPLEMENT_INFERENCE_ENGINE_PLUGIN
    $<TARGET_PROPERTY:openvino::runtime,INTERFACE_COMPILE_DEFINITIONS>)
endif()

if (DLA_ALLOW_ENCRYPTION)
  add_definitions(-DDLA_ALLOW_ENCRYPTION)
  find_package(OpenSSL REQUIRED)
  set (CRYPTO_LIB_NAME OpenSSL::Crypto)
endif()

if (NOT WIN32)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -lrt" )
endif()

if(NOT EMULATION)
  target_include_directories(${TARGET_NAME} PUBLIC
    ${COREDLA_ROOT}/dla_plugin/inc
    ${COREDLA_ROOT}/dla_plugin/
    ${CMAKE_CURRENT_SOURCE_DIR}/coredla_device/inc
    ${CMAKE_CURRENT_SOURCE_DIR}/coredla_device/mmd/${MMD_DIR_NAME}/host
    ${CMAKE_CURRENT_SOURCE_DIR}/coredla_device/mmd/${MMD_DIR_NAME}/include
    ${CMAKE_CURRENT_SOURCE_DIR}/coredla_device/stream_controller/app
    ${COREDLA_ROOT}/util/inc
  )

  if (WIN32)
    target_include_directories(${TARGET_NAME} PUBLIC ${Protobuf_INCLUDE_DIRS})
  endif()

  if (NOT HPS_PLATFORM)
    find_package(Boost REQUIRED COMPONENTS filesystem)

    target_link_libraries(${TARGET_NAME} PUBLIC
      ${CMAKE_DL_LIBS}
      ${TBB_IMPORTED_TARGETS}
      openvino::runtime
      openvino_dev_api
      dliaPluginIOTransformations
      dla_op_transformation
      ${MMD_LIB_NAME}
      ${CRYPTO_LIB_NAME}
      Boost::filesystem
    )

    if (NOT DISABLE_JIT)
      target_link_libraries(${TARGET_NAME} PUBLIC
        archparam
        dla_compiler_core
        dla_compiled_result
        lpsolve5525
      )
    endif()
  else()
    target_link_libraries(${TARGET_NAME} PUBLIC
      ${CMAKE_DL_LIBS}
      openvino::runtime
      openvino_dev_api
      dliaPluginIOTransformations
      dla_op_transformation
      ${MMD_LIB_NAME}
    )
  endif()

  # Needed for coredla_device/inc/dla_dma_constants.h to find dla_dma_constants.svh, since
  # the cmake description (find_package(CoreDLA)) does not know about this dependency.
  #
  # Also needed for a variety of .h files in the DISABLE_JIT case, where we do not
  # use the CoreDLA package.
  if (EXISTS ${COREDLA_ROOT}/inc)
    target_include_directories(${TARGET_NAME} PUBLIC ${COREDLA_ROOT}/inc)
  else()
    target_include_directories(${TARGET_NAME} PUBLIC ${COREDLA_ROOT}/build/coredla/dla/inc)
  endif()

  get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
  foreach(dir ${dirs})
    message(STATUS "dir='${dir}'")
  endforeach()
  add_subdirectory(coredla_device/mmd/${MMD_DIR_NAME})
  # For some reason, (${HW_BUILD_PLATFORM} STREQUAL "DE10_AGILEX") does not work in the line below
  if (DE10_AGILEX)
    add_subdirectory(fpga_jtag_reprogram)
  endif()
  if (WIN32)
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/plugins_win.xml ${CMAKE_CURRENT_BINARY_DIR}/plugins.xml COPYONLY)
  else()
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/plugins.xml ${CMAKE_CURRENT_BINARY_DIR}/ COPYONLY)
  endif()

  # This is an ugly hack to keep internal regression tests happy
  if (NOT HPS_PLATFORM)
    if (DEFINED ENV{ARC_JOB_ID})
      if (EXISTS "/p/psg/pac/release/rush_creek/adapt/19.1/367/linux64/sw/deps/lib/libjson-c.so.4")
        target_link_libraries(${TARGET_NAME} PUBLIC "/p/psg/pac/release/rush_creek/adapt/19.1/367/linux64/sw/deps/lib/libjson-c.so.4")
      endif()
    endif()
  endif()
  if (NOT HPS_PLATFORM)
    add_subdirectory(dla_aot_splitter)
  endif()
endif()

add_subdirectory(dla_benchmark)

# Runtime demos are not built by default.
# Pass argument -build_demo to build_runtime.sh to build runtime demos.
if (DEFINED BUILD_DEMO)
  if (DISABLE_JIT)
    message(FATAL_ERROR
      "Error: BUILD_DEMO requires JIT support, but JIT compilation disabled via DISABLE_JIT."
      "       If you did not specify these options, then they may have been cached.  Remove"
      "       ${CMAKE_BINARY_DIR} to clear the cache."
  )
  endif()
  add_subdirectory(classification_sample_async)
  add_subdirectory(object_detection_demo)
  add_subdirectory(segmentation_demo)
endif()

if (HPS_PLATFORM)
  add_subdirectory(streaming/streaming_inference_app)
  add_subdirectory(streaming/image_streaming_app)
endif()

# Runtime install is applicable for Windows only
if (WIN32)
  install(TARGETS ${TARGET_NAME}
    RUNTIME DESTINATION "dla/runtime/bin" COMPONENT RUNTIME
    LIBRARY DESTINATION "dla/runtime/lib" COMPONENT RUNTIME
    ARCHIVE DESTINATION "dla/runtime/lib" COMPONENT RUNTIME
  )
endif()

# Add ed0 streaming example tcl script
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/streaming/ed0_streaming_example/system_console_script.tcl
     DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/streaming/ed0_streaming_example/.)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/streaming/ed0_streaming_example/system_console_script_perf.tcl
     DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/streaming/ed0_streaming_example/.)