412a2bfaba40d9d82c99cafabd58d44fabe9c337
[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
14 # by means of developer package
15 include(check_features_ie)
16
17 # resolving dependencies for the project
18 include(dependencies)
19
20
21 # Fuzz tests also building without ENABLE_FUZZING
22 include(fuzzing)
23
24 if (ENABLE_FUZZING)
25     enable_fuzzing()
26 endif()
27
28 find_package(Threads REQUIRED)
29
30 unset(IEDeveloperPackageTargets CACHE)
31 function(ie_developer_export_targets)
32     set(IEDeveloperPackageTargets "${IEDeveloperPackageTargets};${ARGV}")
33
34     # to allow exporting of aliased targets with the original names
35     foreach(target_name ${IEDeveloperPackageTargets})
36         if(TARGET "${target_name}")
37             get_target_property(original_name ${target_name} ALIASED_TARGET)
38             if(TARGET "${original_name}")
39                 message(STATUS "The name ${target_name} is an ALIAS for ${original_name}. "
40                         "It will be exported to the InferenceEngineDeveloperPackage with the original name.")
41                 list(REMOVE_ITEM IEDeveloperPackageTargets ${target_name})
42                 list(APPEND IEDeveloperPackageTargets ${original_name})
43             endif()
44         endif()
45     endforeach()
46
47     list(REMOVE_DUPLICATES IEDeveloperPackageTargets)
48     set(IEDeveloperPackageTargets "${IEDeveloperPackageTargets}" CACHE INTERNAL
49         "Paths to extra Inference Engine plugins" FORCE)
50 endfunction()
51
52 function(ie_developer_export)
53     export(TARGETS ${IEDeveloperPackageTargets} NAMESPACE IE::
54             APPEND FILE "${CMAKE_BINARY_DIR}/targets_developer.cmake")
55
56     # Custom target to build only Inference Engine Developer Package targets
57     add_custom_target(ie_dev_targets ALL DEPENDS ${IEDeveloperPackageTargets} gflags)
58 endfunction()
59
60 add_subdirectory(thirdparty)
61
62 add_subdirectory(src)
63
64 if(ENABLE_TESTS)
65     add_subdirectory(tests_deprecated)
66     add_subdirectory(tests)
67 endif()
68
69 add_subdirectory(tools)
70
71 function(ie_build_samples)
72     # samples should be build with the same flags as from OpenVINO package,
73     # so unset all flags
74     foreach(var CMAKE_CXX_FLAGS CMAKE_C_FLAGS CMAKE_CXX_STANDARD
75                 CMAKE_EXE_LINKER_FLAGS CMAKE_POLICY_DEFAULT_CMP0063
76                 CMAKE_CXX_VISIBILITY_PRESET CMAKE_C_VISIBILITY_PRESET
77                 CMAKE_VISIBILITY_INLINES_HIDDEN CMAKE_POSITION_INDEPENDENT_CODE
78                 THREADS_PREFER_PTHREAD_FLAG X86_64 X86 ARM AARCH64 LINUX
79                 MINGW64 CMAKE_BUILD_TYPE CMAKE_MACOSX_RPATH)
80         unset(${var})
81     endforeach()
82
83     add_subdirectory(samples)
84 endfunction()
85
86 # gflags and format_reader targets are kept inside of samples directory and
87 # they must be built even if samples build is disabled (required for tests and tools).
88 ie_build_samples()
89
90 file(GLOB_RECURSE SAMPLES_SOURCES samples/*.cpp samples/*.hpp samples/*.h)
91 add_cpplint_target(sample_cpplint
92     FOR_SOURCES ${SAMPLES_SOURCES}
93     EXCLUDE_PATTERNS "thirdparty/*" "pugixml/*")
94
95 if (ENABLE_PYTHON)
96     add_subdirectory(ie_bridges/python)
97 endif()
98
99 if (ENABLE_C)
100     add_subdirectory(ie_bridges/c)
101 endif()
102
103 add_cpplint_report_target()
104
105 #
106 # Install
107 #
108
109 # install C++ samples
110
111 ie_cpack_add_component(cpp_samples REQUIRED DEPENDS core)
112
113 if(UNIX)
114     install(DIRECTORY samples/
115             DESTINATION ${IE_CPACK_IE_DIR}/samples/cpp
116             COMPONENT cpp_samples
117             USE_SOURCE_PERMISSIONS
118             PATTERN *.bat EXCLUDE
119             PATTERN speech_libs_and_demos EXCLUDE)
120 elseif(WIN32)
121     install(DIRECTORY samples/
122             DESTINATION ${IE_CPACK_IE_DIR}/samples/cpp
123             COMPONENT cpp_samples
124             USE_SOURCE_PERMISSIONS
125             PATTERN *.sh EXCLUDE
126             PATTERN speech_libs_and_demos EXCLUDE)
127 endif()
128
129 # install C samples
130
131 ie_cpack_add_component(c_samples REQUIRED DEPENDS core)
132
133 if(UNIX)
134     install(PROGRAMS samples/build_samples.sh
135             DESTINATION ${IE_CPACK_IE_DIR}/samples/c
136             COMPONENT c_samples)
137 elseif(WIN32)
138     install(PROGRAMS samples/build_samples_msvc.bat
139             DESTINATION ${IE_CPACK_IE_DIR}/samples/c
140             COMPONENT c_samples)
141 endif()
142
143 install(DIRECTORY ie_bridges/c/samples/
144         DESTINATION ${IE_CPACK_IE_DIR}/samples/c
145         COMPONENT c_samples
146         PATTERN ie_bridges/c/samples/CMakeLists.txt EXCLUDE)
147
148 install(FILES samples/CMakeLists.txt
149         DESTINATION ${IE_CPACK_IE_DIR}/samples/c
150         COMPONENT c_samples)
151
152 # install Python samples
153
154 if(ENABLE_PYTHON)
155     ie_cpack_add_component(python_samples REQUIRED DEPENDS core)
156
157     install(DIRECTORY ${ie_python_api_SOURCE_DIR}/sample/
158             DESTINATION ${IE_CPACK_IE_DIR}/samples/python
159             COMPONENT python_samples)
160 endif()
161
162 # install speech demo files
163
164 if(SPEECH_LIBS_AND_DEMOS)
165     ie_cpack_add_component(speech_demo_files REQUIRED)
166
167     install(DIRECTORY ${TEMP}/deployment_tools
168                       ${TEMP}/data_processing
169             DESTINATION .
170             COMPONENT speech_demo_files)
171 endif()
172
173 #
174 # Developer package
175 #
176
177 ie_developer_export_targets(format_reader)
178 ie_developer_export_targets(${NGRAPH_LIBRARIES})
179
180 ie_developer_export()
181
182 configure_file(
183     "${IE_MAIN_SOURCE_DIR}/cmake/developer_package_config.cmake.in"
184     "${CMAKE_BINARY_DIR}/InferenceEngineDeveloperPackageConfig.cmake"
185     @ONLY)
186
187 configure_file(
188     "${IE_MAIN_SOURCE_DIR}/cmake/share/InferenceEngineConfig-version.cmake.in"
189     "${CMAKE_BINARY_DIR}/InferenceEngineDeveloperPackageConfig-version.cmake"
190     COPYONLY)
191
192 #
193 # Coverage
194 #
195
196 if(ENABLE_COVERAGE)
197     include(coverage_ie)
198 endif()
199
200 #
201 # Add plugins
202 #
203
204 function(register_extra_plugins)
205     set(InferenceEngineDeveloperPackage_DIR "${CMAKE_CURRENT_BINARY_DIR}/build-plugins")
206     set(iedevconfig_file "${InferenceEngineDeveloperPackage_DIR}/InferenceEngineDeveloperPackageConfig.cmake")
207     file(REMOVE "${iedevconfig_file}")
208
209     file(WRITE "${iedevconfig_file}" "\# !! AUTOGENERATED: DON'T EDIT !!\n\n")
210     file(APPEND "${iedevconfig_file}" "ie_deprecated_no_errors()\n")
211
212     foreach(target IN LISTS IEDeveloperPackageTargets)
213         if(target)
214             file(APPEND "${iedevconfig_file}" "add_library(IE::${target} ALIAS ${target})\n")
215         endif()
216     endforeach()
217
218     # automatically import plugins from the 'plugins' folder
219     file(GLOB local_extra_plugins "plugins/*")
220     list(APPEND local_extra_plugins "${OpenVINO_MAIN_SOURCE_DIR}/docs/template_plugin")
221
222     foreach(plugin_path IN LISTS IE_EXTRA_PLUGINS local_extra_plugins)
223         get_filename_component(plugin_dir "${plugin_path}" NAME)
224         message(STATUS "Register ${plugin_dir} to be built in build-plugins/${plugin_dir}")
225         add_subdirectory("${plugin_path}" "build-plugins/${plugin_dir}")
226     endforeach()
227 endfunction()
228
229 register_extra_plugins()