[GNA] Added tests for negative memory layer offset and split - trivial permute -...
[platform/upstream/dldt.git] / inference-engine / CMakeLists.txt
1 # Copyright (C) 2018-2020 Intel Corporation
2 # SPDX-License-Identifier: Apache-2.0
3 #
4 project(InferenceEngine)
5
6 set(CMAKE_MODULE_PATH "${IE_MAIN_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
7
8 include(features_ie)
9
10 # include developer package
11 include(developer_package_ie)
12
13 # These options are shared with 3rdparty plugins by means of developer package
14 include(check_features_ie)
15
16 # resolving dependencies for the project
17 include(dependencies)
18
19
20 # Fuzz tests also building without ENABLE_FUZZING
21 include(fuzzing)
22
23 if (ENABLE_FUZZING)
24     enable_fuzzing()
25 endif()
26
27 find_package(Threads REQUIRED)
28
29 unset(IEDeveloperPackageTargets CACHE)
30 function(ie_developer_export_targets)
31     set(IEDeveloperPackageTargets "${IEDeveloperPackageTargets};${ARGV}")
32
33     # to allow exporting of aliased targets with the original names
34     foreach(target_name ${IEDeveloperPackageTargets})
35         if(TARGET "${target_name}")
36             get_target_property(original_name ${target_name} ALIASED_TARGET)
37             if(TARGET "${original_name}")
38                 message(STATUS "The name ${target_name} is an ALIAS for ${original_name}. "
39                         "It will be exported to the InferenceEngineDeveloperPackage with the original name.")
40                 list(REMOVE_ITEM IEDeveloperPackageTargets ${target_name})
41                 list(APPEND IEDeveloperPackageTargets ${original_name})
42             endif()
43         endif()
44     endforeach()
45
46     list(REMOVE_DUPLICATES IEDeveloperPackageTargets)
47     set(IEDeveloperPackageTargets "${IEDeveloperPackageTargets}" CACHE INTERNAL
48         "Paths to extra Inference Engine plugins" FORCE)
49 endfunction()
50
51 function(ie_developer_export)
52     export(TARGETS ${OpenVINODeveloperPackageTargets} NAMESPACE IE::
53         APPEND FILE "${CMAKE_BINARY_DIR}/targets_developer.cmake")
54
55     export(TARGETS ${IEDeveloperPackageTargets} NAMESPACE IE::
56         APPEND FILE "${CMAKE_BINARY_DIR}/targets_developer.cmake")
57
58     # Custom target to build only Inference Engine Developer Package targets
59     add_custom_target(ie_dev_targets ALL DEPENDS ${OpenVINODeveloperPackageTargets} ${IEDeveloperPackageTargets} gflags
60                       inference_engine_ir_reader inference_engine_ir_v7_reader)
61 endfunction()
62
63 add_subdirectory(thirdparty)
64
65 add_subdirectory(src)
66
67 if(ENABLE_TESTS)
68     add_subdirectory(tests_deprecated)
69     add_subdirectory(tests)
70 endif()
71
72 add_subdirectory(tools)
73
74 function(ie_build_samples)
75     # samples should be build with the same flags as from OpenVINO package,
76     # so unset all flags
77     foreach(var CMAKE_CXX_FLAGS CMAKE_C_FLAGS CMAKE_CXX_STANDARD
78                 CMAKE_EXE_LINKER_FLAGS CMAKE_POLICY_DEFAULT_CMP0063
79                 CMAKE_CXX_VISIBILITY_PRESET CMAKE_C_VISIBILITY_PRESET
80                 CMAKE_VISIBILITY_INLINES_HIDDEN CMAKE_POSITION_INDEPENDENT_CODE
81                 THREADS_PREFER_PTHREAD_FLAG X86_64 X86 ARM AARCH64 LINUX
82                 MINGW64 CMAKE_BUILD_TYPE CMAKE_MACOSX_RPATH)
83         unset(${var})
84     endforeach()
85     include(sanitizer)
86     add_subdirectory(samples)
87 endfunction()
88
89 # gflags and format_reader targets are kept inside of samples directory and
90 # they must be built even if samples build is disabled (required for tests and tools).
91 ie_build_samples()
92
93 file(GLOB_RECURSE SAMPLES_SOURCES samples/*.cpp samples/*.hpp samples/*.h)
94 add_cpplint_target(sample_cpplint
95     FOR_SOURCES ${SAMPLES_SOURCES}
96     EXCLUDE_PATTERNS "thirdparty/*" "pugixml/*")
97
98 if (ENABLE_PYTHON)
99     add_subdirectory(ie_bridges/python)
100 endif()
101
102 add_subdirectory(ie_bridges/c)
103
104 if (ENABLE_JAVA)
105     add_subdirectory(ie_bridges/java)
106 endif()
107
108 add_cpplint_report_target()
109
110 #
111 # Install
112 #
113
114 # install C++ samples
115
116 ie_cpack_add_component(cpp_samples REQUIRED DEPENDS core)
117
118 if(UNIX)
119     install(DIRECTORY samples/
120             DESTINATION ${IE_CPACK_IE_DIR}/samples/cpp
121             COMPONENT cpp_samples
122             USE_SOURCE_PERMISSIONS
123             PATTERN *.bat EXCLUDE
124             PATTERN speech_libs_and_demos EXCLUDE)
125 elseif(WIN32)
126     install(DIRECTORY samples/
127             DESTINATION ${IE_CPACK_IE_DIR}/samples/cpp
128             COMPONENT cpp_samples
129             USE_SOURCE_PERMISSIONS
130             PATTERN *.sh EXCLUDE
131             PATTERN speech_libs_and_demos EXCLUDE)
132 endif()
133
134 # install C samples
135
136 ie_cpack_add_component(c_samples REQUIRED DEPENDS core)
137
138 if(UNIX)
139     install(PROGRAMS samples/build_samples.sh
140             DESTINATION ${IE_CPACK_IE_DIR}/samples/c
141             COMPONENT c_samples)
142 elseif(WIN32)
143     install(PROGRAMS samples/build_samples_msvc.bat
144             DESTINATION ${IE_CPACK_IE_DIR}/samples/c
145             COMPONENT c_samples)
146 endif()
147
148 install(DIRECTORY ie_bridges/c/samples/
149         DESTINATION ${IE_CPACK_IE_DIR}/samples/c
150         COMPONENT c_samples
151         PATTERN ie_bridges/c/samples/CMakeLists.txt EXCLUDE)
152
153 install(FILES samples/CMakeLists.txt
154         DESTINATION ${IE_CPACK_IE_DIR}/samples/c
155         COMPONENT c_samples)
156
157 # install Python samples
158
159 if(ENABLE_PYTHON)
160     ie_cpack_add_component(python_samples REQUIRED DEPENDS core)
161
162     install(DIRECTORY ${ie_python_api_SOURCE_DIR}/sample/
163             DESTINATION ${IE_CPACK_IE_DIR}/samples/python
164             COMPONENT python_samples)
165 endif()
166
167 # install speech demo files
168
169 if(SPEECH_LIBS_AND_DEMOS)
170     ie_cpack_add_component(speech_demo_files REQUIRED)
171
172     install(DIRECTORY ${TEMP}/deployment_tools
173                       ${TEMP}/data_processing
174             DESTINATION .
175             COMPONENT speech_demo_files)
176 endif()
177
178 #
179 # Developer package
180 #
181
182 ie_developer_export_targets(format_reader)
183 ie_developer_export_targets(${NGRAPH_LIBRARIES})
184
185 # for Template plugin
186 if(NGRAPH_INTERPRETER_ENABLE)
187     ie_developer_export_targets(ngraph_backend interpreter_backend)
188 endif()
189
190 ie_developer_export()
191
192 configure_file(
193     "${IE_MAIN_SOURCE_DIR}/cmake/developer_package_config.cmake.in"
194     "${CMAKE_BINARY_DIR}/InferenceEngineDeveloperPackageConfig.cmake"
195     @ONLY)
196
197 configure_file(
198     "${IE_MAIN_SOURCE_DIR}/cmake/share/InferenceEngineConfig-version.cmake.in"
199     "${CMAKE_BINARY_DIR}/InferenceEngineDeveloperPackageConfig-version.cmake"
200     COPYONLY)
201
202 #
203 # Coverage
204 #
205
206 if(ENABLE_COVERAGE)
207     include(coverage_ie)
208 endif()
209
210 #
211 # Add extra modules
212 #
213
214 function(register_extra_modules)
215     set(InferenceEngineDeveloperPackage_DIR "${CMAKE_CURRENT_BINARY_DIR}/build-modules")
216
217     function(generate_fake_dev_package)
218         set(iedevconfig_file "${InferenceEngineDeveloperPackage_DIR}/InferenceEngineDeveloperPackageConfig.cmake")
219         file(REMOVE "${iedevconfig_file}")
220
221         file(WRITE "${iedevconfig_file}" "\# !! AUTOGENERATED: DON'T EDIT !!\n\n")
222         file(APPEND "${iedevconfig_file}" "ie_deprecated_no_errors()\n")
223
224         foreach(target IN LISTS OpenVINODeveloperPackageTargets IEDeveloperPackageTargets)
225             if(target)
226                 file(APPEND "${iedevconfig_file}" "add_library(IE::${target} ALIAS ${target})\n")
227             endif()
228         endforeach()
229     endfunction()
230
231     generate_fake_dev_package()
232
233     # automatically import plugins from the 'plugins' folder
234     file(GLOB local_extra_modules "plugins/*")
235     if(NGRAPH_INTERPRETER_ENABLE)
236         list(APPEND local_extra_modules "${OpenVINO_MAIN_SOURCE_DIR}/docs/template_plugin")
237     endif()
238
239     # detect where IE_EXTRA_MODULES contains folders with CMakeLists.txt
240     # other folders are supposed to have sub-folders with CMakeLists.txt
241     foreach(module_path IN LISTS IE_EXTRA_MODULES)
242         if(EXISTS "${module_path}/CMakeLists.txt")
243             list(APPEND extra_modules "${module_path}")
244         elseif(module_path)
245             file(GLOB extra_modules ${extra_modules} "${module_path}/*")
246         endif()
247     endforeach()
248
249     # add each extra module
250     foreach(module_path IN LISTS extra_modules local_extra_modules)
251         if(module_path)
252             get_filename_component(module_name "${module_path}" NAME)
253             set(build_module ON)
254             if(NOT EXISTS "${module_path}/CMakeLists.txt") # if module is built not using cmake
255                 set(build_module OFF)
256             endif()
257             if(NOT DEFINED BUILD_${module_name})
258                 set(BUILD_${module_name} ${build_module} CACHE BOOL "Build ${module_name} extra module" FORCE)
259             endif()
260             if(BUILD_${module_name})
261                 message(STATUS "Register ${module_name} to be built in build-modules/${module_name}")
262                 add_subdirectory("${module_path}" "build-modules/${module_name}")
263             endif()
264         endif()
265     endforeach()
266 endfunction()
267
268 register_extra_modules()