Commit 77928d32 authored by Rashad Kanavath's avatar Rashad Kanavath

ENH: fix pkg_install rule

parent 00c77aec
......@@ -19,7 +19,14 @@
#
function(find_python_soname result)
set(${result} PARENT_SCOPE)
if(NOT PYTHON_EXECUTABLE)
message(FATAL_ERROR "PYTHON_EXECUTABLE not set. but we use this in this function")
return()
endif()
execute_process(
COMMAND ${PYTHON_EXECUTABLE}
-c
......@@ -32,7 +39,9 @@ function(find_python_soname result)
message( FATAL_ERROR
"python_INSTALLED_SONAME_rv=${python_INSTALLED_SONAME_rv}: Cannot find python library")
endif()
set(${result} "${python_INSTALLED_SONAME_ov}" PARENT_SCOPE)
endfunction()
......@@ -96,19 +105,9 @@ macro(add_to_symlink_list src_file_name link_file_name)
set(SKIP_INSTALL FALSE)
get_filename_component(src_file_name_NAME ${src_file_name} NAME)
if(PKG_GENERATE_XDK)
if ("${src_file_name_NAME}"
MATCHES
"libOTB|libotb|otbApp|otbapp_|otbTest|libMonteverdi|monteverdi|mapla|iceViewer"
)
set(SKIP_INSTALL TRUE)
endif()
endif(PKG_GENERATE_XDK)
get_filename_component(src_file_name_NAME ${src_file_name} NAME)
setif_value_in_list(is_gtk_lib "${src_file_name_NAME}" GTK_LIB_LIST_1)
if(is_gtk_lib AND PKG_GENERATE_XDK)
if(is_gtk_lib)
set(SKIP_INSTALL TRUE)
endif()
......@@ -128,149 +127,6 @@ macro(add_to_symlink_list src_file_name link_file_name)
endif()
endmacro()
function(is_file_executable2 file_var result_var)
#
# A file is not executable until proven otherwise:
#
set(${result_var} 0 PARENT_SCOPE)
get_filename_component(file_full "${${file_var}}" ABSOLUTE)
string(TOLOWER "${file_full}" file_full_lower)
# If file name ends in .exe on Windows, *assume* executable:
#
if(WIN32 AND NOT UNIX)
if("${file_full_lower}" MATCHES "(\\.exe|\\.dll)$")
set(${result_var} 1 PARENT_SCOPE)
return()
endif()
# A clause could be added here that uses output or return value of dumpbin
# to determine ${result_var}. In 99%+? practical cases, the exe name
# match will be sufficient...
#
endif() #WIN32 AND NOT UNIX
func_is_file_a_symbolic_link("${file_full}" is_a_symlink file_full_target)
if(is_a_symlink)
message("Resolving '${file_full}' to '${file_full_target}")
get_filename_component(file_full_path "${file_full}" PATH)
set(file_full "${file_full_path}/${file_full_target}")
if( EXISTS "${file_full}")
set(${file_var} "${file_full}" PARENT_SCOPE)
else()
message(FATAL_ERROR "${file_full} does not exists. Cannot continue")
endif()
string(TOLOWER "${file_full}" file_full_lower)
endif()
# Use the information returned from the Unix shell command "file" to
# determine if ${file_full} should be considered an executable file...
#
# If the file command's output contains "executable" and does *not* contain
# "text" then it is likely an executable suitable for prerequisite analysis
# via the get_prerequisites macro.
#
#if we are not on a unix or unix-like platform, then we don't have any business here
if(NOT UNIX)
return()
endif()
if(NOT FILE_COMMAND)
message(FATAL_ERROR "warning: No 'file' command, cannot continue...")
endif()
if(NOT EXISTS "${file_full}")
message(FATAL_ERROR "err. '${file_full}' does not exists or is not absolute path")
set(${file_var} "" PARENT_SCOPE)
endif()
execute_process(COMMAND "${FILE_COMMAND}" "${file_full}"
RESULT_VARIABLE file_rv
OUTPUT_VARIABLE file_ov
ERROR_VARIABLE file_ev
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT file_rv STREQUAL "0")
message(FATAL_ERROR "${FILE_COMMAND} failed: ${file_rv}\n${file_ev}")
endif()
# Replace the name of the file in the output with a placeholder token
# (the string " _file_full_ ") so that just in case the path name of
# the file contains the word "text" or "executable" we are not fooled
# into thinking "the wrong thing" because the file name matches the
# other 'file' command output we are looking for...
#
string(REPLACE "${file_full}" " _file_full_ " file_ov "${file_ov}")
string(TOLOWER "${file_ov}" file_ov)
# message(STATUS "file_ov='${file_ov}'")
# below executable check works for both mac osx and linux
# message("file_full=${file_ov}")
if("${file_ov}" MATCHES "executable")
#message(STATUS "executable!")
if("${file_ov}" MATCHES "text")
set(${result_var} 0 PARENT_SCOPE)
#message(FATAL_ERROR "but text, so *not* a binary executable!")
else()
set(${result_var} 1 PARENT_SCOPE)
return()
endif()
endif()
# detect position independent executables on Linux,
# where "file" gives "dynamically linked (uses shared libraries)"
if("${file_ov}" MATCHES "dynamically linked.*\(uses shared libs\)")
set(${result_var} 1 PARENT_SCOPE)
return()
endif()
# detect position independent executables on Linux,
# where "file" gives "shared object ... (uses shared libraries)"
if("${file_ov}" MATCHES "shared object.*\(uses shared libs\)")
set(${result_var} 1 PARENT_SCOPE)
return()
endif()
# detect shared libraries on Linux,
# where "file" gives "ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not stripped"
if("${file_ov}" MATCHES "elf.*shared object.*version")
set(${result_var} 1 PARENT_SCOPE)
return()
endif()
# "file" version 5.22 does not print "(used shared libraries)"
# but uses "interpreter"
if("${file_ov}" MATCHES "shared object.*interpreter")
set(${result_var} 1 PARENT_SCOPE)
return()
endif()
if(APPLE)
# detect shared libraries on Mac OSX
# where "file" gives "Mach-O 64-bit x86_64 dynamically linked shared library"
if("${file_ov}" MATCHES "mach-o.*dynamically linked shared library")
set(${result_var} 1 PARENT_SCOPE)
return()
endif()
#below check is redundant. detect executables on Mac OSX
# where "file" gives "Mach-O 64-bit x86_64 executable"
if("${file_ov}" MATCHES "mach-o.*executable")
set(${result_var} 1 PARENT_SCOPE)
return()
endif()
# detect shared libraries on Mac OSX
# where "file" gives "Mach-O 64-bit x86_64 bundle"
if("${file_ov}" MATCHES "mach-o.*bundle")
set(${result_var} 1 PARENT_SCOPE)
return()
endif()
endif(APPLE)
endfunction()
# The below function is modified from GetPrerequisities.cmake
......@@ -409,3 +265,5 @@ function(func_patch_cmake_files_for)
func_install_without_message("${PATCH_DIR_TEMP}" "lib/cmake")
endfunction()
......@@ -2,82 +2,178 @@ function(install_rule src_file)
get_filename_component(src_file_EXT ${src_file} EXT)
get_filename_component(src_file_NAME ${src_file} NAME)
set(file_type PROGRAMS)
if(NOT src_file_EXT)
set(output_dir "bin")
elseif("${src_file_EXT}" MATCHES "(.[Dd][Ll][Ll]|.exe)")
set(output_dir "bin")
elseif("${src_file_EXT}" MATCHES "(.lib|.so|.dylib)")
set(output_dir "lib")
set(file_type FILES)
else()
message(FATAL_ERROR "unreachable code")
endif()
set(SKIP_INSTALL FALSE)
setif_value_in_list(is_gtk_lib "${src_file_NAME}" GTK_LIB_LIST_1)
if(is_gtk_lib)
if(PKG_GENERATE_XDK)
set(SKIP_INSTALL TRUE)
else()
set(output_dir "lib/gtk")
endif() #if(PKG_GENERATE_XDK)
endif() #if(is_gtk_lib)
get_filename_component(src_file_NAME_WE ${src_file} NAME_WE)
get_filename_component(src_file_PATH ${src_file} PATH)
set(SKIP_INSTALL FALSE)
string(TOLOWER "${src_file_NAME}" src_file_NAME_LOWER)
#avoid test executables
#TODO:! a special case
if ("${src_file_NAME_LOWER}" MATCHES "(otb|mvd)*.*test*.*${EXE_EXT}")
if (NOT "${src_file_NAME_LOWER}" MATCHES "\\${LIB_EXT}" AND
NOT "${src_file_NAME_LOWER}" MATCHES "otbtestdriver" )
set(SKIP_INSTALL TRUE)
message("SKIP_INSTALL for ${src_file_NAME}")
endif()
if(NOT FILE_COMMAND)
message(FATAL_ERROR "warning: No 'file' command, cannot continue...")
endif()
#special case
if("${src_file_NAME}" MATCHES "^otbapp_")
set(output_dir "lib/otb/applications")
set(file_type PROGRAMS)
set(SKIP_INSTALL FALSE)
file(GLOB src_file_star "${src_file_PATH}/${src_file_NAME_WE}*")
get_filename_component(src_file_NAME_WE ${src_file} NAME_WE)
########### install cli and gui script for each application ###########
set(WRAPPER_SCRIPT_EXT "")
if(WIN32)
set(WRAPPER_SCRIPT_EXT ".bat")
foreach(sfile ${src_file_star})
#message( "sfile=${sfile}")
get_filename_component(sfile_NAME ${sfile} NAME)
get_filename_component(file_full "${sfile}" ABSOLUTE)
string(TOLOWER "${file_full}" file_full_lower)
string(TOLOWER "${sfile_NAME}" sfile_NAME_LOWER)
if ("${sfile_NAME_LOWER}" MATCHES "^(otb|mvd)([a-z]+)(headertest|testdriver)")
message( "SKIP INSTALL for ${sfile_NAME_LOWER}")
continue()
endif()
set(${src_file_NAME_WE}_CLI "${SUPERBUILD_INSTALL_DIR}/bin/otbcli_${src_file_NAME_WE}${WRAPPER_SCRIPT_EXT}")
set(${src_file_NAME_WE}_GUI "${SUPERBUILD_INSTALL_DIR}/bin/otbgui_${src_file_NAME_WE}${WRAPPER_SCRIPT_EXT}")
string(REPLACE "otbapp_" "" ${src_file_NAME_WE}_GUI ${${src_file_NAME_WE}_GUI})
string(REPLACE "otbapp_" "" ${src_file_NAME_WE}_CLI ${${src_file_NAME_WE}_CLI})
if(EXISTS "${${src_file_NAME_WE}_CLI}")
install(PROGRAMS ${${src_file_NAME_WE}_CLI} DESTINATION ${PKG_STAGE_DIR}/bin)
set(install_type)
set(install_dir)
if("${file_full_lower}" MATCHES "(\\.exe)$")
set(install_type PROGRAMS)
set(install_dir bin)
elseif("${file_full_lower}" MATCHES "(\\.dll)$")
set(install_type FILES)
set(install_dir bin)
elseif("${file_full_lower}" MATCHES "(\\.lib)$")
set(install_type FILES)
set(install_dir lib)
elseif("${file_full_lower}" MATCHES "(\\.a)$")
set(install_type FILES)
set(install_dir lib)
elseif("${file_full_lower}" MATCHES "\\.lnk$")
#Assuming the file is linked to a file with same name without .lnk extension
get_filename_component(real_file "${file_full_lower}" NAME_WE)
get_filename_component(real_file_PATH "${real_file}" PATH)
get_filename_component(real_file_PATH "${real_file_PATH}" PATH)
set(install_type "symlink")
set(install_dir ${real_file_PATH})
set(linked_to_file ${real_file})
elseif("${file_full_lower}" MATCHES "\\.prl$")
continue()
elseif("${file_full_lower}" MATCHES "\\.la$")
continue()
else()
message(FATAL_ERROR "Cannot find ${${src_file_NAME_WE}_CLI} for ${src_file_NAME_WE}")
execute_process(COMMAND "${FILE_COMMAND}" "${file_full}"
RESULT_VARIABLE file_rv
OUTPUT_VARIABLE file_ov
ERROR_VARIABLE file_ev
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT file_rv STREQUAL "0")
message(FATAL_ERROR "${FILE_COMMAND} failed: ${file_rv}\n${file_ev}\n${file_ov}")
endif()
string(REPLACE "${file_full}" " _file_full_ " file_ov "${file_ov}")
string(TOLOWER "${file_ov}" file_ov)
# below executable check works for both mac osx and linux
if("${file_ov}" MATCHES "executable")
set(install_type PROGRAMS)
set(install_dir bin)
# detect position independent executables on Linux,
# where "file" gives "dynamically linked (uses shared libraries)"
elseif("${file_ov}" MATCHES "dynamically linked.*\(uses shared libs\)")
set(install_type FILES)
set(install_dir lib)
# detect position independent executables on Linux,
# where "file" gives "shared object ... (uses shared libraries)"
elseif("${file_ov}" MATCHES "shared object.*\(uses shared libs\)")
set(install_type FILES)
set(install_dir lib)
# detect shared libraries on Linux,
# where "file" gives "ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not stripped"
elseif("${file_ov}" MATCHES "elf.*shared object.*version")
set(install_type FILES)
set(install_dir lib)
# "file" version 5.22 does not print "(used shared libraries)"
# but uses "interpreter"
elseif("${file_ov}" MATCHES "shared object.*interpreter")
set(install_type FILES)
set(install_dir lib)
# detect shared libraries on Mac OSX
# where "file" gives "Mach-O 64-bit x86_64 dynamically linked shared library"
elseif("${file_ov}" MATCHES "mach-o.*dynamically linked shared library")
set(install_type FILES)
set(install_dir lib)
#below check is redundant. detect executables on Mac OSX
# where "file" gives "Mach-O 64-bit x86_64 executable"
elseif("${file_ov}" MATCHES "mach-o.*executable")
set(install_type PROGRAMS)
set(install_dir bin)
# detect shared libraries on Mac OSX
# where "file" gives "Mach-O 64-bit x86_64 bundle"
elseif("${file_ov}" MATCHES "mach-o.*bundle")
set(install_type FILES)
set(install_dir lib)
elseif("${file_ov}" MATCHES "mach-o.*bundle")
set(install_type FILES)
set(install_dir lib)
elseif("${file_ov}" MATCHES "symbolic link")
#Now find where the symlink is linked to.
#Do a regex replace
string(REGEX REPLACE "_file_full_*.*symbolic.link.to." "" target_file ${file_ov})
#older version of file command output has [`} character(remove it).
string(REPLACE "`" "" target_file ${target_file} )
#older version of file command output has {'} character(remove it).
string(REPLACE "'" "" target_file "${target_file}")
#strip final output
string(STRIP ${target_file} target_file)
setif_value_in_list(is_gtk_lib "${sfile_NAME}" GTK_LIB_LIST_1)
set(lib_dir "lib")
if(is_gtk_lib)
set(lib_dir "lib/gtk")
endif()
file(APPEND
${CMAKE_BINARY_DIR}/make_symlinks
"ln -sf \"$OUT_DIR/${lib_dir}/${target_file}\" \"$OUT_DIR/${lib_dir}/${sfile_NAME}\" \n"
)
continue()
endif()
endif()
if(EXISTS "${${src_file_NAME_WE}_GUI}")
install(PROGRAMS ${${src_file_NAME_WE}_GUI} DESTINATION ${PKG_STAGE_DIR}/bin)
else()
message(FATAL_ERROR "Cannot find ${${src_file_NAME_WE}_GUI} for ${src_file_NAME_WE}")
if("${sfile_NAME}" MATCHES "^otbapp_")
set(output_dir "lib/otb/applications")
set(install_type PROGRAMS)
########### install cli and gui script for each application ###########
set(WRAPPER_SCRIPT_EXT "")
if(WIN32)
set(WRAPPER_SCRIPT_EXT ".bat")
endif()
set(${src_file_NAME_WE}_CLI "${SUPERBUILD_INSTALL_DIR}/bin/otbcli_${src_file_NAME_WE}${WRAPPER_SCRIPT_EXT}")
set(${src_file_NAME_WE}_GUI "${SUPERBUILD_INSTALL_DIR}/bin/otbgui_${src_file_NAME_WE}${WRAPPER_SCRIPT_EXT}")
string(REPLACE "otbapp_" "" ${src_file_NAME_WE}_GUI ${${src_file_NAME_WE}_GUI})
string(REPLACE "otbapp_" "" ${src_file_NAME_WE}_CLI ${${src_file_NAME_WE}_CLI})
if(NOT EXISTS "${${src_file_NAME_WE}_CLI}")
message(FATAL_ERROR "Cannot find ${${src_file_NAME_WE}_CLI} for ${src_file_NAME_WE}")
endif()
if(NOT EXISTS "${${src_file_NAME_WE}_GUI}")
message(FATAL_ERROR "Cannot find ${${src_file_NAME_WE}_GUI} for ${src_file_NAME_WE}")
endif()
install(PROGRAMS
${${src_file_NAME_WE}_CLI}
${${src_file_NAME_WE}_GUI}
DESTINATION
${PKG_STAGE_DIR}/bin )
endif()
if(install_type AND install_dir)
install(${install_type} "${sfile}"
DESTINATION
"${PKG_STAGE_DIR}/${install_dir}"
)
else()
message(FATAL_ERROR "sfile=${sfile} || file_ov=${file_ov}")
endif()
endif()
endforeach()
if(NOT SKIP_INSTALL)
install(${file_type} "${src_file}"
DESTINATION
"${PKG_STAGE_DIR}/${output_dir}"
)
endif()
endfunction()
......@@ -12,6 +12,7 @@ function(install_script_files)
#we need startup files for mapla monteverdi in the root directory
#For Unixes, we make them inside pkgsetup script!
if(HAVE_MVD)
message(FATAL_ERROR "HAVE_MVD is set")
install(
PROGRAMS ${PACKAGE_SUPPORT_FILES_DIR}/mapla.bat
PROGRAMS ${PACKAGE_SUPPORT_FILES_DIR}/monteverdi.bat
......
......@@ -13,23 +13,17 @@ function(prepare_file_list PKG_PEFILES)
set(PKG_PEFILES "otbApplicationLauncherCommandLine${EXE_EXT}")
set(HAVE_QT4 FALSE)
if(EXISTS "${SUPERBUILD_INSTALL_DIR}/bin/otbApplicationLauncherQt${EXE_EXT}")
set(HAVE_QT4 TRUE)
if(HAVE_QT4)
list(APPEND PKG_PEFILES "otbApplicationLauncherQt${EXE_EXT}")
endif()
set(HAVE_MVD FALSE)
if(EXISTS "${SUPERBUILD_INSTALL_DIR}/bin/monteverdi${EXE_EXT}")
set(HAVE_MVD TRUE)
if(HAVE_MVD)
list(APPEND PKG_PEFILES "monteverdi${EXE_EXT}")
list(APPEND PKG_PEFILES "mapla${EXE_EXT}")
endif()
set(HAVE_PYTHON FALSE)
if(EXISTS "${SUPERBUILD_INSTALL_DIR}/lib/otb/python/_otbApplication${PYMODULE_EXT}")
if(HAVE_PYTHON)
list(APPEND PKG_PEFILES "_otbApplication${PYMODULE_EXT}")
set(HAVE_PYTHON TRUE)
endif()
foreach(exe_file "iceViewer" "otbTestDriver" "SharkVersion")
......@@ -76,17 +70,22 @@ function(prepare_file_list PKG_PEFILES)
if(NOT a_symlink)
list(APPEND PKG_PEFILES "${itk_lib_file}")
endif()
endforeach()
#end hack
endforeach()
#end hack
file(GLOB otb_test_exe_list
"${SUPERBUILD_INSTALL_DIR}/bin/gdal*${EXE_EXT}"
"${OTB_BINARY_DIR}/bin/*[T|t]est*${EXE_EXT}"
)
list(REMOVE_ITEM otb_test_exe_list "${SUPERBUILD_INSTALL_DIR}/bin/gdal-config")
list(REMOVE_ITEM otb_test_exe_list "${OTB_BINARY_DIR}/bin/otbcli_TestApplication")
list(REMOVE_ITEM otb_test_exe_list "${OTB_BINARY_DIR}/bin/otbgui_TestApplication")
file(GLOB otb_test_exe_list
"${SUPERBUILD_INSTALL_DIR}/bin/gdal*${EXE_EXT}"
"${OTB_BINARY_DIR}/bin/*Test*${EXE_EXT}"
)
foreach(otb_test_exe ${otb_test_exe_list})
get_filename_component(otb_test_exe_name ${otb_test_exe} NAME)
list(APPEND PKG_PEFILES ${otb_test_exe_name})
endforeach()
foreach(otb_test_exe ${otb_test_exe_list})
get_filename_component(otb_test_exe_name ${otb_test_exe} NAME)
list(APPEND PKG_PEFILES ${otb_test_exe_name})
endforeach()
# special case for msvc: ucrtbase.dll must be explicitly vetted.
if(MSVC)
......
......@@ -23,48 +23,8 @@ function(process_file_recurse input_file)
message("Processing ${input_file_full_path}")
endif()
set(is_executable FALSE)
is_file_executable2(input_file_full_path is_executable)
if(NOT is_executable)
#copy back to input_file_full_path
install_rule(${input_file_full_path})
message("not is_executable ${input_file_full_path}")
return()
endif() #NOT is_executable
if(UNIX)
# Deal with symlinks.
# For any valid symlinks, (see 'not_valid' below)
# we append ln -s source target commands to a file
# That file is executed during installation.
get_filename_component(bn_we ${input_file_full_path} NAME_WE)
get_filename_component(bn_path ${input_file_full_path} PATH)
file(GLOB sofiles "${bn_path}/${bn_we}*")
foreach(sofile ${sofiles})
get_filename_component(basename_of_sofile ${sofile} NAME)
get_filename_component(sofile_ext ${sofile} EXT)
set(not_valid FALSE)
if( "${sofile_ext}" MATCHES ".la"
OR "${sofile_ext}" MATCHES ".prl"
OR IS_DIRECTORY "${sofile}" )
set(not_valid TRUE)
endif()
if(not_valid)
continue()
endif()
func_is_file_a_symbolic_link("${sofile}" is_symlink linked_to_file)
if(is_symlink)
add_to_symlink_list("${linked_to_file}" "${basename_of_sofile}")
endif() # is_symlink
endforeach()
endif(UNIX)
install_rule(${input_file_full_path})
set(raw_items)
......
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