process_file_recurse.cmake 4.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#
# Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
#
# This file is part of Orfeo Toolbox
#
#     https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
function(process_file_recurse input_file)
  set(input_file_full_path)
  search_library(${input_file} PKG_SEARCHDIRS input_file_full_path)
  if(NOT input_file_full_path)
    if(LINUX)
      setif_value_in_list(is_gtk_lib "${input_file}" ALLOWED_SYSTEM_DLLS)
      if(is_gtk_lib)
	search_library(${input_file} PKG_GTK_SEARCHDIRS input_file_full_path)
	if( NOT input_file_full_path)
	  message(FATAL_ERROR "${input_file} not found. searched in ${PKG_GTK_SEARCHDIRS}")
	endif()
      endif()
      if( NOT input_file_full_path)
	message(FATAL_ERROR "${input_file} not found. searched in ${PKG_SEARCHDIRS}")
	endif()
    endif(LINUX)

  endif() #if(NOT input_file_full_path)

  if(NOT PKG_DEBUG)
    message("Processing ${input_file_full_path}")
  endif()
42 43 44 45 46
  
  # Install the file with install_rule().
  # This function has specific "rules" to decide wheather and where to install file  
  install_rule(${input_file_full_path})
  
47 48 49
  set(raw_items)

  execute_process(
50
    COMMAND ${LOADER_PROGRAM} ${LOADER_ARGS} "${input_file_full_path}"
51 52 53 54 55 56 57 58 59 60
    RESULT_VARIABLE loader_rv
    OUTPUT_VARIABLE loader_ov
    ERROR_VARIABLE loader_ev
    )
  
  if(loader_rv)
    message(FATAL_ERROR "loader_ev=${loader_ev}\n PACKAGE-OTB: result_variable is '${loader_rv}'")
  endif()

  string(REPLACE ";" "\\;" candidates "${loader_ov}")
61
  string(REPLACE "\n" "${LOADER_REGEX_EOL};" candidates "${candidates}")
62 63 64 65 66 67 68 69 70 71 72 73 74
  
  get_filename_component(bn_name ${input_file_full_path} NAME)
  set(${bn_name}_USED TRUE CACHE INTERNAL "")

  if(PKG_DEBUG)
    message("Processing ${input_file} started. Set ${bn_name}_USED=${${bn_name}_USED}")
  endif()

  foreach(candidate ${candidates})
    if(NOT candidate)
      continue()
    endif()

75
    if(NOT "${candidate}" MATCHES "${LOADER_REGEX}")
76 77
      continue()
    endif()
Rashad Kanavath's avatar
Rashad Kanavath committed
78

79
    string(REGEX REPLACE "${LOADER_REGEX}" "\\1" raw_item "${candidate}")
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

    if(NOT raw_item)
      continue()
    endif()  

    string(STRIP ${raw_item} raw_item)
    set(is_system FALSE)
    setif_value_in_list(is_system "${raw_item}" SYSTEM_DLLS)
    if(APPLE AND NOT is_system)
      if("${raw_item}" MATCHES "@rpath")
        string(REGEX REPLACE "@rpath." "" raw_item "${raw_item}")
      else()
        message(FATAL_ERROR "'${raw_item}' does not have @rpath")
      endif()
    endif()

    if(PKG_DEBUG AND ${raw_item}_RESOLVED)
      message("${raw_item} is already resolved [${raw_item}_RESOLVED=${${raw_item}_RESOLVED}]")
    endif()

Rashad Kanavath's avatar
Rashad Kanavath committed
100 101 102
    if(PKG_DEBUG)
      message("raw_item='${raw_item}'\tis_system='${is_system}'")
    endif()
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    if(is_system OR ${raw_item}_RESOLVED OR ${raw_item}_USED)
      continue()
    endif()
    
    list(APPEND raw_items ${raw_item})
    
  endforeach()

  if(PKG_DEBUG)
    string(REPLACE ";" "\n" raw_items_pretty_print "${raw_items}")
    # message(FATAL_ERROR "raw_items=${raw_items_pretty_print}")
  endif(PKG_DEBUG)

  if(raw_items)
    list(REVERSE raw_items)
    foreach(item ${raw_items})      
      search_library(${item} PKG_SEARCHDIRS item_full_path)
      set(is_a_symlink FALSE)
      set(item_target_file)
122
      isfile_symlink("${item_full_path}" is_a_symlink item_target_file)
123 124 125 126 127 128 129
      if(is_a_symlink)
        set(${item}_RESOLVED TRUE CACHE INTERNAL "")
        set(item ${item_target_file})
      endif()
      if(PKG_DEBUG)
        message("${bn_name} depends on '${item}'. So we now process '${item}'") # [ ${item}_USED=${${item}_USED} ${item}_RESOLVED=${${item}_RESOLVED}]")
      endif()
Rashad Kanavath's avatar
Rashad Kanavath committed
130
      process_file_recurse(${item})
131 132 133 134 135 136 137 138
    endforeach()
  endif()

  set(${bn_name}_RESOLVED TRUE CACHE INTERNAL "")
   if(PKG_DEBUG)
     message("All dependencies of ${bn_name} are processed. Install file and set ${bn_name}_RESOLVED=${${bn_name}_RESOLVED}")
   endif()

139
   #install_rule(${input_file_full_path})
140

Rashad Kanavath's avatar
Rashad Kanavath committed
141
endfunction() #function(process_file_recurse infile)