Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / cmake / debug.cmake
1 # Copyright (C) 2018-2019 Intel Corporation
2 #
3 # SPDX-License-Identifier: Apache-2.0
4 #
5
6 function (debug_message)
7     if (VERBOSE_BUILD)
8         message(${ARGV})
9     endif()
10 endfunction()
11
12
13 function(clean_message type)
14   string (REPLACE ";" "" output_string "${ARGN}")
15   execute_process(COMMAND ${CMAKE_COMMAND} -E echo "${output_string}")
16   if(${ARGV0} STREQUAL "FATAL_ERROR")
17     message (FATAL_ERROR)
18   endif()  
19 endfunction()
20
21 file(REMOVE ${CMAKE_BINARY_DIR}/ld_library_rpath_64.txt)
22
23 # log relative path to shared library that has to be used in LD_LIBRARY_PATH
24 function (log_rpath_remove_top component component_remove_top lib lib_remove_top)
25   
26   set(top_lib_dir ${${component}})
27   set(lib_dir ${lib})
28
29 #  debug_message(STATUS "LIB-IN=${lib} ")
30 #  debug_message(STATUS "TOPLIB-IN=${top_lib_dir} ")
31   get_filename_component(top_lib_dir ${${component}} DIRECTORY)
32
33   if (${component_remove_top} AND ${component})
34   else()
35     get_filename_component(add_name ${${component}} NAME)
36     set(top_lib_dir "${top_lib_dir}/${add_name}")
37   endif()
38   if (${lib_remove_top} AND lib)
39     get_filename_component(lib_dir ${lib} DIRECTORY)
40   endif()
41
42   string (REPLACE "//" "/" top_lib_dir "${top_lib_dir}")
43   string (REPLACE "//" "/" lib_dir "${lib_dir}")
44
45   string (REPLACE "\\\\" "/" top_lib_dir "${top_lib_dir}")
46   string (REPLACE "\\\\" "/" lib_dir "${lib_dir}")
47
48 #  debug_message(STATUS "LIB-OUT=${lib_dir}")
49 #  debug_message(STATUS "TOPLIB-OUT=${top_lib_dir}")
50  
51   string (REPLACE "${top_lib_dir}" "" component_dir "${lib_dir}")
52
53   set(RPATH_INFO "${component}=${component_dir}")
54   debug_message(STATUS "LD_LIBRARY_RPATH: ${RPATH_INFO}")
55   file(APPEND ${CMAKE_BINARY_DIR}/ld_library_rpath_64.txt "${RPATH_INFO}\n")
56 endfunction()
57
58 function (log_rpath_from_dir component lib_dir)
59   if(NOT APPLE)
60     log_rpath_remove_top("${component}" TRUE "${lib_dir}" FALSE)
61   endif()
62 endfunction()
63
64 function (log_rpath component lib_path)
65   log_rpath_remove_top(${component} TRUE ${lib_path} TRUE)
66 endfunction()
67
68 # Just wrapping of the original message() function to make this macro known during IE build.
69 # This macro is redefined (with additional checks) within the InferenceEngineConfig.cmake file.
70 macro(ext_message TRACE_LEVEL)
71     message(${TRACE_LEVEL} "${ARGN}")
72 endmacro()