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