summaryrefslogtreecommitdiff
path: root/inference-engine/cmake/debug.cmake
blob: 4a8edf0bc749fb3bea16f95d3552a529b4a37e2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#

cmake_minimum_required (VERSION 2.8)

function (debug_message)
    if (VERBOSE_BUILD)
        message(${ARGV})
    endif()
endfunction()


function(clean_message type)
  string (REPLACE ";" "" output_string "${ARGN}")
  execute_process(COMMAND ${CMAKE_COMMAND} -E echo "${output_string}")
  if(${ARGV0} STREQUAL "FATAL_ERROR")
    message (FATAL_ERROR)
  endif()  
endfunction()

file(REMOVE ${CMAKE_BINARY_DIR}/ld_library_rpath_64.txt)

# log relative path to shared library that has to be used in LD_LIBRARY_PATH
function (log_rpath_remove_top component component_remove_top lib lib_remove_top)
  
  set(top_lib_dir ${${component}})
  set(lib_dir ${lib})

#  debug_message(STATUS "LIB-IN=${lib} ")
#  debug_message(STATUS "TOPLIB-IN=${top_lib_dir} ")
  get_filename_component(top_lib_dir ${${component}} DIRECTORY)

  if (${component_remove_top} AND ${component})
  else()
    get_filename_component(add_name ${${component}} NAME)
    set(top_lib_dir "${top_lib_dir}/${add_name}")
  endif()
  if (${lib_remove_top} AND lib)
    get_filename_component(lib_dir ${lib} DIRECTORY)
  endif()

  string (REPLACE "//" "/" top_lib_dir "${top_lib_dir}")
  string (REPLACE "//" "/" lib_dir "${lib_dir}")

  string (REPLACE "\\\\" "/" top_lib_dir "${top_lib_dir}")
  string (REPLACE "\\\\" "/" lib_dir "${lib_dir}")

#  debug_message(STATUS "LIB-OUT=${lib_dir}")
#  debug_message(STATUS "TOPLIB-OUT=${top_lib_dir}")
 
  string (REPLACE "${top_lib_dir}" "" component_dir "${lib_dir}")

  set(RPATH_INFO "${component}=${component_dir}")
  debug_message(STATUS "LD_LIBRARY_RPATH: ${RPATH_INFO}")
  file(APPEND ${CMAKE_BINARY_DIR}/ld_library_rpath_64.txt "${RPATH_INFO}\n")
endfunction()

function (log_rpath_from_dir component lib_dir)
  if(NOT APPLE)
    log_rpath_remove_top("${component}" TRUE "${lib_dir}" FALSE)
  endif()
endfunction()

function (log_rpath component lib_path)
  log_rpath_remove_top(${component} TRUE ${lib_path} TRUE)
endfunction()