install_rule.cmake 4.69 KB
Newer Older
1
#
2
# Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#
# 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.
#
#
21 22 23 24
# This is one big fat if-elseif ladder
# that will detect a type and destination to use in
# install(..

Rashad Kanavath's avatar
Rashad Kanavath committed
25 26 27 28
function(install_rule src_file)

  get_filename_component(src_file_EXT ${src_file} EXT)
  get_filename_component(src_file_NAME ${src_file} NAME)
Rashad Kanavath's avatar
Rashad Kanavath committed
29 30
  get_filename_component(src_file_NAME_WE ${src_file} NAME_WE)
  get_filename_component(src_file_PATH ${src_file} PATH)
Rashad Kanavath's avatar
Rashad Kanavath committed
31

32 33 34
  get_filename_component(src_file_GPATH ${src_file_PATH} PATH)
  get_filename_component(src_file_GNAME ${src_file_GPATH} NAME)

Rashad Kanavath's avatar
Rashad Kanavath committed
35 36 37 38
  file(GLOB src_file_star "${src_file_PATH}/${src_file_NAME_WE}*")
  foreach(sfile ${src_file_star})
    get_filename_component(sfile_NAME ${sfile} NAME)
    string(TOLOWER "${sfile_NAME}" sfile_NAME_LOWER)
39 40 41

    get_filename_component(sfile_ABS "${sfile}" ABSOLUTE)
    string(TOLOWER "${sfile_ABS}" sfile_ABS_LOWER)
Rashad Kanavath's avatar
Rashad Kanavath committed
42 43
    set(install_type)
    set(install_dir)
44
    if ("${sfile_NAME_LOWER}" MATCHES "^(otb|mvd)([a-z0-9]+)test*.*" )
45 46 47
      if(PKG_DEBUG)
        message("SKIP INSTALL for ${sfile_NAME_LOWER}")
      endif()
48
      continue()
49
    elseif ("${sfile_NAME_LOWER}" MATCHES "headertest" )
50 51 52
      # special case for remote modules which has executables
      # like MosiacHeaderTest1.exe. This ideally should be
      # fixed in remote modules like OTBMosiacHeaderTest1.exe
53
      if(PKG_DEBUG)
Antoine Regimbeau's avatar
Antoine Regimbeau committed
54
        message("SKIP INSTALL for ${sfile_NAME_LOWER}")
55 56
      endif()
      continue()
57 58 59
    elseif(("${sfile_ABS_LOWER}" MATCHES "(\\${LIB_EXT})$") AND (src_file_GNAME STREQUAL "plugins"))
      # special case: Qt plugins are installed by install_qtdev_files
      continue()
60
    elseif("${sfile_ABS_LOWER}" MATCHES "(\\.exe)$")
Rashad Kanavath's avatar
Rashad Kanavath committed
61 62
      set(install_type PROGRAMS)
      set(install_dir bin)
63
    elseif("${sfile_ABS_LOWER}" MATCHES "(\\.dll)$")
Rashad Kanavath's avatar
Rashad Kanavath committed
64 65
      set(install_type FILES)
      set(install_dir bin) 
66
    elseif("${sfile_ABS_LOWER}" MATCHES "(\\.lib)$")
Rashad Kanavath's avatar
Rashad Kanavath committed
67 68
      set(install_type FILES)
      set(install_dir lib)
69 70 71
    elseif("${sfile_ABS_LOWER}" MATCHES "(\\.pyd)$")
      #python bindings are installed in install_python_bindings
      continue()
72 73 74 75
    elseif( "${sfile_NAME_LOWER}" MATCHES "^_otbapplication")
      # _otbApplication.so matched below; so we explicit skip it
      # because it's already handled in install_python_bindings.cmake
      continue()
76 77
    elseif("${sfile_ABS_LOWER}" MATCHES "\\.lnk$")
      #we don't install symlink on windows. issue a warning
78 79
      set(install_type "symlink")
      set(install_dir)
80 81 82
    elseif("${sfile_ABS_LOWER}" MATCHES "(\\.a)$")
      set(install_type FILES)
      set(install_dir lib)
83
    elseif("${sfile_ABS_LOWER}" MATCHES "\\.prl$")
Rashad Kanavath's avatar
Rashad Kanavath committed
84
      continue()
85 86
    elseif("${sfile_ABS_LOWER}" MATCHES "\\.la$")
      continue()
87 88
    elseif("${sfile_ABS_LOWER}" MATCHES "\\.settings$")
      continue()
89 90
    elseif("${sfile_ABS_LOWER}" MATCHES "-config$")
      continue()
Rashad Kanavath's avatar
Rashad Kanavath committed
91
    else()
92
      if(UNIX)
93 94 95 96 97
        #the last else() loop where we run a 'file' command to find file type and directory
        set(install_type)
        set(install_dir)
        #this is whole other story
        detect_using_file_command(${sfile_ABS} install_type install_dir)
98 99
      endif(UNIX)
    endif()
100 101

    if(install_type STREQUAL "symlink")
102
      #we don't install symlink on windows. issue a warning and continue
103 104 105
      if(PKG_DEBUG)
        message("${sfile_ABS} is a symbolic link and this will be excluded from package")
      endif()
106
      continue()
107
    endif()
Rashad Kanavath's avatar
Rashad Kanavath committed
108
    
109 110 111
    # This check comes outside the first if-elseif ladder
    # because no matter what extension of file type, otbapp_* must go
    # into lib/otb/applications
Antoine Regimbeau's avatar
Antoine Regimbeau committed
112 113 114 115 116
    if("${sfile_NAME_LOWER}" MATCHES "^otbapp_")
      install_otbapp_wrapper_scripts(${sfile_NAME})
      set(install_dir "lib/otb/applications")
      set(install_type PROGRAMS)
    endif()
117 118
  
    if(NOT install_type OR NOT install_dir)
119
      #throw fatal error and return
120
      message(FATAL_ERROR "sfile_ABS=${sfile_ABS}.\ninstall_type=${install_type}\ninstall_dir=${install_dir}")
121 122
      return()
    endif()
123 124 125 126 127

    install(${install_type} "${sfile}"
      DESTINATION
      "${PKG_STAGE_DIR}/${install_dir}"
      )
128

129
  endforeach()  
Rashad Kanavath's avatar
Rashad Kanavath committed
130 131
endfunction()