Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / cmake / utils.cmake
1 #===============================================================================
2 # Copyright 2018 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #===============================================================================
16
17 # Auxiliary build functions
18 #===============================================================================
19
20 if(utils_cmake_included)
21     return()
22 endif()
23 set(utils_cmake_included true)
24 include("cmake/options.cmake")
25
26 # Common configuration for tests / test cases on Windows
27 function(maybe_configure_windows_test name kind)
28     if(WIN32 OR MINGW)
29         string(REPLACE  ";" "\;" PATH "${CTESTCONFIG_PATH};$ENV{PATH}")
30         set_property(${kind} ${name} PROPERTY ENVIRONMENT "PATH=${PATH}")
31         configure_file(${PROJECT_SOURCE_DIR}/cmake/template.vcxproj.user
32             ${name}.vcxproj.user @ONLY)
33     endif()
34 endfunction()
35
36 # Register new executable/test
37 #   name -- name of the executable
38 #   srcs -- list of source, if many must be enclosed with ""
39 #   test -- "test" to mark executable as a test, "" otherwise
40 #   arg4 -- (optional) list of extra library dependencies
41 function(register_exe name srcs test)
42     add_executable(${name} ${srcs})
43     target_link_libraries(${name} ${LIB_NAME} ${EXTRA_SHARED_LIBS} ${ARGV3})
44     if("${test}" STREQUAL "test")
45         add_test(${name} ${name})
46         maybe_configure_windows_test(${name} TEST)
47     endif()
48 endfunction()
49
50 # Append to a variable
51 #   var = var + value
52 macro(append var value)
53     set(${var} "${${var}} ${value}")
54 endmacro()
55
56 # Append to a variable if building a product build (as opposed to a developer
57 # build that is detected via the MKLDNN_PRODUCT_BUILD_MODE option)
58 macro(append_if_product var value)
59     if(MKLDNN_PRODUCT_BUILD_MODE)
60         append(${var} "${value}")
61     endif()
62 endmacro()
63
64 if(MKLDNN_PRODUCT_BUILD_MODE)
65     message(STATUS "This is a product build")
66 else()
67     message(WARNING "This is a developer build")
68 endif()
69
70 # Set variable depending on condition:
71 #   var = cond ? val_if_true : val_if_false
72 macro(set_ternary var condition val_if_true val_if_false)
73     if (${condition})
74         set(${var} "${val_if_true}")
75     else()
76         set(${var} "${val_if_false}")
77     endif()
78 endmacro()
79
80 # Conditionally set a variable
81 #   if (cond) var = value
82 macro(set_if condition var value)
83     if (${condition})
84         set(${var} "${value}")
85     endif()
86 endmacro()
87
88 # Conditionally append
89 #   if (cond) var = var + value
90 macro(append_if condition var value)
91     if (${condition})
92         append(${var} "${value}")
93     endif()
94 endmacro()
95
96 # Append a path to path_list variable (Windows-only version)
97 macro(append_to_windows_path_list path_list path)
98     file(TO_NATIVE_PATH "${path}" append_to_windows_path_list_tmp__)
99     if(${path_list})
100         set(${path_list}
101             "${${path_list}};${append_to_windows_path_list_tmp__}")
102     else()
103         set(${path_list}
104             "${append_to_windows_path_list_tmp__}")
105     endif()
106 endmacro()
107
108 function(target_link_libraries_private target list)
109     # Foreach is required for compatibility with 2.8.11 ways
110     foreach(lib ${list})
111         target_link_libraries(${target} LINK_PRIVATE
112             "$<BUILD_INTERFACE:${lib}>")
113     endforeach(lib)
114 endfunction()
115
116 function(target_link_libraries_public target list)
117     # Foreach is required for compatibility with 2.8.11 ways
118     foreach(lib ${list})
119         get_filename_component(base "${lib}" NAME)
120         target_link_libraries(${target} LINK_PUBLIC
121             "$<INSTALL_INTERFACE:${base}>")
122     endforeach(lib)
123 endfunction()