Commit 3ab46139 authored by Guillaume Pasero's avatar Guillaume Pasero

BUG: Mantis-1474: try to remove system locations in OTB package

parent 9b577891
......@@ -18,6 +18,56 @@
# limitations under the License.
#
function(sanitize_system_paths)
cmake_parse_arguments(SANITIZE "" "SOURCE" "" ${ARGN} )
# does not support Windows ...
if(APPLE)
set(SHARED_EXT "\\.dylib")
elseif(UNIX)
set(SHARED_EXT "\\.so")
endif()
set(filtered_content)
file(STRINGS "${SANITIZE_SOURCE}" source_file_content NEWLINE_CONSUME)
string(REGEX REPLACE "\n" "\n;" source_file_content "${source_file_content}")
set(SEARCH_REGEX "(^[^#\"]+(LIBRARIES|INCLUDE_DIR[A-Z]*) +\")(.+)(\"[^\"]*)")
foreach(line ${source_file_content})
set(filtered_line "${line}")
if(line MATCHES "${SEARCH_REGEX}")
string(REGEX REPLACE "${SEARCH_REGEX}" "\\3" extract_str "${line}" )
string(REGEX REPLACE ";;" ";" extract_str "${extract_str}")
set(_to_be_removed)
set(_to_be_added)
foreach(path ${extract_str})
if(IS_ABSOLUTE ${path})
list(APPEND _to_be_removed "${path}")
if(NOT IS_DIRECTORY ${path})
if(path MATCHES "^.*/lib[^\\.]+${SHARED_EXT}.*")
string(REGEX REPLACE "^.*/lib([^\\.]+)${SHARED_EXT}.*" "\\1" _lib_name "${path}")
list(APPEND _to_be_added "${_lib_name}")
endif()
endif()
endif()
endforeach()
if(_to_be_removed)
list(REMOVE_ITEM extract_str ${_to_be_removed})
endif()
if(_to_be_added)
list(INSERT extract_str 0 ${_to_be_added})
endif()
if(extract_str)
list(REMOVE_DUPLICATES extract_str)
endif()
string(REGEX REPLACE "${SEARCH_REGEX}" "\\1${extract_str}\\4" filtered_line "${line}" )
endif()
list(APPEND filtered_content "${filtered_line}")
endforeach()
string(REGEX REPLACE "\n;" "\n" filtered_content "${filtered_content}")
file(WRITE "${SANITIZE_SOURCE}" "${filtered_content}")
endfunction()
#check variables are set
foreach(var P_DIRS P_MATCH P_REPLACE)
if(NOT ${var})
......@@ -42,5 +92,8 @@ foreach( p_dir ${P_DIRS} )
file(WRITE "${cmake_file}" "# This file is modified by OTB after installation.
\n${cmake_file_CONTENTS}")
endif()
if(UNIX)
sanitize_system_paths(SOURCE ${cmake_file})
endif()
endforeach() # foreach( cmake_file
endforeach() # foreach( p_dir
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment