Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / CMakeLists.txt
1 # Copyright (c) 2016 Intel Corporation
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6
7 #      http://www.apache.org/licenses/LICENSE-2.0
8
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
16 include(CheckCXXCompilerFlag)
17
18 # Register Intel helper modules.
19 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/utils/build/cmake/modules")
20 include(IntelHelpers)
21
22
23 # ======================================================================================================
24 # ==================================== BUILD CONFIGURATIONS (part 1) ===================================
25 # ======================================================================================================
26 # The section must be before project definition which is a point for configurations generation
27 # for multi-configuration generators.
28
29 # Available configuration types:
30 # Two standard configurations.
31 set(CMAKE_CONFIGURATION_TYPES
32     "Debug"
33     "Release"
34   )
35 set(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES} CACHE INTERNAL "Available build configurations.")
36
37 # ======================================================================================================
38 # ======================================================================================================
39 # ======================================================================================================
40
41 # Name of project (helper constant variable).
42 set(CLDNN__PROJ_NAME "clDNN")
43
44 # Default languages: C, C++.
45 project("${CLDNN__PROJ_NAME}")
46
47
48 # ======================================================================================================
49 # ==================================== BUILD CONFIGURATIONS (part 2) ===================================
50 # ======================================================================================================
51 # The section must be after project definition and its supported languages because otherwise
52 # used variables are not available yet.
53
54 #intel_custom_build_add("<custom config>" "Release") # No custom configuration at the momeent.
55 # Populating global property with list of debug configurations.
56 set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS "Debug")
57 # Use solution folders.
58 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
59
60 # ======================================================================================================
61 # ======================================================================================================
62 # ======================================================================================================
63
64
65 # ======================================================================================================
66 # ====================================== HELPER CONSTANT VARIABLES =====================================
67 # ======================================================================================================
68
69 # Path which points to main directory of project.
70 set(CLDNN__MAIN_DIR      "${CMAKE_CURRENT_SOURCE_DIR}")
71
72 # Path which points to directory with common dependencies (internal and 3-rd party).
73 set(CLDNN__COMMON_DIR    "${CMAKE_CURRENT_SOURCE_DIR}/common")
74
75 # Path which points to directory with interface for framework.
76 set(CLDNN__API_DIR       "${CMAKE_CURRENT_SOURCE_DIR}/api")
77
78 # Path which points to directory with interface extension for framework.
79 set(CLDNN__API_EXTENSION_DIR       "${CMAKE_CURRENT_SOURCE_DIR}/api_extension")
80
81 # Path which points to directory with interface for framework.
82 set(CLDNN__KERNEL_SELECTOR_DIR       "${CMAKE_CURRENT_SOURCE_DIR}/kernel_selector")
83
84 # Path which points to directory with binaries for Intel OpenCL SDK ICD (Installable Client Driver).
85 set(CLDNN__IOCL_ICD_DIR  "${CLDNN__COMMON_DIR}/intel_ocl_icd")
86
87 # Path which points to directory with C++ bindings for OpenCL (header files + wrapper that disables specific warnings).
88 set(CLDNN__KHR_CLHPP_DIR "${CLDNN__COMMON_DIR}/khronos_ocl_clhpp")
89
90 # Path which points to directory with fused version of googletest framework (with fused googlemock as well).
91 set(CLDNN__GTEST_DIR     "${CLDNN__COMMON_DIR}/googletest-fused")
92
93 # Build targets settings.
94
95 # Path which points to default root directory for compilation output.
96 set(CLDNN_BUILD__DEFAULT_OUT_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/build/out")
97
98 # Prefix for all targets in internal pass.
99 set(CLDNN_BUILD__PROJ_NAME_PREFIX "")
100
101 # Single/multi-configuration generator helpers.
102 if(CMAKE_CFG_INTDIR STREQUAL ".")
103   set(CLDNN__TARGET_CFG_VAR "${CMAKE_BUILD_TYPE}")
104   set(CLDNN__MULTI_CFG_GEN  NO)
105 else()
106   set(CLDNN__TARGET_CFG_VAR "${CMAKE_CFG_INTDIR}")
107   set(CLDNN__MULTI_CFG_GEN  YES)
108 endif()
109
110 # Code generation settings.
111
112 # Path which points to root directory where code generated elements are created.
113 set(CLDNN__CODEGEN_BASEDIR "${CMAKE_CURRENT_BINARY_DIR}/codegen")
114 # Path which points to root directory where code generated elements are created
115 # (specific to build configuration).
116 set(CLDNN__CODEGEN_DIR     "${CLDNN__CODEGEN_BASEDIR}/${CLDNN__TARGET_CFG_VAR}")
117
118 # Path which points to automatically included directory with code generated elements
119 # (to support "copy-if-different" optimization).
120 set(CLDNN__CODEGEN_INCDIR  "${CLDNN__CODEGEN_DIR}/include")
121
122 # Version file.
123 set(CLDNN__VERSION_FILE_NAME "${CLDNN__MAIN_DIR}/version.json")
124
125 # ======================================================================================================
126 # ======================================================================================================
127 # ======================================================================================================
128
129
130 # ======================================================================================================
131 # =========================================== HELPER FUNCTIONS =========================================
132 # ======================================================================================================
133
134 # Writes debug message in project (it will be presented only if debug is enabled).
135 #
136 # @param text Text to present.
137 function(cldnn_dmsg text)
138   if(CLDNN__CMAKE_DEBUG)
139     message(STATUS "[clDNN][D] ${text}")
140   endif()
141 endfunction()
142
143 # ======================================================================================================
144
145 # Locates and detects all versions of specific component.
146 #
147 # The highest version of component is also returned as default version to use.
148 #
149 # @param retVarNameVersions       Name of variable placeholder with all versions of specified component
150 #                                 which are available in the build.
151 # @param retVarNamePaths          Name of variable placeholder with all paths to versions of specified
152 #                                 component which are available in build. The paths map to corresponding
153 #                                 versions from retVarNameVersions (1:1).
154 # @param retVarNameDefaultVersion Default version to use. It is highest specified version, or 0 if no
155 #                                 version of component was found.
156 # @param componentName            Descriptive name of a component. It is presentated in warning and
157 #                                 debug messages.
158 # @param componentBaseDir         Base directory for component (directory containing version
159 #                                 subdirectories).
160 # @param [componentReqFile [...]] Optional list of component required files to check for existence.
161 #                                 The componentReqFile can contain file(GLOB) wildcards. If multiple
162 #                                 are specified, checked version is valid when all files are existing
163 #                                 (or GLOB return at least one file for each entry).
164 function(cldnn_locate_component_versions retVarNameVersions retVarNamePaths retVarNameDefaultVersion
165                                          componentName componentBaseDir)
166   if(NOT EXISTS "${componentBaseDir}")
167     cldnn_dmsg("Base directory for ${componentName} does not exist at ${componentBaseDir}.")
168     set("${retVarNameVersions}"       ""  PARENT_SCOPE)
169     set("${retVarNamePaths}"          ""  PARENT_SCOPE)
170     set("${retVarNameDefaultVersion}" "0" PARENT_SCOPE)
171     return()
172   endif()
173
174   # Detecting all versions of added component in the project.
175   file(GLOB __CLDNN_F_CompVersionPaths RELATIVE "${componentBaseDir}" "${componentBaseDir}/[0-9rRvV]*")
176   set(__CLDNN_F_CompVersions "")
177   set(__CLDNN_F_CompPaths    "")
178   foreach(__CLDNN_F_CompVersionPath ${__CLDNN_F_CompVersionPaths})
179     string(REPLACE ";" "\;" __CLDNN_F_CompVersionPath "${__CLDNN_F_CompVersionPath}") # [WA#1] Must escape ; again if occurred in item.
180     if(__CLDNN_F_CompVersionPath MATCHES "^[rRvV]?([0-9]+([\\._][0-9]+([\\._][0-9]+([\\._][0-9]+)?)?)?)")
181       string(REPLACE "_" "." __CLDNN_F_CompVersion "${CMAKE_MATCH_1}")
182       set(__CLDNN_F_CompPath "${componentBaseDir}/${__CLDNN_F_CompVersionPath}")
183
184       set(__CLDNN_F_CompPathValid TRUE)
185       foreach(__CLDNN_F_CompReqFile ${ARGN})
186         string(REPLACE ";" "\;" __CLDNN_F_CompReqFile "${__CLDNN_F_CompReqFile}") # [WA#1] Must escape ; again if occurred in item.
187         set(__CLDNN_F_CompReqFileGlob "${__CLDNN_F_CompPath}/${__CLDNN_F_CompReqFile}")
188
189         file(GLOB __CLDNN_F_CompReqTargets ${__CLDNN_F_CompReqFileGlob})
190         list(LENGTH __CLDNN_F_CompReqTargets __CLDNN_F_CompReqTargetsCount)
191         if(__CLDNN_F_CompReqTargetsCount LESS 1)
192             message(WARNING "[clDNN] ${componentName} at \"${__CLDNN_F_CompPath}\" does not contain required files. It will be omitted.")
193             set(__CLDNN_F_CompPathValid FALSE)
194             break()
195         endif()
196       endforeach()
197       unset(__CLDNN_F_CompReqFile)
198       unset(__CLDNN_F_CompReqFileGlob)
199       unset(__CLDNN_F_CompReqTargets)
200       unset(__CLDNN_F_CompReqTargetsCount)
201
202       if(__CLDNN_F_CompPathValid)
203         cldnn_dmsg("Found internal ${componentName} (version: ${__CLDNN_F_CompVersion}) at path: ${__CLDNN_F_CompPath}")
204         list(APPEND __CLDNN_F_CompVersions "${__CLDNN_F_CompVersion}")
205         list(APPEND __CLDNN_F_CompPaths    "${__CLDNN_F_CompPath}")
206       endif()
207     endif()
208   endforeach()
209   unset(__CLDNN_F_CompVersionPaths)
210   unset(__CLDNN_F_CompVersionPath)
211   unset(__CLDNN_F_CompVersion)
212   unset(__CLDNN_F_CompPath)
213   unset(__CLDNN_F_CompPathValid)
214
215   # Selecting highest version of component as a default version.
216   set(__CLDNN_F_CompDefaultVersion "0")
217   foreach(__CLDNN_F_CompVersion ${__CLDNN_F_CompVersions})
218     if(__CLDNN_F_CompVersion VERSION_GREATER __CLDNN_F_CompDefaultVersion)
219       set(__CLDNN_F_CompDefaultVersion "${__CLDNN_F_CompVersion}")
220     endif()
221   endforeach()
222   unset(__CLDNN_F_CompVersion)
223   cldnn_dmsg("Selected default version of internal ${componentName}: ${__CLDNN_F_CompDefaultVersion}")
224
225   set("${retVarNameVersions}"       ${__CLDNN_F_CompVersions}         PARENT_SCOPE)
226   set("${retVarNamePaths}"          ${__CLDNN_F_CompPaths}            PARENT_SCOPE)
227   set("${retVarNameDefaultVersion}" "${__CLDNN_F_CompDefaultVersion}" PARENT_SCOPE)
228 endfunction()
229
230
231 # ======================================================================================================
232 # ======================================================================================================
233 # ======================================================================================================
234
235
236 # Expressing CMake setting for current build configuration as option and providing a way to correct it (treat as case-insensitive).
237 if(DEFINED CMAKE_BUILD_TYPE)
238   string(TOLOWER "${CMAKE_BUILD_TYPE}" __CLDNN_BuildType)
239   string(STRIP "${__CLDNN_BuildType}" __CLDNN_BuildType)
240
241   if(__CLDNN_BuildType MATCHES "^release$")
242     set(__CLDNN_BuildType "Release")
243   elseif(__CLDNN_BuildType MATCHES "^debug$")
244     set(__CLDNN_BuildType "Debug")
245   else()
246     set(__CLDNN_BuildType "Debug")
247     if(NOT CLDNN__MULTI_CFG_GEN)
248       message(WARNING "[clDNN] CMAKE_BUILD_TYPE: Unknown build configuration. The following configurations are available: ${CMAKE_CONFIGURATION_TYPES}.
249           The \"${__CLDNN_BuildType}\" configuration will be used.
250
251           This value has meaning only for single-configuration generators (like Make). It will be ignored for MSVC/XCode."
252         )
253     endif()
254   endif()
255 else()
256   set(__CLDNN_BuildType "Debug")
257   if(NOT CLDNN__MULTI_CFG_GEN)
258     message(WARNING "[clDNN] CMAKE_BUILD_TYPE: No build configuration specified. The following configurations are available: ${CMAKE_CONFIGURATION_TYPES}.
259         The \"${__CLDNN_BuildType}\" configuration will be used.
260
261         This value has meaning only for single-configuration generators (like Make). It will be ignored for MSVC/XCode."
262       )
263   endif()
264 endif()
265 set(CMAKE_BUILD_TYPE "${__CLDNN_BuildType}")
266 unset(__CLDNN_BuildType)
267
268 # ======================================================================================================
269
270 # Detecting, setting and validating target architecture for compilation.
271
272 set(__CLDNN_RequestedArch "")
273
274 intel_arch_detect(__CLDNN_DetectedArch_Target __CLDNN_DetectedArch_Host __CLDNN_RequestedArch)
275 intel_arch_validate(__CLDNN_DetectedArchValid_Target "${__CLDNN_DetectedArch_Target}")
276 unset(__CLDNN_DetectedArch_Host)
277 unset(__CLDNN_RequestedArch)
278
279 if(DEFINED CLDNN__ARCHITECTURE_TARGET)
280   intel_arch_normalize(__CLDNN_Arch_Target "${CLDNN__ARCHITECTURE_TARGET}")
281 elseif(__CLDNN_DetectedArchValid_Target)
282   set(__CLDNN_Arch_Target "${__CLDNN_DetectedArch_Target}")
283   message("[clDNN] CLDNN__ARCHITECTURE_TARGET: Target architecture is not specified. Trying to deduce it from context.")
284 else()
285   message(FATAL_ERROR "[clDNN] CLDNN__ARCHITECTURE_TARGET: Target architecture is not specified and cannot be deduced from context.
286       Please specify one, e.g. Windows32, Linux64, Android32, Darwin32, ..."
287     )
288 endif()
289 set(CLDNN__ARCHITECTURE_TARGET "${__CLDNN_Arch_Target}")
290 unset(__CLDNN_Arch_Target)
291 unset(__CLDNN_DetectedArchValid_Target)
292
293 intel_arch_validate(__CLDNN_ArchValid_Target "${CLDNN__ARCHITECTURE_TARGET}")
294 if(NOT __CLDNN_ArchValid_Target)
295   message(FATAL_ERROR "[clDNN] CLDNN__ARCHITECTURE_TARGET: Target architecture \"${CLDNN__ARCHITECTURE_TARGET}\" is invalid.
296       Please specify correct one, e.g. Windows32, Linux64, Android32, Darwin32, ..."
297     )
298 endif()
299 unset(__CLDNN_ArchValid_Target)
300
301 # ======================================================================================================
302
303 # Detecting all versions of added Intel OpenCL SDK ICDs in the project.
304 if(NOT EXISTS "${CLDNN__IOCL_ICD_DIR}")
305   if(NOT CLDNN__IOCL_ICD_USE_EXTERNAL)
306     message(FATAL_ERROR "[clDNN] Root for ICDs for Intel OpenCL SDK is invalid or does not exist.
307       Please make sure that ICDs are added into \"${CLDNN__IOCL_ICD_DIR}\".")
308   endif()
309 endif()
310
311 cldnn_locate_component_versions(__CLDNN_IOclIcdVersions __CLDNN_IOclIcdPaths __CLDNN_IOclIcdDefaultVersion
312     "ICD for Intel OpenCL SDK" "${CLDNN__IOCL_ICD_DIR}"
313     "*/include/CL/opencl.h"
314   )
315
316 if(__CLDNN_IOclIcdDefaultVersion VERSION_EQUAL "0")
317   if(NOT CLDNN__IOCL_ICD_USE_EXTERNAL)
318     message(FATAL_ERROR "[clDNN] Intel OpenCL SDK ICD required for build cannot be located.")
319   endif()
320 endif()
321
322 # ======================================================================================================
323 # ============================================ CMAKE OPTIONS ===========================================
324 # ======================================================================================================
325
326 # Current build configuration (only for single-configuration generators).
327 set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "Current build configuration (only for single-configuration generators)." FORCE)
328 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
329
330 # ======================================================================================================
331
332 # Target architecture for compilation.
333 set(CLDNN__ARCHITECTURE_TARGET "${CLDNN__ARCHITECTURE_TARGET}" CACHE STRING "Target architecture for compilation." FORCE)
334 if(MSVC)
335   set_property(CACHE CLDNN__ARCHITECTURE_TARGET PROPERTY STRINGS "Windows32" "Windows64")
336 elseif(DEFINED XCODE_VERSION)
337   set_property(CACHE CLDNN__ARCHITECTURE_TARGET PROPERTY STRINGS "Darwin32" "Darwin64")
338 endif()
339
340 # ======================================================================================================
341 if(DEFINED CLDNN__OUTPUT_DIR)
342   set(CLDNN__OUTPUT_BIN_DIR "${CLDNN__OUTPUT_DIR}" CACHE PATH "Output directory path where the final exetuables, examples and tests will be stored.")
343   set(CLDNN__OUTPUT_LIB_DIR "${CLDNN__OUTPUT_DIR}" CACHE PATH "Output directory path where the final libraries will be stored.")
344 elseif(NOT DEFINED CLDNN__OUTPUT_BIN_DIR AND NOT DEFINED CLDNN__OUTPUT_LIB_DIR)
345   # Output directory path where the final libraries, examples and tests will be stored.
346   if(CLDNN__MULTI_CFG_GEN)
347     # Multi-configuration generators automatically append build type subdirectory.
348     set(__CLDNN_OutDir "${CLDNN_BUILD__DEFAULT_OUT_ROOT}/${CLDNN__ARCHITECTURE_TARGET}")
349   else()
350     set(__CLDNN_OutDir "${CLDNN_BUILD__DEFAULT_OUT_ROOT}/${CLDNN__ARCHITECTURE_TARGET}/${CMAKE_BUILD_TYPE}")
351   endif()
352   set(CLDNN__OUTPUT_BIN_DIR "${__CLDNN_OutDir}" CACHE PATH "Output directory path where the final exetuables, examples and tests will be stored.")
353   set(CLDNN__OUTPUT_LIB_DIR "${CLDNN__OUTPUT_BIN_DIR}" CACHE PATH "Output directory path where the final libraries will be stored.")
354   unset(__CLDNN_OutDir)
355 endif()
356 # ======================================================================================================
357
358 # Intel OpenCL SDK ICD: Version of ICD used to build clDNN.
359 set(CLDNN__IOCL_ICD_VERSION "${__CLDNN_IOclIcdDefaultVersion}" CACHE STRING "Intel OpenCL SDK ICD: Version of ICD used to build clDNN framework.")
360 mark_as_advanced(CLDNN__IOCL_ICD_VERSION)
361 set_property(CACHE CLDNN__IOCL_ICD_VERSION PROPERTY STRINGS ${__CLDNN_IOclIcdVersions})
362
363 # ======================================================================================================
364
365 set(CLDNN__IOCL_ICD_USE_EXTERNAL OFF CACHE BOOL "Intel OpenCL SDK ICD: Try to use externally-intalled Intel OpenCL SDK ICD.")
366 mark_as_advanced(CLDNN__IOCL_ICD_USE_EXTERNAL)
367
368 # ======================================================================================================
369
370 # Include and build: Core of clDNN framework.
371 set(CLDNN__INCLUDE_CORE ON CACHE BOOL "Include and build: clDNN core.")
372 mark_as_advanced(CLDNN__INCLUDE_CORE)
373
374 # ======================================================================================================
375
376 # Include and build: Kernel selector for clDNN framework.
377 set(CLDNN__INCLUDE_KERNEL_SELECTOR ON CACHE BOOL "Include and build: clDNN kernel selector.")
378 mark_as_advanced(CLDNN__INCLUDE_KERNEL_SELECTOR)
379
380 # ======================================================================================================
381
382 # Include and build: Tests (unit tests and small acceptance tests) for clDNN framework.
383 set(CLDNN__INCLUDE_TESTS ON CACHE BOOL "Include and build: clDNN framework's tests.")
384 mark_as_advanced(CLDNN__INCLUDE_TESTS)
385
386 # ======================================================================================================
387
388 # Include and build: Core Internal Tests (unit tests and small acceptance tests) for core internal clDNN framework mechanisms.
389 set(CLDNN__INCLUDE_CORE_INTERNAL_TESTS ON CACHE BOOL "Include and build: clDNN framework's core internal tests.")
390 mark_as_advanced(CLDNN__INCLUDE_CORE_INTERNAL_TESTS)
391
392 # ======================================================================================================
393
394
395 # Include and build: clDNN tutorial.
396 set(CLDNN__INCLUDE_TUTORIAL ON CACHE BOOL "Include and build: clDNN Tutorial.")
397 mark_as_advanced(CLDNN__INCLUDE_TUTORIAL)
398
399 # ======================================================================================================
400
401 # Run (requires CLDNN__INCLUDE_TESTS to be true): Tests (unit tests and small acceptance tests) for clDNN framework.
402 set(CLDNN__RUN_TESTS OFF CACHE BOOL "Run: clDNN framework's tests.")
403 mark_as_advanced(CLDNN__RUN_TESTS)
404
405 # ======================================================================================================
406
407 # Run (requires CLDNN__INCLUDE_CORE_INTERNAL_TESTS to be true): Tests (unit tests and small acceptance core internal tests) for clDNN framework.
408 set(CLDNN__RUN_CORE_INTERNAL_TESTS OFF CACHE BOOL "Run: clDNN framework's core internal tests.")
409 mark_as_advanced(CLDNN__RUN_CORE_INTERNAL_TESTS)
410
411 # ======================================================================================================
412
413 # Compile / Link: Use static C++ Runtime library.
414 set(CLDNN__COMPILE_LINK_USE_STATIC_RUNTIME OFF CACHE BOOL "Compile / Link: Use static version of C++ Runtime library instead of shared one.")
415 mark_as_advanced(CLDNN__COMPILE_LINK_USE_STATIC_RUNTIME)
416
417 # ======================================================================================================
418
419 # Compile / Link: Allow unsafe binary size optimizations.
420 set(CLDNN__COMPILE_LINK_ALLOW_UNSAFE_SIZE_OPT ON CACHE BOOL "Compile / Link: Allow unsafe binary size optimizations.")
421 mark_as_advanced(CLDNN__COMPILE_LINK_ALLOW_UNSAFE_SIZE_OPT)
422
423 # ======================================================================================================
424
425 # CMake: Enables debug trace messages in adapter project.
426 set(CLDNN__CMAKE_DEBUG OFF CACHE BOOL "CMake: Enables debug trace messages in clDNN project.")
427 mark_as_advanced(CLDNN__CMAKE_DEBUG)
428
429 # ======================================================================================================
430 # ======================================================================================================
431
432 # Minimum versions of compilers.
433 set(CLDNN__MIN_COMPILER_VERSION__MSVC  "19.0")
434 set(CLDNN__MIN_COMPILER_VERSION__CLANG "3.5")
435 set(CLDNN__MIN_COMPILER_VERSION__ICC   "17.0")
436 set(CLDNN__MIN_COMPILER_VERSION__GCC   "4.8")
437
438 # ======================================================================================================
439
440 # Checking whether tests can be run.
441 if((NOT CLDNN__INCLUDE_TESTS) AND CLDNN__RUN_TESTS)
442   message(WARNING "[clDNN] CLDNN__RUN_TESTS: Selected running of tests, but test are not built. Option will be disabled.")
443   set(CLDNN__RUN_TESTS OFF)
444 endif()
445
446 # ======================================================================================================
447
448 # Checking whether tests can be run.
449 if((NOT CLDNN__INCLUDE_CORE_INTERNAL_TESTS) AND CLDNN__RUN_CORE_INTERNAL_TESTS)
450   message(WARNING "[clDNN] CLDNN__INCLUDE_CORE_INTERNAL_TESTS: Selected running of core internal tests, but test are not built. Option will be disabled.")
451   set(CLDNN__RUN_CORE_INTERNAL_TESTS OFF)
452 endif()
453
454 # ======================================================================================================
455
456 # Check for python 2.7 interpreter (required tool).
457 find_package(PythonInterp 2.7)
458 if(NOT PYTHONINTERP_FOUND)
459   message(WARNING "[clDNN] Project requires Python 2.7 interpreter to build (with python loader). CMake could not detect it correctly.
460       If you have installed this interpreter, please disregard this warning or specify PYTHON_EXECUTABLE in CMake command-line."
461     )
462 endif()
463
464 # ======================================================================================================
465
466 # Setting helper variables for component paths.
467 intel_arch_get_os(__CLDNN_TargetOs "${CLDNN__ARCHITECTURE_TARGET}")
468 string(TOLOWER "${__CLDNN_TargetOs}" __CLDNN_TargetOs)
469
470 intel_arch_get_cpu(__CLDNN_TargetCpu "${CLDNN__ARCHITECTURE_TARGET}")
471 string(TOLOWER "${__CLDNN_TargetCpu}" __CLDNN_TargetCpu)
472
473 if(__CLDNN_TargetCpu STREQUAL "32")
474   set(__CLDNN_TargetCpuDir "x86")
475 elseif(__CLDNN_TargetCpu STREQUAL "64")
476   set(__CLDNN_TargetCpuDir "x64")
477 else()
478   set(__CLDNN_TargetCpuDir "${__CLDNN_TargetCpu}")
479 endif()
480
481 if((CMAKE_C_COMPILER_ID MATCHES "^Clang$") OR (CMAKE_CXX_COMPILER_ID MATCHES "^Clang$"))
482   set(__CLDNN_TargetCompilerDir "clang")
483 else()
484   set(__CLDNN_TargetCompilerDir ".")
485 endif()
486
487 # ======================================================================================================
488
489 # Selecting Intel OpenCL SDK version and path.
490 if (CLDNN__IOCL_ICD_USE_EXTERNAL)
491   if(NOT DEFINED ENV{INTELOCLSDKROOT})
492     message(FATAL_ERROR "[clDNN] CLDNN__IOCL_ICD_USE_EXTERNAL: Usage of external Intel OpenCL SDK ICD was selected, but the INTELOCLSDKROOT environment variable cannot be found.
493       Make sure that SDK is installed on the host.")
494   endif()
495   if(NOT EXISTS "$ENV{INTELOCLSDKROOT}/include/CL/opencl.h")
496     message(FATAL_ERROR "[clDNN] CLDNN__IOCL_ICD_USE_EXTERNAL: Usage of external Intel OpenCL SDK ICD was selected, but the INTELOCLSDKROOT environment variable points to invalid directory.
497       Make sure that SDK is installed on the host.")
498   endif()
499   set(CLDNN__IOCL_ICD_ROOT "$ENV{INTELOCLSDKROOT}")
500 else()
501   list(FIND __CLDNN_IOclIcdVersions "${CLDNN__IOCL_ICD_VERSION}" __CLDNN_IOclIcdVersionIdx)
502   if(__CLDNN_IOclIcdVersionIdx LESS 0)
503     message(FATAL_ERROR "[clDNN] CLDNN__IOCL_ICD_VERSION: Selected version of Intel OpenCL SDK ICD cannot be found.
504       Please use one of following values: ${__CLDNN_IOclIcdVersions}.")
505   endif()
506   list(GET __CLDNN_IOclIcdPaths ${__CLDNN_IOclIcdVersionIdx} CLDNN__IOCL_ICD_ROOT)
507 endif()
508
509 set(CLDNN__IOCL_ICD_ROOT "${CLDNN__IOCL_ICD_ROOT}" CACHE INTERNAL "Path to Intel OpenCL SDK ICD used to build clDNN framework.")
510
511 # Select SDK subdirectories with headers, binaries and libraries (based on architecture, cpu, generator and SDK type).
512 if(CLDNN__IOCL_ICD_USE_EXTERNAL)
513   set(CLDNN__IOCL_ICD_INCDIRS "${CLDNN__IOCL_ICD_ROOT}/include" CACHE INTERNAL "Paths to interface headers for Intel OpenCL SDK ICD.")
514   set(CLDNN__IOCL_ICD_STLDIRS "${CLDNN__IOCL_ICD_ROOT}/lib/${__CLDNN_TargetCpuDir}" CACHE INTERNAL "Paths to static libraries for Intel OpenCL SDK ICD.")
515
516   set(__CLDNN_FindLibSuffixes ${CMAKE_FIND_LIBRARY_SUFFIXES})
517   set(CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_SHARED_LIBRARY_SUFFIX}")
518   find_library(CLDNN_FIND__IOCL_ICD_SHLPATH
519     NAMES OpenCL
520     PATHS "${CLDNN__IOCL_ICD_ROOT}"
521           "${CLDNN__IOCL_ICD_ROOT}/bin"
522           "${CLDNN__IOCL_ICD_ROOT}/bin/${__CLDNN_TargetCpuDir}"
523           "${CLDNN__IOCL_ICD_ROOT}/lib"
524           "${CLDNN__IOCL_ICD_ROOT}/lib/${__CLDNN_TargetCpuDir}"
525     NO_CMAKE_FIND_ROOT_PATH
526   )
527   set(CMAKE_FIND_LIBRARY_SUFFIXES ${__CLDNN_FindLibSuffixes})
528
529   if(CLDNN_FIND__IOCL_ICD_SHLPATH)
530     get_filename_component(__CLDNN_IOclIcdSharedLibDir "${CLDNN_FIND__IOCL_ICD_SHLPATH}" DIRECTORY)
531     set(CLDNN__IOCL_ICD_SHLDIRS "${__CLDNN_IOclIcdSharedLibDir}" CACHE INTERNAL "Paths to shared libraries for Intel OpenCL SDK ICD.")
532   else()
533     message(FATAL_ERROR "[clDNN] CLDNN__IOCL_ICD_USE_EXTERNAL: Usage of external Intel OpenCL SDK ICD was selected, but the ICD shared library cannot be located.
534       Make sure that SDK is installed on the host.")
535   endif()
536
537   unset(CLDNN_FIND__IOCL_ICD_SHLPATH CACHE)
538   unset(__CLDNN_FindLibSuffixes)
539   unset(__CLDNN_IOclIcdSharedLibDir)
540 else()
541   set(CLDNN__IOCL_ICD_INCDIRS "${CLDNN__IOCL_ICD_ROOT}/${__CLDNN_TargetOs}/include" CACHE INTERNAL "Paths to interface headers for Intel OpenCL SDK ICD.")
542   set(CLDNN__IOCL_ICD_STLDIRS "${CLDNN__IOCL_ICD_ROOT}/${__CLDNN_TargetOs}/${CLDNN__TARGET_CFG_VAR}/lib/${__CLDNN_TargetCpuDir}" CACHE INTERNAL "Paths to static libraries for Intel OpenCL SDK ICD.")
543   set(CLDNN__IOCL_ICD_SHLDIRS "${CLDNN__IOCL_ICD_ROOT}/${__CLDNN_TargetOs}/${CLDNN__TARGET_CFG_VAR}/bin/${__CLDNN_TargetCpuDir}" CACHE INTERNAL "Paths to shared libraries for Intel OpenCL SDK ICD.")
544 endif()
545
546 # Select link directory based on targeted OS.
547 # - on Windows: static libraries directory.
548 # - on others:  shared libraries directory.
549 if(__CLDNN_TargetOs MATCHES "^windows$")
550   set(CLDNN__IOCL_ICD_LIBDIRS ${CLDNN__IOCL_ICD_STLDIRS} CACHE INTERNAL "Paths to libraries to link for Intel OpenCL SDK ICD.")
551 else()
552   set(CLDNN__IOCL_ICD_LIBDIRS ${CLDNN__IOCL_ICD_SHLDIRS} CACHE INTERNAL "Paths to libraries to link for Intel OpenCL SDK ICD.")
553 endif()
554
555 unset(__CLDNN_IOclIcdVersions)
556 unset(__CLDNN_IOclIcdPaths)
557 unset(__CLDNN_IOclIcdDefaultVersion)
558 unset(__CLDNN_IOclIcdVersionIdx)
559
560
561 # ======================================================================================================
562 set(CLDNN_UTILS__RAPIDJSON_INCDIRS "utils/rapidjson" CACHE INTERNAL "Paths to interface headers for rapidjson.")
563 # ====================================== Version Calculation ===========================================
564
565 if(EXISTS "${CLDNN__VERSION_FILE_NAME}")
566   file(READ "${CLDNN__VERSION_FILE_NAME}" __CLDNN_VersionFileContent)
567
568   # Extracting JSON object with version.
569   set(__CLDNN_VersionJsonObject "")
570   if("${__CLDNN_VersionFileContent}" MATCHES "\\\"version\\\"[ \t\n\r]*:[ \t\n\r]*\\{[ \t\n\r]*(.*)[ \t\n\r]*\\}")
571     set(__CLDNN_VersionJsonObject "${CMAKE_MATCH_1}")
572   endif()
573
574   # Extracting field values.
575   set(__CLDNN_VersionJsonMajor   "0")
576   set(__CLDNN_VersionJsonMinor   "-1")
577   set(__CLDNN_VersionJsonBuild   "-1")
578   set(__CLDNN_VersionJsonRevBase "0")
579   set(__CLDNN_VersionJsonRevMin  "-1")
580   if("${__CLDNN_VersionJsonObject}" MATCHES "\\\"major\\\"[ \t\n\r]*:[ \t\n\r]*([-+]?[0-9]+)[ \t\n\r#,}]")
581     set(__CLDNN_VersionJsonMajor "${CMAKE_MATCH_1}")
582   endif()
583   if("${__CLDNN_VersionJsonObject}" MATCHES "\\\"minor\\\"[ \t\n\r]*:[ \t\n\r]*([-+]?[0-9]+)[ \t\n\r#,}]")
584     set(__CLDNN_VersionJsonMinor "${CMAKE_MATCH_1}")
585   endif()
586   if("${__CLDNN_VersionJsonObject}" MATCHES "\\\"build\\\"[ \t\n\r]*:[ \t\n\r]*([-+]?[0-9]+)[ \t\n\r#,}]")
587     set(__CLDNN_VersionJsonBuild "${CMAKE_MATCH_1}")
588   endif()
589   if("${__CLDNN_VersionJsonObject}" MATCHES "\\\"revision_base\\\"[ \t\n\r]*:[ \t\n\r]*([-+]?[0-9]+)[ \t\n\r#,}]")
590     set(__CLDNN_VersionJsonRevBase "${CMAKE_MATCH_1}")
591   endif()
592   if("${__CLDNN_VersionJsonObject}" MATCHES "\\\"revision_min\\\"[ \t\n\r]*:[ \t\n\r]*([-+]?[0-9]+)[ \t\n\r#,}]")
593     set(__CLDNN_VersionJsonRevMin "${CMAKE_MATCH_1}")
594   endif()
595
596   # Fetching revision identifier (first from env. variable, next from CMake variable).
597   if(DEFINED "ENV{CLDNN__REV_ID}")
598     set(__CLDNN_VersionRevId "$ENV{CLDNN__REV_ID}")
599   elseif(DEFINED CLDNN__REV_ID)
600     set(__CLDNN_VersionRevId "${CLDNN__REV_ID}")
601   else()
602     set(__CLDNN_VersionRevId "0")
603   endif()
604
605   # Calculating version components (WA for lack of support for unary operators in CMake math()).
606   math(EXPR CLDNN__VERSION_MAJOR    "(0${__CLDNN_VersionJsonMajor})")
607   math(EXPR CLDNN__VERSION_MINOR    "(0${__CLDNN_VersionJsonMinor})")
608   math(EXPR CLDNN__VERSION_BUILD    "(0${__CLDNN_VersionJsonBuild})")
609   math(EXPR CLDNN__VERSION_REVISION "(0${__CLDNN_VersionRevId})-(0${__CLDNN_VersionJsonRevBase})")
610   math(EXPR __CLDNN_VersionJsonRevMin "(0${__CLDNN_VersionJsonRevMin})")
611   if("${CLDNN__VERSION_REVISION}" LESS "${__CLDNN_VersionJsonRevMin}")
612     set(CLDNN__VERSION_REVISION "${__CLDNN_VersionJsonRevMin}")
613   endif()
614
615   unset(__CLDNN_VersionFileContent)
616   unset(__CLDNN_VersionJsonObject)
617   unset(__CLDNN_VersionJsonMajor)
618   unset(__CLDNN_VersionJsonMinor)
619   unset(__CLDNN_VersionJsonBuild)
620   unset(__CLDNN_VersionJsonRevBase)
621   unset(__CLDNN_VersionJsonRevMin)
622 else()
623   set(CLDNN__VERSION_MAJOR    "0")
624   set(CLDNN__VERSION_MINOR    "-1")
625   set(CLDNN__VERSION_BUILD    "-1")
626   set(CLDNN__VERSION_REVISION "-1")
627 endif()
628
629 # ============================================= Status =================================================
630
631 # Display status.
632 message(STATUS "[clDNN] ======================== ${CLDNN__PROJ_NAME} Project =======================")
633 message(STATUS "[clDNN] Version:          ${CLDNN__VERSION_MAJOR}.${CLDNN__VERSION_MINOR}.${CLDNN__VERSION_BUILD}.${CLDNN__VERSION_REVISION}")
634 message(STATUS "[clDNN]")
635 message(STATUS "[clDNN] Build type:       ${CMAKE_BUILD_TYPE} (for single-configuration generators)")
636 message(STATUS "[clDNN] Av. build types:  ${CMAKE_CONFIGURATION_TYPES} (for multi-configuration generators)")
637 message(STATUS "[clDNN]")
638 message(STATUS "[clDNN] Output bin directory:")
639 message(STATUS "[clDNN]  - \"${CLDNN__OUTPUT_BIN_DIR}\"")
640 message(STATUS "[clDNN] Output lib directory:")
641 message(STATUS "[clDNN]  - \"${CLDNN__OUTPUT_LIB_DIR}\"")
642 message(STATUS "[clDNN] Architecture:")
643 message(STATUS "[clDNN]  - target: ${CLDNN__ARCHITECTURE_TARGET}    (detected: ${__CLDNN_DetectedArch_Target})")
644 message(STATUS "[clDNN]")
645 message(STATUS "[clDNN]")
646 message(STATUS "[clDNN] Advanced:")
647 if (CLDNN__IOCL_ICD_USE_EXTERNAL)
648   message(STATUS "[clDNN]  - ICD version used to build:         N/A (installed externally)")
649 else()
650   message(STATUS "[clDNN]  - ICD version used to build:         ${CLDNN__IOCL_ICD_VERSION}")
651 endif()
652 message(STATUS "[clDNN]")
653 message(STATUS "[clDNN]  - Include/Build cldnn core:          ${CLDNN__INCLUDE_CORE}")
654 message(STATUS "[clDNN]  - Include/Build kernel selector:     ${CLDNN__INCLUDE_KERNEL_SELECTOR}")
655 message(STATUS "[clDNN]  - Include/Build tests:               ${CLDNN__INCLUDE_TESTS}")
656 message(STATUS "[clDNN]  - Include/Build core internal tests: ${CLDNN__INCLUDE_CORE_INTERNAL_TESTS}")
657 message(STATUS "[clDNN]  - Include/Build tutorial:            ${CLDNN__INCLUDE_TUTORIAL}")
658 message(STATUS "[clDNN]")
659 message(STATUS "[clDNN]  - Run tests:                     ${CLDNN__RUN_TESTS}")
660 message(STATUS "[clDNN]  - Run core internal tests:       ${CLDNN__RUN_CORE_INTERNAL_TESTS}")
661 message(STATUS "[clDNN]")
662 message(STATUS "[clDNN]  - Use static C++ Runtime:        ${CLDNN__COMPILE_LINK_USE_STATIC_RUNTIME}")
663 message(STATUS "[clDNN]  - Allow unsafe size opts:        ${CLDNN__COMPILE_LINK_ALLOW_UNSAFE_SIZE_OPT}")
664 message(STATUS "[clDNN]  - CMake debug trace:             ${CLDNN__CMAKE_DEBUG}")
665 message(STATUS "[clDNN]")
666 message(STATUS "[clDNN]")
667 message(STATUS "[clDNN] ICD:")
668 message(STATUS "[clDNN]  - Root:            ${CLDNN__IOCL_ICD_ROOT}")
669 message(STATUS "[clDNN]     + Headers:      ${CLDNN__IOCL_ICD_INCDIRS}")
670 message(STATUS "[clDNN]     + Static libs:  ${CLDNN__IOCL_ICD_STLDIRS}")
671 message(STATUS "[clDNN]     + Shared libs:  ${CLDNN__IOCL_ICD_SHLDIRS}")
672 message(STATUS "[clDNN]     + Libs to link: ${CLDNN__IOCL_ICD_LIBDIRS}")
673 message(STATUS "[clDNN] =============================================================================")
674 unset(__CLDNN_DetectedArch_Target)
675
676
677 # ======================================================================================================
678 # ==================================== COMMON BUILD CONFIGURATION ======================================
679 # ======================================================================================================
680
681 # =================================== Main targets names and labels ====================================
682
683 set(CLDNN_BUILD__PROJ__clDNN       "${CLDNN_BUILD__PROJ_NAME_PREFIX}clDNN_shlib")
684 set(CLDNN_BUILD__PROJ_LABEL__clDNN "clDNN")
685
686 # ================================================ Outputs =============================================
687
688 # Old.
689 set(EXECUTABLE_OUTPUT_PATH "${CLDNN__OUTPUT_BIN_DIR}")
690 set(LIBRARY_OUTPUT_PATH    "${CLDNN__OUTPUT_LIB_DIR}")
691 # New.
692 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CLDNN__OUTPUT_LIB_DIR}")
693 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CLDNN__OUTPUT_LIB_DIR}")
694 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CLDNN__OUTPUT_BIN_DIR}")
695
696
697 # Main targets' output names.
698 intel_arch_get_cpu(CLDNN__OUT_CPU_SUFFIX "${CLDNN__ARCHITECTURE_TARGET}")
699
700 set(CLDNN_BUILD__PROJ_OUTPUT_NAME__clDNN "clDNN${CLDNN__OUT_CPU_SUFFIX}")
701
702
703 # RPATH for executables (Linux, Android, Mac)
704 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
705
706 intel_arch_get_os(__CLDNN_TargetOs "${CLDNN__ARCHITECTURE_TARGET}")
707 if(__CLDNN_TargetOs MATCHES "^Darwin$")
708   set(CMAKE_INSTALL_RPATH "@executable_path")
709 else()
710   set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
711 endif()
712 unset(__CLDNN_TargetOs)
713
714 # ======================================================================================================
715
716 cldnn_dmsg("${CLDNN__PROJ_NAME} Settings:")
717 cldnn_dmsg(" - project file name: ${CLDNN_BUILD__PROJ__clDNN}")
718 cldnn_dmsg(" - project label:     ${CLDNN_BUILD__PROJ_LABEL__clDNN}")
719 cldnn_dmsg(" - library name:      ${CLDNN_BUILD__PROJ_OUTPUT_NAME__clDNN}")
720 cldnn_dmsg(" - used generator:    ${CMAKE_GENERATOR}")
721 cldnn_dmsg("    + platform:       ${CMAKE_GENERATOR_PLATFORM}")
722 cldnn_dmsg("    + toolset:        ${CMAKE_GENERATOR_TOOLSET}")
723 cldnn_dmsg(" - crosscompiling:    ${CMAKE_CROSSCOMPILING}")
724 if(CMAKE_CROSSCOMPILING)
725   cldnn_dmsg("    + toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
726 endif()
727 cldnn_dmsg(" - compiler (C++):    ${CMAKE_CXX_COMPILER_ID}")
728 cldnn_dmsg("    + version:        ${CMAKE_CXX_COMPILER_VERSION}")
729 cldnn_dmsg(" - compiler (C):      ${CMAKE_C_COMPILER_ID}")
730 cldnn_dmsg("    + version:        ${CMAKE_C_COMPILER_VERSION}")
731
732 # ============================== Abstraction of compiler and linker options ============================
733
734 include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeCompilerLinkerOpts.txt" NO_POLICY_SCOPE)
735
736 # ======================================= Generic compiler options =====================================
737 # Selecting C++ Runtime.
738 if(CLDNN__COMPILE_LINK_USE_STATIC_RUNTIME)
739   set(__CLDNN_RtType      "RtMultiThreadedStatic")
740   set(__CLDNN_RtTypeDebug "RtMultiThreadedStaticDebug")
741 else()
742   set(__CLDNN_RtType      "RtMultiThreadedShared")
743   set(__CLDNN_RtTypeDebug "RtMultiThreadedSharedDebug")
744 endif()
745
746 foreach(__CLDNN_CompilerFlagName IN ITEMS "CMAKE_CXX_FLAGS" "CMAKE_C_FLAGS")
747   # Change some generic settings of compiler.
748   # NOTE: Debug info generation is enabled for all build configuration, because it is separate on Windows
749   #       and we will use "strip" command on Linux and Android (to separate it).
750   intel_config_flag_apply_settings(
751       CompilerOptions
752       "${__CLDNN_CompilerFlagName}"
753       ALL_PATTERN ""
754       SET
755         CompileAsDefault
756         ExceptionsEnabled
757         MultiProcessorCompilation
758         DeadCodeEliminate
759         ExtensionsEnabled
760         TreatWarnAsErrorEnabled
761         WarnLevel4
762         NoFastMath
763         StackProtector
764     )
765   intel_config_flag_apply_settings(
766       CompilerOptions
767       "${__CLDNN_CompilerFlagName}"
768       ALL_PATTERN_NOINHERIT ""
769       SET
770         OptimizeSize
771         "${__CLDNN_RtType}"
772     )
773   intel_config_flag_apply_settings(
774       CompilerOptions
775       "${__CLDNN_CompilerFlagName}"
776       PATTERN "^Debug"
777       SET
778         OptimizeDisabled
779         "${__CLDNN_RtTypeDebug}"
780     )
781
782   # Adding needed settings specific to MSVC.
783   if(MSVC)
784     if(CMAKE_COMPILER_IS_INTEL)
785       intel_config_flag_apply_settings(
786           CompilerOptions
787           "${__CLDNN_CompilerFlagName}"
788           ALL_PATTERN ""
789           SET_RAW
790             "/wd177"
791             "/wd367"
792             "/wd411"
793             "/wd2415"
794             "/wd3280"
795             "/wd3346"
796             "/wd11074"
797             "/wd11076"
798         )
799     else()
800       if(__CLDNN_TargetCpu STREQUAL "32")
801         intel_config_flag_apply_settings(
802             CompilerOptions
803             "${__CLDNN_CompilerFlagName}"
804             ALL_PATTERN ""
805             SET_RAW
806             "/arch:SSE2"
807             "/sdl"
808         )
809       else()
810         intel_config_flag_apply_settings(
811                 CompilerOptions
812                 "${__CLDNN_CompilerFlagName}"
813                 ALL_PATTERN ""
814                 SET_RAW
815                 "/sdl"
816             )
817       endif()
818     endif()
819   elseif(CMAKE_COMPILER_IS_INTEL)
820     message(FATAL_ERROR "TODO Support native ICC")
821   # Adding needed settings specific to GCC.
822   # NOTE: Following options can be needed in the future (although some not recommended: NR):
823   # [NR] -fno-short-enums
824   # [NR] -fno-tree-pre
825   #      -fno-omit-frame-pointer
826   #      -Wa,--noexecstack
827   #      -fkeep-inline-functions
828   elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
829     intel_config_flag_apply_settings(
830         CompilerOptions
831         "${__CLDNN_CompilerFlagName}"
832         ALL_PATTERN ""
833         SET_RAW
834           -pipe
835           -fmessage-length=0
836           -fno-strict-aliasing
837           -W
838           -Wno-unknown-pragmas
839           -Wwrite-strings
840           -Wswitch
841           -Wformat
842           -Wformat-security
843           -Wno-error=missing-field-initializers
844           -Wno-error=unused-parameter
845           -Wno-error=unused-function
846           -march=corei7
847           -mstackrealign
848           -msse
849           -msse2
850           -msse3
851           -mssse3
852           -msse4
853           -msse4.1
854           -msse4.2
855           -fvisibility=hidden
856           -finline
857           -finline-functions
858           -finline-limit=300
859           -funswitch-loops
860           -fPIE
861           -fPIC
862           -Wl,--no-undefined
863       )
864   elseif((CMAKE_C_COMPILER_ID MATCHES "^Clang$") OR (CMAKE_CXX_COMPILER_ID MATCHES "^Clang$"))
865     intel_config_flag_apply_settings(
866         CompilerOptions
867         "${__CLDNN_CompilerFlagName}"
868         ALL_PATTERN ""
869         SET_RAW
870           -pipe
871           -fvisibility=hidden
872           -fvisibility-inlines-hidden
873           -Wall
874           -Wno-covered-switch-default
875           -Wextra
876           -Wno-unused-parameter
877           -Wno-gnu
878           -pedantic
879           -finline
880           -msse4.2
881           -fPIE
882           -fPIC
883       )
884   endif()
885 endforeach()
886
887 # C++ only options.
888 intel_config_flag_apply_settings(
889     CompilerOptions
890     CMAKE_CXX_FLAGS
891     ALL_PATTERN ""
892     SET
893       RttiDisabled
894       StandardCxx11
895   )
896
897 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
898   intel_config_flag_apply_settings(
899       CompilerOptions
900       CMAKE_CXX_FLAGS
901       ALL_PATTERN ""
902       SET_RAW
903         -fno-operator-names
904         -fpermissive
905         -fvisibility-inlines-hidden
906     )
907 endif()
908
909 # NOTE: When compiling with Clang, use the flags below for C++ files. These flags cannot be enabled when compiling
910 #       C files.
911 if((CMAKE_C_COMPILER_ID MATCHES "^Clang$") OR (CMAKE_CXX_COMPILER_ID MATCHES "^Clang$"))
912   intel_config_flag_apply_settings(
913       CompilerOptions
914       CMAKE_CXX_FLAGS
915       ALL_PATTERN ""
916       SET_RAW
917         -stdlib=libc++
918     )
919 endif()
920
921 unset(__CLDNN_RtType)
922 unset(__CLDNN_RtTypeDebug)
923 unset(__CLDNN_CompilerFlagName)
924
925 # ======================================== Generic linker options ======================================
926
927 # Additional libraries that needs to be linked to shared objects/executables.
928 set(CLDNN__SYSTEM_LINK_LIBRARIES)
929
930 foreach(__CLDNN_LinkerFlagName IN ITEMS "CMAKE_EXE_LINKER_FLAGS" "CMAKE_SHARED_LINKER_FLAGS")
931   # Change some generic settings of linker.
932   # NOTE: Debug info generation is enabled for all build configuration, because it is separate on Windows
933   #       and we will use "strip" command on Linux and Android (to separate it).
934   intel_config_flag_apply_settings(
935       LinkerOptions
936       "${__CLDNN_LinkerFlagName}"
937       ALL_PATTERN ""
938       SET
939         DeadCodeEliminate
940         IdenticalCodeDataFold
941         IncrementalDisabled
942     )
943 endforeach()
944
945 # Force static linking of common libraries on Android for shared objects.
946 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
947   intel_config_flag_apply_settings(
948         LinkerOptions
949         CMAKE_EXE_LINKER_FLAGS
950         ALL_PATTERN ""
951         SET_RAW
952           -pie
953           -Wl,-z,noexecstack,-z,relro,-z,now
954       )
955   intel_config_flag_apply_settings(
956         LinkerOptions
957         CMAKE_SHARED_LINKER_FLAGS
958         ALL_PATTERN ""
959         SET_RAW
960           -Wl,-z,noexecstack,-z,relro,-z,now
961       )
962   list(APPEND CLDNN__SYSTEM_LINK_LIBRARIES "dl")
963 endif()
964
965 if((CMAKE_C_COMPILER_ID MATCHES "^Clang$") OR (CMAKE_CXX_COMPILER_ID MATCHES "^Clang$"))
966   intel_config_flag_apply_settings(
967       LinkerOptions
968       CMAKE_SHARED_LINKER_FLAGS
969       ALL_PATTERN ""
970       SET_RAW
971         -shared
972         -Wl,-undefined,dynamic_lookup
973         -Wl,-headerpad_max_install_names
974     )
975
976   list(APPEND CLDNN__SYSTEM_LINK_LIBRARIES "c++" "c++abi" "supc++" "dl")
977 endif()
978
979 unset(__CLDNN_LinkerFlagName)
980
981 # ======================================================================================================
982
983 cldnn_dmsg(" - compile/link flags:")
984 foreach(__CLDNN_Flag IN ITEMS "CMAKE_CXX_FLAGS" "CMAKE_C_FLAGS" "CMAKE_EXE_LINKER_FLAGS" "CMAKE_SHARED_LINKER_FLAGS")
985   cldnn_dmsg("    + ${__CLDNN_Flag}:     ${${__CLDNN_Flag}}")
986   foreach(__CLDNN_CfgType ${CMAKE_CONFIGURATION_TYPES})
987     string(TOUPPER "${__CLDNN_Flag}_${__CLDNN_CfgType}" __CLDNN_CfgFlag)
988     if(DEFINED "${__CLDNN_CfgFlag}")
989       cldnn_dmsg("    + ${__CLDNN_CfgFlag}:     ${${__CLDNN_CfgFlag}}")
990     endif()
991   endforeach()
992   cldnn_dmsg("")
993 endforeach()
994 unset(__CLDNN_Flag)
995 unset(__CLDNN_CfgType)
996 unset(__CLDNN_CfgFlag)
997
998 # ======================================================================================================
999
1000 # Clean-up of helper variables for component paths.
1001 unset(__CLDNN_TargetOs)
1002 unset(__CLDNN_TargetCpu)
1003 unset(__CLDNN_TargetCpuDir)
1004 unset(__CLDNN_TargetCompilerDir)
1005
1006 # ============================== Generic compiler preprocessor definitions =============================
1007
1008 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
1009     CLDNN_CMAKE
1010   )
1011
1012 if (MSVC)
1013 #  set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
1014 #      _SCL_SECURE_NO_WARNINGS
1015 #    )
1016 elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
1017   set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
1018     _GLIBCXX_USE_CXX11_ABI=0
1019     $<$<CONFIG:Release>:_FORTIFY_SOURCE=2>
1020   )
1021 endif()
1022
1023 # ===================================== Include/Link directories =======================================
1024
1025 include_directories(
1026     ${CLDNN__IOCL_ICD_INCDIRS}
1027         ${CLDNN_UTILS__RAPIDJSON_INCDIRS}
1028     "${CLDNN__KHR_CLHPP_DIR}"
1029     "${CLDNN__CODEGEN_INCDIR}"
1030   )
1031 link_directories(
1032     ${CLDNN__IOCL_ICD_LIBDIRS}
1033   )
1034
1035 # =================================== Link targets and dependencies ====================================
1036 if(CLDNN__INCLUDE_CORE)
1037   add_subdirectory(src)
1038   add_subdirectory(api_test_builds)
1039 endif()
1040 if(CLDNN__INCLUDE_TESTS)
1041   add_subdirectory(tests)
1042 endif()
1043 if(CLDNN__INCLUDE_CORE_INTERNAL_TESTS)
1044   add_subdirectory(tests_core_internal)
1045 endif()
1046 if(CLDNN__INCLUDE_KERNEL_SELECTOR)
1047   add_subdirectory(kernel_selector)
1048 endif()
1049 if(CLDNN__INCLUDE_TUTORIAL)
1050   add_subdirectory(tutorial)
1051 endif()
1052
1053 add_subdirectory(docs)
1054
1055
1056 # ======================================================================================================
1057 # ======================================================================================================
1058 # ======================================================================================================