CMAKE: moved GNA var setting to proper place; removed find_package when build python...
[platform/upstream/dldt.git] / inference-engine / cmake / ie_parallel.cmake
1 # Copyright (C) 2018-2019 Intel Corporation
2 # SPDX-License-Identifier: Apache-2.0
3 #
4
5 function(set_ie_threading_interface_for TARGET_NAME)
6     function(ie_target_link_libraries TARGET_NAME)
7         get_target_property(target_type ${TARGET_NAME} TYPE)
8
9         if(NOT target_type STREQUAL "OBJECT_LIBRARY")
10             target_link_libraries(${TARGET_NAME} ${ARGN})
11         endif()
12     endfunction()
13
14     set(IE_THREAD_DEFINE "IE_THREAD_SEQ")
15
16     if (THREADING STREQUAL "TBB" OR THREADING STREQUAL "TBB_AUTO")
17         if (DEFINED ENV{TBBROOT})
18             # Check TBB package in case if custom TBBROOT path configured
19             find_package(TBB QUIET PATHS "$ENV{TBBROOT}/cmake")
20             if (TBB_FOUND)
21                 set(IE_THREAD_DEFINE "IE_THREAD_TBB")
22                 if (WIN32)
23                     ie_target_link_libraries(${TARGET_NAME} PUBLIC "-nodefaultlib:vcomp")
24                 endif ()
25                 ie_target_link_libraries(${TARGET_NAME} PUBLIC ${TBB_IMPORTED_TARGETS})
26             else ()
27                 # TBB was not found by the configured TBBROOT path, SEQ method will be used
28                 ext_message(WARNING "TBB not found by the configured TBBROOT path $ENV{TBBROOT}")
29             endif ()
30         else()
31             if (NOT (IE_MAIN_SOURCE_DIR))
32                 set(incl_path ${IE_EXTERNAL_DIR}/tbb/include)
33                 if (WIN32)
34                     set(lib_rel_path ${IE_LIB_REL_DIR})
35                     set(lib_dbg_path ${IE_LIB_DBG_DIR})
36                 else ()
37                     set(lib_rel_path ${IE_EXTERNAL_DIR}/tbb/lib)
38                     set(lib_dbg_path ${lib_rel_path})
39                 endif ()
40             else ()
41                 set(incl_path ${TBB}/include)
42                 set(lib_rel_path ${TBB}/lib)
43                 set(lib_dbg_path ${lib_rel_path})
44             endif ()
45
46             if (NOT TBB_INCLUDE_DIRS OR NOT TBB_LIBRARIES_RELEASE)
47                 find_path(TBB_INCLUDE_DIRS tbb/tbb.h ${incl_path} NO_DEFAULT_PATH)
48                 find_library(TBB_LIBRARIES_RELEASE tbb ${lib_rel_path} NO_DEFAULT_PATH)
49                 ext_message(STATUS "TBB include: ${TBB_INCLUDE_DIRS}")
50                 ext_message(STATUS "TBB Release lib: ${TBB_LIBRARIES_RELEASE}")
51                 if (NOT LINUX)
52                     find_library(TBB_LIBRARIES_DEBUG tbb_debug ${lib_dbg_path} NO_DEFAULT_PATH)
53                     if (TBB_LIBRARIES_DEBUG)
54                         ext_message(STATUS "TBB Debug lib: ${TBB_LIBRARIES_DEBUG}")
55                     else ()
56                         ext_message(WARNING "TBB Debug binaries are missed.")
57                     endif ()
58                 endif ()
59             endif ()
60
61             if (NOT TBB_INCLUDE_DIRS OR NOT TBB_LIBRARIES_RELEASE)
62                 ext_message(WARNING "TBB not found. TBB support will be disabled. ${IE_THREAD_DEFINE} is defined")
63             else ()
64                 set(IE_THREAD_DEFINE "IE_THREAD_TBB")
65
66                 target_include_directories(${TARGET_NAME} PUBLIC ${TBB_INCLUDE_DIRS})
67                 if (WIN32)
68                     ie_target_link_libraries(${TARGET_NAME} PUBLIC "-nodefaultlib:vcomp")
69                 endif ()
70
71                 # Debug binaries are optional.
72                 if (TBB_LIBRARIES_DEBUG AND NOT LINUX)
73                     if (WIN32)
74                         ie_target_link_libraries(${TARGET_NAME} PUBLIC "$<$<CONFIG:DEBUG>:${TBB_LIBRARIES_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${TBB_LIBRARIES_RELEASE}>")
75                     else ()
76                         if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
77                             ie_target_link_libraries(${TARGET_NAME} PUBLIC ${TBB_LIBRARIES_DEBUG})
78                         else()
79                             ie_target_link_libraries(${TARGET_NAME} PUBLIC ${TBB_LIBRARIES_RELEASE})
80                         endif ()
81                     endif ()
82                 else ()
83                     # Link Release library to all configurations.
84                     ie_target_link_libraries(${TARGET_NAME} PUBLIC ${TBB_LIBRARIES_RELEASE})
85                 endif ()
86             endif ()
87         endif()
88     elseif (THREADING STREQUAL "OMP")
89         if (WIN32)
90             set(omp_lib_name libiomp5md)
91         else ()
92             set(omp_lib_name iomp5)
93         endif ()
94
95         if (NOT(IE_MAIN_SOURCE_DIR))
96             if (WIN32)
97                 set(lib_rel_path ${IE_LIB_REL_DIR})
98                 set(lib_dbg_path ${IE_LIB_DBG_DIR})
99             else ()
100                 set(lib_rel_path ${IE_EXTERNAL_DIR}/omp/lib)
101                 set(lib_dbg_path ${lib_rel_path})
102             endif ()
103         else ()
104             set(lib_rel_path ${OMP}/lib)
105             set(lib_dbg_path ${lib_rel_path})
106         endif ()
107
108         if (NOT OMP_LIBRARIES_RELEASE)
109             find_library(OMP_LIBRARIES_RELEASE ${omp_lib_name} ${lib_rel_path} NO_DEFAULT_PATH)
110             ext_message(STATUS "OMP Release lib: ${OMP_LIBRARIES_RELEASE}")
111             if (NOT LINUX)
112                 find_library(OMP_LIBRARIES_DEBUG ${omp_lib_name} ${lib_dbg_path} NO_DEFAULT_PATH)
113                 if (OMP_LIBRARIES_DEBUG)
114                     ext_message(STATUS "OMP Debug lib: ${OMP_LIBRARIES_DEBUG}")
115                 else ()
116                     ext_message(WARNING "OMP Debug binaries are missed.")
117                 endif ()
118             endif ()
119         endif ()
120
121         if (NOT OMP_LIBRARIES_RELEASE)
122             ext_message(WARNING "Intel OpenMP not found. Intel OpenMP support will be disabled. ${IE_THREAD_DEFINE} is defined")
123         else ()
124             set(IE_THREAD_DEFINE "IE_THREAD_OMP")
125
126             if (WIN32)
127                 target_compile_options(${TARGET_NAME} PUBLIC ${OpenMP_CXX_FLAGS} /openmp)
128                 target_compile_options(${TARGET_NAME} PUBLIC ${OpenMP_CXX_FLAGS} /Qopenmp)
129                 ie_target_link_libraries(${TARGET_NAME} PUBLIC "-nodefaultlib:vcomp")
130             else()
131                 target_compile_options(${TARGET_NAME} PUBLIC ${OpenMP_CXX_FLAGS} -fopenmp)
132             endif ()
133
134             # Debug binaries are optional.
135             if (OMP_LIBRARIES_DEBUG AND NOT LINUX)
136                 if (WIN32)
137                     ie_target_link_libraries(${TARGET_NAME} PUBLIC "$<$<CONFIG:DEBUG>:${OMP_LIBRARIES_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${OMP_LIBRARIES_RELEASE}>")
138                 else()
139                     if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
140                         ie_target_link_libraries(${TARGET_NAME} PUBLIC ${OMP_LIBRARIES_DEBUG})
141                     else()
142                         ie_target_link_libraries(${TARGET_NAME} PUBLIC ${OMP_LIBRARIES_RELEASE})
143                     endif ()
144                 endif ()
145             else ()
146                 # Link Release library to all configurations.
147                 ie_target_link_libraries(${TARGET_NAME} PUBLIC ${OMP_LIBRARIES_RELEASE})
148             endif ()
149         endif ()
150
151     endif ()
152
153     target_compile_definitions(${TARGET_NAME} PUBLIC -DIE_THREAD=${IE_THREAD_DEFINE})
154
155     if (NOT THREADING STREQUAL "SEQ")
156         find_package(Threads REQUIRED)
157         ie_target_link_libraries(${TARGET_NAME} PUBLIC ${CMAKE_THREAD_LIBS_INIT})
158     endif()
159 endfunction(set_ie_threading_interface_for)