Commit 94a4ce76 authored by Rashad Kanavath's avatar Rashad Kanavath

ENH: add custom target to build portable binary package for OTB

parent 4a69ebeb
......@@ -29,11 +29,10 @@ else()
-DWITH_SIMD:BOOL=OFF
-DWITH_TURBOJPEG:BOOL=OFF
-DCMAKE_VERBOSE_MAKEFILE:BOOL=OFF
PATCH_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/patches/${proj}/jconfigint.h.in ${JPEG_SB_SRC}/win/
)
PATCH_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/patches/${proj}/jconfigint.h.in ${JPEG_SB_SRC}/win/ )
else()
ExternalProject_Add(${proj}
PREFIX ${proj}
URL "http://sourceforge.net/projects/libjpeg-turbo/files/1.4.1/libjpeg-turbo-1.4.1.tar.gz"
......@@ -58,6 +57,10 @@ else()
DEPENDEES patch update
DEPENDERS configure )
ExternalProject_Add_Step(${proj} remove_static
COMMAND ${CMAKE_COMMAND} -E remove -f ${SB_INSTALL_PREFIX}/lib/libturbojpeg.a
DEPENDEES install )
endif()
set(_SB_${proj}_INCLUDE_DIR ${SB_INSTALL_PREFIX}/include)
......
set(proj PACKAGE-OTB)
if(NOT __EXTERNAL_${proj}__)
set(__EXTERNAL_${proj}__ 1)
message(STATUS "Setup OTB Packaging...")
SETUP_SUPERBUILD(PROJECT ${proj})
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/${proj}/src/")
# declare dependencies
#set(${proj}_DEPENDENCIES OTB)
#INCLUDE_SUPERBUILD_DEPENDENCIES(${${proj}_DEPENDENCIES})
ExternalProject_Add(${proj}
PREFIX ${proj}
SOURCE_DIR ${PACKAGE-OTB_SB_SRC_DIR}
BINARY_DIR ${PACKAGE-OTB_SB_BUILD_DIR}
INSTALL_DIR ${SB_INSTALL_PREFIX}
DOWNLOAD_COMMAND ""
CMAKE_CACHE_ARGS
-DCMAKE_INSTALL_PREFIX:STRING=${SB_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE:STRING=Release
CMAKE_COMMAND ${SB_CMAKE_COMMAND}
DEPENDS OTB)
endif()
set(PACKAGE_VERSION 5.0.0) #should take from cmake instead of hardcoded value
set(PACKAGE_NAME OTB)
set(PACKAGE_LONG_NAME OrfeoToolBox)
set(ARCHIVE_NAME ${PACKAGE_NAME}-${PACKAGE_VERSION}-Linux64)
set(MAKESELF_SCRIPT ${CMAKE_BINARY_DIR}/PACKAGE-OTB/build/makeself.sh)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/PACKAGE-OTB/build")
file(WRITE "${CMAKE_BINARY_DIR}/PACKAGE-OTB/src/PACKAGE-OTB/CMakeLists.txt"
"cmake_minimum_required(VERSION 2.6)
include(CMakeParseArguments)
set(CMAKE_INSTALL_PREFIX \"${SB_INSTALL_PREFIX}\")
set(DOWNLOAD_LOCATION \"${DOWNLOAD_LOCATION}\")
set(SETUP_SCRIPT_SRC ${CMAKE_SOURCE_DIR}/CMake/pkgsetup.in)
set(OTB_USE_QT4 OFF)
include(${CMAKE_SOURCE_DIR}/CMake/External_pkgtools.cmake)
include(${CMAKE_SOURCE_DIR}/CMake/Package_Macro.cmake)
superbuild_package(
OUTDIR \"${ARCHIVE_NAME}\"
INSTALLDIR \"${SB_INSTALL_PREFIX}\"
PEFILES \"${PEFILES}\"
SEARCHDIRS \"\")")
add_custom_target(PACKAGE-OTB-configure
COMMAND ${CMAKE_COMMAND}
"${CMAKE_BINARY_DIR}/PACKAGE-OTB/src/PACKAGE-OTB"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/PACKAGE-OTB/build" )
add_custom_target(PACKAGE-OTB-build
COMMAND ${CMAKE_COMMAND}
"--build" "${CMAKE_BINARY_DIR}/PACKAGE-OTB/build" "--target" "install"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/PACKAGE-OTB/build"
DEPENDS PACKAGE-OTB-configure)
add_custom_target(PACKAGE-OTB
COMMAND ${MAKESELF_SCRIPT} "--target" "${ARCHIVE_NAME}" "${SB_INSTALL_PREFIX}/${ARCHIVE_NAME}" "${ARCHIVE_NAME}.bin" "${PACKAGE_LONG_NAME} ${PACKAGE_VERSION}" "./pkgsetup"
DEPENDS PACKAGE-OTB-build)
add_custom_target(PACKAGE-OTB-clean
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_BINARY_DIR}/PACKAGE-OTB"
COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.bin"
COMMAND ${CMAKE_COMMAND} "${CMAKE_BINARY_DIR}" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" )
include(ExternalProject)
set(proj PACKAGE-TOOLS)
if(NOT __EXTERNAL_${proj}__)
set(__EXTERNAL_${proj}__ 1)
set(PKGTOOLS_SB_SRC "${CMAKE_BINARY_DIR}/${proj}/src/${proj}")
set(PKGTOOLS_SB_BUILD_DIR "${CMAKE_BINARY_DIR}/${proj}/build/")
ExternalProject_Add(${proj}
PREFIX ${proj}
URL "http://nixos.org/releases/patchelf/patchelf-0.8/patchelf-0.8.tar.gz"
URL_MD5 407b229e6a681ffb0e2cdd5915cb2d01
SOURCE_DIR ${PKGTOOLS_SB_SRC}
BINARY_DIR ${PKGTOOLS_SB_BUILD_DIR}
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
PATCH_COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_INSTALL_PREFIX}/tools
UPDATE_COMMAND ${CMAKE_COMMAND} -E copy_directory ${PKGTOOLS_SB_SRC} ${PKGTOOLS_SB_BUILD_DIR}
CONFIGURE_COMMAND ${PKGTOOLS_SB_BUILD_DIR}/configure --prefix ${CMAKE_INSTALL_PREFIX}/tools
BUILD_COMMAND $(MAKE)
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${PKGTOOLS_SB_BUILD_DIR}/src/patchelf ${CMAKE_INSTALL_PREFIX}/tools )
ExternalProject_Add(makeself
PREFIX makeself
URL "https://www.orfeo-toolbox.org/packages/makeself-2.2.0.tar.gz"
URL_MD5 3c61df934b0c61ddcd7bd63b391e951d
DOWNLOAD_DIR ${DOWNLOAD_LOCATION}
SOURCE_DIR ${PKGTOOLS_SB_BUILD_DIR}/makeself/src
BINARY_DIR ${PKGTOOLS_SB_BUILD_DIR}/makeself/build
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
####${CMAKE_COMMAND} -E copy ${PKGTOOLS_SB_BUILD_DIR}/makeself/src/makeself.lsm ${CMAKE_BINARY_DIR}/makeself.lsm
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMAKE_COMMAND} -E copy ${PKGTOOLS_SB_BUILD_DIR}/makeself/src/makeself-header.sh ${CMAKE_BINARY_DIR}/makeself-header.sh
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${PKGTOOLS_SB_BUILD_DIR}/makeself/src/makeself.sh ${CMAKE_BINARY_DIR}/makeself.sh
DEPENDS ${proj})
endif()
......@@ -2,18 +2,28 @@ macro(superbuild_package)
cmake_parse_arguments(PACKAGE "" "OUTDIR;INSTALLDIR" "SEARCHDIRS;PEFILES" ${ARGN} )
find_program(OBJDUMP_PROGRAM "objdump")
set(PATCHELF_PROGRAM "/home/mrashad/Tools/patchelf-0.8/src/patchelf")
include(GetPrerequisites)
list(APPEND PACKAGE_SEARCHDIRS "${PACKAGE_INSTALLDIR}/bin") #exe
list(APPEND PACKAGE_SEARCHDIRS "${PACKAGE_INSTALLDIR}/lib") #so
list(APPEND PACKAGE_SEARCHDIRS "${PACKAGE_INSTALLDIR}/lib/otb/applications") #otb apps
# install_common()
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${PACKAGE_INSTALLDIR}/${PACKAGE_OUTDIR}")
#install share/gdal, otbcli* otbgui*
install_common()
list(APPEND PACKAGE_PEFILES ${PACKAGE_INSTALLDIR}/bin/otbApplicationLauncherCommandLine)
list(APPEND PACKAGE_PEFILES ${PACKAGE_INSTALLDIR}/bin/otbTestDriver)
if(OTB_USE_QT4)
list(APPEND PACKAGE_PEFILES ${PACKAGE_INSTALLDIR}/bin/otbApplicationLauncherQt)
endif()
file(GLOB otbapps_list ${PACKAGE_INSTALLDIR}/lib/otb/applications/otbapp_*so) # /lib/otb
# list(APPEND PACKAGE_PEFILES ${otbapps_list})
list(APPEND PACKAGE_PEFILES ${otbapps_list})
set(alldlls)
set(notfound_dlls)
......@@ -28,8 +38,12 @@ macro(superbuild_package)
message(FATAL_ERROR "Following dlls were not found: ${notfound_dlls}. Please consider adding their paths to SEARCHDIRS when calling superbuild_package macro.")
endif()
endmacro(superbuild_package)
set(PKG_OUTPUT_DIR "${PACKAGE_INSTALLDIR}/${PACKAGE_OUTDIR}")
configure_file(${SETUP_SCRIPT_SRC}
${PACKAGE_INSTALLDIR}/${PACKAGE_OUTDIR}/pkgsetup @ONLY)
endmacro(superbuild_package)
SET(SYSTEM_DLLS
libm.so
......@@ -40,6 +54,7 @@ SET(SYSTEM_DLLS
libdl.so
libpthread.so
libidn.so
libgomp.so*
)
## http://www.cmake.org/Wiki/CMakeMacroListOperations
......@@ -61,6 +76,10 @@ macro(list_contains var value)
endforeach(value2)
endmacro()
macro(install_rpath_code src_filename)
endmacro()
function(process_deps infile)
get_filename_component(bn ${infile} NAME)
......@@ -73,29 +92,28 @@ function(process_deps infile)
if(EXISTS ${SEARCHDIR}/${infile})
set(DLL_FOUND TRUE)
message(STATUS "Processing ${SEARCHDIR}/${infile}")
#get_filename_component(file_ext ${infile} EXT)
# if("${file_ext}" STREQUAL "${CMAKE_SHARED_LIBRARY_SUFFIX}")
# install(FILES "${SEARCHDIR}/${infile}"
# DESTINATION ${PACKAGE_OUTDIR}/lib)
# add_custom_target(RPATH_${bn}
# INSTALL
# POST_BUILD
# COMMAND ${PATCHELF_PROGRAM} "--set-rpath" "../lib" "${PACKAGE_INSTALLDIR}/${PACKAGE_OUTDIR}/bin/${infile}")
#else() #we assume it is executable
# install(FILES "${SEARCHDIR}/${infile}"
# DESTINATION ${PACKAGE_OUTDIR}/bin)
file(GLOB sofiles "${SEARCHDIR}/${bn}*")
foreach(sofile ${sofiles})
install(TARGETS "${sofile}"
is_file_executable("${SEARCHDIR}/${infile}" is_executable)
if(is_executable)
install(FILES "${SEARCHDIR}/${infile}"
DESTINATION ${PACKAGE_OUTDIR}/bin
PERMISSIONS )
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)
else(is_executable)
if(${infile} MATCHES "otbapp_")
install(FILES "${PACKAGE_INSTALLDIR}/lib/otb/applications/${infile}"
DESTINATION ${PACKAGE_OUTDIR}/lib/otb/applications
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)
else()
get_filename_component(bn_we ${infile} NAME_WE)
file(GLOB sofiles "${SEARCHDIR}/${bn_we}*")
foreach(sofile ${sofiles})
install(FILES "${sofile}"
DESTINATION ${PACKAGE_OUTDIR}/lib
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)
endforeach()
#endif()
endif()
endif(is_executable)
if(NOT EXISTS ${OBJDUMP_PROGRAM})
message(FATAL_ERROR "objdump executable not found. please check OBJDUMP_PROGRAM is set to correct cross compiled executable")
endif()
......@@ -124,44 +142,40 @@ function(process_deps infile)
set(notfound_dlls "${notfound_dlls}" PARENT_SCOPE )
endif()
endfunction()
function(install_common)
set(OUT_DIR "${PACKAGE_OUTDIR}")
set(BIN_DIR "${OUTDIR}/bin")
set(OTBLIBS_DIR "${OUTDIR}/lib/otb")
set(DATA_DIR "${OUTDIR}/share")
set(BIN_DIR "${OUT_DIR}/bin")
set(OTBAPPS_DIR "${OUT_DIR}/lib/otb")
set(DATA_DIR "${OUT_DIR}/share")
####################### install GDAL data #######################
####################### install GDAL data ###########################
find_path(GDAL_DATA epsg.wkt ${PACKAGE_INSTALLDIR}/share/gdal)
install(DIRECTORY ${GDAL_DATA}
DESTINATION ${DATA_DIR})
####################### Check otb applications #######################
file(GLOB OTB_APPS_LIST ${PACKAGE_INSTALLDIR}/lib/otb/applications/otbapp_*so) # /lib/otb
if(NOT OTB_APPS_LIST)
message(FATAL_ERROR "No OTB-applications detected")
endif()
####################### install otb applications #######################
install(DIRECTORY "${PACKAGE_INSTALLDIR}/lib/otb/applications"
DESTINATION ${OTBLIBS_DIR})
####################### install patchelf #####################
install(FILES ${PACKAGE_INSTALLDIR}/tools/patchelf
DESTINATION ${OUT_DIR}/tools
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ
)
####################### install otbcli scripts #######################
file(GLOB CLI_SCRIPTS ${SB_INSTALL_DIR}/bin/otbcli*)
####################### install otbcli scripts ######################
file(GLOB CLI_SCRIPTS ${PACKAGE_INSTALLDIR}/bin/otbcli*)
foreach(CLI_SCRIPT ${CLI_SCRIPTS})
install(FILES "${CLI_SCRIPT}"
DESTINATION ${BIN_DIR})
DESTINATION ${BIN_DIR}
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)
endforeach()
####################### install otbgui scripts #######################
####################### install otbgui scripts ######################
if(OTB_USE_QT4)
file(GLOB GUI_SCRIPTS ${SB_INSTALL_DIR}/bin/otbgui*)
file(GLOB GUI_SCRIPTS ${PACKAGE_INSTALLDIR}/bin/otbgui*)
foreach(GUI_SCRIPT ${GUI_SCRIPTS})
install(FILES "${GUI_SCRIPT}"
DESTINATION ${BIN_DIR})
DESTINATION ${BIN_DIR}
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)
endforeach()
endif()
......
#!/bin/bash
cd `dirname $0`
OUT=`pwd`
PATCH_ELF_EXE=$OUT/tools/patchelf
#setup bin and lib dirs
INSTALL_LIBDIRS=$OUT/lib
INSTALL_BINDIRS=$OUT/bin
echo "Configuring..."
#run patchelf to set rpath
for lib in $INSTALL_LIBDIRS/*.so*; do
# echo "adding rpath to $lib"
$PATCH_ELF_EXE --set-rpath "$OUT/lib" $lib;
done
#run patchelf on otbapp_
for lib in $INSTALL_LIBDIRS/otb/applications/*.so*; do
# echo "adding rpath to $lib"
$PATCH_ELF_EXE --set-rpath "$OUT/lib" $lib;
done
#run patchelf on otb executables
for bin in "$INSTALL_BINDIRS/otbTestDriver" "`ls $INSTALL_BINDIRS/otbApplicationLaunch*`"; do
# echo "adding rpath to $bin"
$PATCH_ELF_EXE --set-rpath "$OUT/lib" $bin;
done
rm -fr $OUT/tools
rm -f $OUT/pkgsetup
......@@ -177,22 +177,6 @@ include(External_otb)
#check compiler is gnu?
if(UNIX AND NOT APPLE)
# include(External_package)
# set(ARCHIVE_NAME OTB-5.0.0-Linux64)
# file(GLOB PEFILES
# ${CMAKE_INSTALL_PREFIX}/bin/otbApplicationLaunch*
# ${CMAKE_INSTALL_PREFIX}/bin/otbTestDriver )
# file(WRITE "${CMAKE_BINARY_DIR}/PACKAGE-OTB/src/PACKAGE-OTB/CMakeLists.txt"
# "cmake_minimum_required(VERSION 2.6)
# include(CMakeParseArguments)
# set(CMAKE_INSTALL_PREFIX \"${SB_INSTALL_PREFIX}\")
# include(${CMAKE_SOURCE_DIR}/CMake/Package_Macro.cmake)
# superbuild_package(
# OUTDIR \"${ARCHIVE_NAME}\"
# INSTALLDIR \"${SB_INSTALL_PREFIX}\"
# PEFILES \"${PEFILES}\"
# SEARCHDIRS \"\")")
include(External_package)
endif(UNIX AND NOT APPLE)
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