Skip to content
Snippets Groups Projects
Commit 06766699 authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

PKG: find file command in CMakeLists to avoid finding again in function

parent 21e965c1
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,6 @@ macro(macro_setup_cmake_project pkg)
else()
set(PKG_GENERATE_XDK OFF)
endif()
if(PKG_GENERATE_XDK)
set(archive_name ${PACKAGE_NAME}-${PKG_OTB_VERSION_STRING}-xdk-${PACKAGE_PLATFORM_NAME}${PACKAGE_ARCH})
......@@ -50,6 +49,7 @@ macro(macro_setup_cmake_project pkg)
set(OTB_TARGET_SYSTEM_ARCH_IS_X64 ${OTB_TARGET_SYSTEM_ARCH_IS_X64})
set(OTB_WRAP_PYTHON ${OTB_WRAP_PYTHON})
set(PKG_DEBUG ${PKG_DEBUG})
set(FILE_COMMAND \"${FILE_COMMAND}\")
${EXTRA_CACHE_CONFIG}
include(${SUPERBUILD_SOURCE_DIR}/Packaging/PackageMacros.cmake)
include(${SUPERBUILD_SOURCE_DIR}/Packaging/PackageHelper.cmake)
......
......@@ -14,10 +14,16 @@ macro(macro_super_package)
message(FATAL_ERROR "DEPENDENCIES_INSTALL_DIR is not set of empty")
endif()
if(LINUX AND NOT PATCHELF_PROGRAM)
message(FATAL_ERROR "PATCHELF_PROGRAM not set")
endif()
if(LINUX)
if(NOT FILE_COMMAND)
message(FATAL_ERROR "warning: No 'file' command, cannot continue...")
endif()
if(NOT PATCHELF_PROGRAM)
message(FATAL_ERROR "PATCHELF_PROGRAM not set")
endif()
endif(LINUX)
#setting this variable. prints a lot of debug information
#set( PKG_DEBUG 1)
......@@ -51,7 +57,7 @@ macro(macro_super_package)
if(NOT LOADER_PROGRAM)
message(FATAL_ERROR "${loader_program_names} not found in ${loader_program_PATHS}.")
endif()
include(GetPrerequisites)
set(LOADER_PROGRAM_ARGS ${loader_program_args})
......
function(find_python_soname result)
set(${result} PARENT_SCOPE)
execute_process(
COMMAND ${PYTHON_EXECUTABLE}
-c
"import sys; from distutils import sysconfig; print (sysconfig.get_config_var('INSTSONAME'));"
RESULT_VARIABLE python_INSTALLED_SONAME_rv
OUTPUT_VARIABLE python_INSTALLED_SONAME_ov
)
set(${result} PARENT_SCOPE)
execute_process(
COMMAND ${PYTHON_EXECUTABLE}
-c
"import sys; from distutils import sysconfig; print (sysconfig.get_config_var('INSTSONAME'));"
RESULT_VARIABLE python_INSTALLED_SONAME_rv
OUTPUT_VARIABLE python_INSTALLED_SONAME_ov
)
if(NOT python_INSTALLED_SONAME_rv EQUAL 0)
message( FATAL_ERROR
"python_INSTALLED_SONAME_rv=${python_INSTALLED_SONAME_rv}: Cannot find python library")
endif()
set(${result} "${python_INSTALLED_SONAME_ov}" PARENT_SCOPE)
if(NOT python_INSTALLED_SONAME_rv EQUAL 0)
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()
......@@ -22,7 +22,7 @@ function(func_install_without_message src_dir dst_dir_suffix)
if (${num_extra_args} GREATER 0)
list(GET extra_func_args 0 optional_msg)
endif()
if( "${dst_dir_suffix}" STREQUAL "")
set(dst_dir "${PKG_STAGE_DIR}")
else()
......@@ -68,7 +68,7 @@ function(search_library input_file pkg_searchdirs result)
return()
endif()
endforeach()
endfunction()
macro(add_to_symlink_list src_file target_file)
......@@ -93,10 +93,10 @@ macro(add_to_symlink_list src_file target_file)
# NOTE: $OUT_DIR is set actually in pkgsetup.in. So don't try
# any pre-mature optimization on that variable names
if(NOT SKIP_INSTALL)
file(APPEND
${CMAKE_BINARY_DIR}/make_symlinks_temp
"ln -sf \"$OUT_DIR/lib/${src_file}\" \"$OUT_DIR/lib/${target_file}\" \n"
)
file(APPEND
${CMAKE_BINARY_DIR}/make_symlinks_temp
"ln -sf \"$OUT_DIR/lib/${src_file}\" \"$OUT_DIR/lib/${target_file}\" \n"
)
endif()
endmacro()
......@@ -121,6 +121,14 @@ function(is_file_executable2 file result_var)
# 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}")
string(TOLOWER "${file_full}" file_full_lower)
endif()
# Use the information returned from the Unix shell command "file" to
......@@ -130,96 +138,97 @@ function(is_file_executable2 file result_var)
# "text" then it is likely an executable suitable for prerequisite analysis
# via the get_prerequisites macro.
#
if(UNIX)
if(NOT file_cmd)
find_program(file_cmd "file")
mark_as_advanced(file_cmd)
endif()
if(file_cmd)
execute_process(COMMAND "${file_cmd}" "${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_cmd} failed: ${file_rv}\n${file_ev}")
endif()
#if we are not on a unix or unix-like platform, then we don't have any business here
if(NOT UNIX)
return()
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
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()
if(NOT FILE_COMMAND)
message(FATAL_ERROR "warning: No 'file' command, cannot continue...")
endif()
# Also 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()
# Also 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()
if(NOT EXISTS "${file_full}")
message(FATAL_ERROR "err. '${file_full}' does not exists or is not absolute path")
endif()
# Also 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()
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()
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()
endif(APPLE)
# 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()
message(STATUS "warning: No 'file' command, skipping execute_process...")
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()
endif(APPLE)
endfunction()
......@@ -264,54 +273,48 @@ function(func_is_file_a_symbolic_link file result_var1 result_var2)
# "text" then it is likely an executable suitable for prerequisite analysis
# via the get_prerequisites macro.
#
if(NOT file_cmd)
find_program(file_cmd "file")
mark_as_advanced(file_cmd)
if(NOT FILE_COMMAND)
message(FATAL_ERROR "warning: No 'file' command, cannot continue...")
endif()
if(file_cmd)
execute_process(COMMAND "${file_cmd}" "${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_cmd} failed: ${file_rv}\n${file_ev}")
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_lower)
# 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_lower)
#message(FATAL_ERROR "file_ov='${file_ov}'")
if("${file_ov_lower}" MATCHES "symbolic link")
set(${result_var1} 1 PARENT_SCOPE)
#Now find where the symlink is linked to.
#Do a regex replace
string(REGEX REPLACE "_file_full_*.*symbolic.link.to." "" symlinked_to ${file_ov})
# message(FATAL_ERROR "file_ov='${file_ov}'")
if("${file_ov_lower}" MATCHES "symbolic link")
set(${result_var1} 1 PARENT_SCOPE)
#Now find where the symlink is linked to.
#Do a regex replace
string(REGEX REPLACE "_file_full_*.*symbolic.link.to." "" symlinked_to ${file_ov})
#older version of file command output has [`} character(remove it).
string(REPLACE "`" "" symlinked_to ${symlinked_to} )
#older version of file command output has {'} character(remove it).
string(REPLACE "'" "" symlinked_to "${symlinked_to}")
#older version of file command output has [`} character(remove it).
string(REPLACE "`" "" symlinked_to ${symlinked_to} )
#strip final output
string(STRIP ${symlinked_to} symlinked_to)
set(${result_var2} "${symlinked_to}" PARENT_SCOPE)
#older version of file command output has {'} character(remove it).
string(REPLACE "'" "" symlinked_to "${symlinked_to}")
#message(FATAL_ERROR "${file_full} is symlinked_to ${symlinked_to}")
return()
endif()
#strip final output
string(STRIP ${symlinked_to} symlinked_to)
set(${result_var2} "${symlinked_to}" PARENT_SCOPE)
else()
message(STATUS "warning: No 'file' command, skipping execute_process...")
#message(FATAL_ERROR "${file_full} is symlinked_to ${symlinked_to}")
return()
endif()
endfunction()
......@@ -325,11 +328,11 @@ macro(setif_value_in_list matched value list)
set(${matched} TRUE)
endif()
endforeach()
#message("'${value}' not found in ${list}")
#message("'${value}' not found in ${list}")
endmacro()
function (get_vars_ending_with suffix result)
get_cmake_property(all_cmake_vars VARIABLES)
string (REGEX MATCHALL "(^|;)[A-Za-z0-9_\\.\\-]*(${suffix})" _matchedVars "${all_cmake_vars}")
set (${result} ${_matchedVars} PARENT_SCOPE)
set(${result} ${_matchedVars} PARENT_SCOPE)
endfunction()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment