1 #===============================================================================
2 # Copyright 2018 Intel Corporation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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 #===============================================================================
17 # Auxiliary build functions
18 #===============================================================================
20 if(utils_cmake_included)
23 set(utils_cmake_included true)
24 include("cmake/options.cmake")
26 # Common configuration for tests / test cases on Windows
27 function(maybe_configure_windows_test name kind)
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)
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)
50 # Append to a variable
52 macro(append var value)
53 set(${var} "${${var}} ${value}")
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}")
64 if(MKLDNN_PRODUCT_BUILD_MODE)
65 message(STATUS "This is a product build")
67 message(WARNING "This is a developer build")
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)
74 set(${var} "${val_if_true}")
76 set(${var} "${val_if_false}")
80 # Conditionally set a variable
81 # if (cond) var = value
82 macro(set_if condition var value)
84 set(${var} "${value}")
88 # Conditionally append
89 # if (cond) var = var + value
90 macro(append_if condition var value)
92 append(${var} "${value}")
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__)
101 "${${path_list}};${append_to_windows_path_list_tmp__}")
104 "${append_to_windows_path_list_tmp__}")
108 function(target_link_libraries_private target list)
109 # Foreach is required for compatibility with 2.8.11 ways
111 target_link_libraries(${target} LINK_PRIVATE
112 "$<BUILD_INTERFACE:${lib}>")
116 function(target_link_libraries_public target list)
117 # Foreach is required for compatibility with 2.8.11 ways
119 get_filename_component(base "${lib}" NAME)
120 target_link_libraries(${target} LINK_PUBLIC
121 "$<INSTALL_INTERFACE:${base}>")