Commit 5fd8f268 authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

PKG: JIRA:997 Generate XDK and OTB package with custom target

parent d32ddc81
......@@ -2,7 +2,7 @@ include(ExternalProject)
if(NOT __EXTERNAL_PACKAGE_TOOLS__)
set(__EXTERNAL_PACKAGE_TOOLS__ 1)
set(PKGTOOLS_SB_PREFIX_DIR "${CMAKE_BINARY_DIR}/PACKAGE-OTB/PACKAGE_TOOLS")
set(PKGTOOLS_SB_PREFIX_DIR "${CMAKE_BINARY_DIR}/TOOLS-PACKAGE")
ExternalProject_Add(MAKESELF
PREFIX "${PKGTOOLS_SB_PREFIX_DIR}"
......@@ -17,22 +17,18 @@ ExternalProject_Add(MAKESELF
BUILD_COMMAND ${CMAKE_COMMAND}
-E copy
${PKGTOOLS_SB_PREFIX_DIR}/src-makeself/makeself-header.sh
${CMAKE_BINARY_DIR}/PACKAGE-OTB/build/makeself-header.sh
${PKGTOOLS_SB_PREFIX_DIR}/makeself-header.sh
INSTALL_COMMAND ${CMAKE_COMMAND}
-E copy
${PKGTOOLS_SB_PREFIX_DIR}/src-makeself/makeself.sh
${CMAKE_BINARY_DIR}/PACKAGE-OTB/build/makeself.sh
${PKGTOOLS_SB_PREFIX_DIR}/makeself.sh
)
set(MAKESELF_SCRIPT ${PKGTOOLS_SB_PREFIX_DIR}/makeself.sh)
if(UNIX)
if(APPLE)
ExternalProject_Add( PATCHELF
PREFIX "${PKGTOOLS_SB_PREFIX_DIR}"
DOWNLOAD_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
add_custom_target(PATCHELF)
else()
ExternalProject_Add(PATCHELF
PREFIX "${PKGTOOLS_SB_PREFIX_DIR}"
......@@ -52,12 +48,6 @@ if(UNIX)
endif(APPLE)
endif(UNIX)
ExternalProject_Add( PACKAGE_TOOLS
PREFIX "${PKGTOOLS_SB_PREFIX_DIR}"
DOWNLOAD_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
DEPENDS MAKESELF PATCHELF)
add_custom_target(PACKAGE-TOOLS DEPENDS MAKESELF PATCHELF)
endif()
macro(superbuild_package)
cmake_parse_arguments(PKG "" "STAGE_DIR;XDK" "SEARCHDIRS" ${ARGN} )
cmake_parse_arguments(PKG "" "STAGE_DIR" "SEARCHDIRS" ${ARGN} )
if(APPLE)
set(loader_program_names otool)
......@@ -68,7 +68,7 @@ macro(superbuild_package)
endif()
endif()
if(PKG_XDK)
if(PKG_GENERATE_XDK)
install_xdk_files()
endif()
......@@ -120,20 +120,20 @@ function(process_deps infile)
#message("${sofile} is a symlink to ${linked_to_file}")
else() # is_symlink
if("${basename_of_sofile}" MATCHES "otbapp_")
if(NOT MAKE_XDK)
if(NOT PKG_GENERATE_XDK)
install(FILES "${sofile}" DESTINATION ${PKG_STAGE_DIR}/lib/otb/applications)
endif()
else() #if(.. MATCHES "otbapp_")
#if we are making xdk. skill all those starting with libotb case insensitively
if(MAKE_XDK)
if(PKG_GENERATE_XDK)
string(TOLOWER "${basename_of_sofile}" sofile_lower )
if(NOT "${sofile_lower}" MATCHES "libotb")
install(FILES "${sofile}" DESTINATION ${PKG_STAGE_DIR}/lib)
endif()
else() #MAKE_XDK
else() #PKG_GENERATE_XDK
#just install the so file to <staging-dir>/lib
install(FILES "${sofile}" DESTINATION ${PKG_STAGE_DIR}/lib)
endif() #MAKE_XDK
endif() #PKG_GENERATE_XDK
# Finally touch a file in temp directory for globbing later
# message("touching ${basename_of_sofile}")
......
......@@ -251,9 +251,6 @@ endif()
if(GENERATE_PACKAGE)
if(UNIX)
if(GENERATE_XDK)
include(GenerateXDK)
endif()
include(External_package)
endif(UNIX)
add_subdirectory(Packaging)
endif()
endif()
\ No newline at end of file
##### check if standalone project ######
if(NOT PROJECT_NAME)
cmake_minimum_required(VERSION 2.6)
include(CMakeParseArguments)
project(OTBPackaging)
endif()
set(OUT_OF_SOURCE_BUILD FALSE)
if(PROJECT_NAME STREQUAL "OTBPackaging")
set(OUT_OF_SOURCE_BUILD TRUE)
endif()
if(OUT_OF_SOURCE_BUILD)
if(BUILD_TESTING)
include(CTest)
endif()
set(SUPERBUILD_BINARY_DIR "" CACHE PATH "path to superbuild binary directory")
option(GENERATE_XDK "Generate XDK for OTB development" OFF)
option(ENABLE_MONTEVERDI "enable monteverdi" ON)
set(DOWNLOAD_LOCATION "" CACHE PATH "path to superbuild binary directory")
set(SB_INSTALL_PREFIX "" CACHE PATH "path to superbuild install directory")
else()
set(SUPERBUILD_BINARY_DIR ${CMAKE_BINARY_DIR})
endif()
set(CMAKE_INSTALL_PREFIX "${SB_INSTALL_PREFIX}")
set(PACKAGE_NAME OTB)
set(PACKAGE_LONG_NAME OrfeoToolBox)
if(UNIX)
if(APPLE)
set(PACKAGE_PLATFORM_NAME "Darwin")
else()
set(PACKAGE_PLATFORM_NAME "Linux")
endif()
endif()
set(PACKAGE_ARCH 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PACKAGE_ARCH 64)
endif()
get_filename_component(OTB_SUPERBUILD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} PATH)
get_filename_component(OTB_SOURCE_DIR ${OTB_SUPERBUILD_SOURCE_DIR} PATH)
include(version_macro.cmake)
get_version("${OTB_SUPERBUILD_SOURCE_DIR}/CMake/External_itk.cmake" "ITK_SB_VERSION" ITK_SB_VERSION)
get_version("${OTB_SOURCE_DIR}/CMakeLists.txt" "OTB_VERSION_" OTB_VERSION_STRING)
set(PACKAGE_LIST OTB)
if(GENERATE_XDK)
list(APPEND PACKAGE_LIST XDK)
endif()
include(${OTB_SUPERBUILD_SOURCE_DIR}/CMake/External_pkgtools.cmake)
foreach(PACKAGE ${PACKAGE_LIST})
#message( "-- To get ${PACKAGE} package. Run 'make PACKAGE-${PACKAGE}'")
message( "-- Configuring ${PACKAGE} package")
set(PACKAGE_PROJECT_DIR ${CMAKE_BINARY_DIR}/${PACKAGE}-PACKAGE)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${PACKAGE_PROJECT_DIR}/build")
#Easy way to have the write "PACKAGE_PROJECT_DIR/src/PACKAGE-${PACKAGE}/CMakeLists.txt"
#inside foreach()
if("${PACKAGE}" STREQUAL "XDK")
set(PACKAGE_PLATFORM_NAME "xdk-${PACKAGE_PLATFORM_NAME}")
set(PKG_GENERATE_XDK ON)
else()
set(PKG_GENERATE_XDK OFF)
endif()
set(ARCHIVE_NAME ${PACKAGE_NAME}-${get_version_OTB_VERSION_STRING}-${PACKAGE_PLATFORM_NAME}${PACKAGE_ARCH})
file(WRITE "${PACKAGE_PROJECT_DIR}/src/PACKAGE-${PACKAGE}/CMakeLists.txt"
"cmake_minimum_required(VERSION 2.6)
include(CMakeParseArguments)
set(CMAKE_INSTALL_PREFIX \"${SB_INSTALL_PREFIX}\")
set(DOWNLOAD_LOCATION \"${DOWNLOAD_LOCATION}\")
set(PACKAGE_SUPPORT_FILES_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\")
set(Monteverdi_SOURCE_DIR \"${SUPERBUILD_BINARY_DIR}/MVD/src/MVD\")
set(Monteverdi_BINARY_DIR \"${SUPERBUILD_BINARY_DIR}/MVD/build\")
set(OTB_INSTALL_DIR \"${SUPERBUILD_BINARY_DIR}/OTB/build\")
set(QT_PLUGINS_DIR \"${SB_INSTALL_PREFIX}/plugins\")
set(QT_TRANSLATIONS_DIR \"${SB_INSTALL_PREFIX}/translations\")
set(ITK_VERSION_STRING \"${get_version_ITK_SB_VERSION}\")
set(PKG_GENERATE_XDK ${PKG_GENERATE_XDK})
include(\"${OTB_SUPERBUILD_SOURCE_DIR}/CMake/Package_Macro.cmake\")
include(\"${OTB_SUPERBUILD_SOURCE_DIR}/CMake/PackageHelper.cmake\")
superbuild_package(STAGE_DIR \"${ARCHIVE_NAME}\")")
#we have a dependency to PACKAGE_TOOLS always. check External_pkgtools.cmake
set(PACKAGE-${PACKAGE}-configure_EXTRA_DEPENDS PACKAGE-TOOLS)
#if we are building packages seperately we need to check OTB and MVD buil
if(OUT_OF_SOURCE_BUILD)
add_custom_target(PACKAGE-${PACKAGE}-check-otb
COMMAND ${CMAKE_COMMAND} --build "${SUPERBUILD_BINARY_DIR}/OTB/build"
WORKING_DIRECTORY "${SUPERBUILD_BINARY_DIR}/OTB/build"
)
if(ENABLE_MONTEVERDI)
add_custom_target(PACKAGE-${PACKAGE}-check-monteverdi
COMMAND ${CMAKE_COMMAND} --build "${SUPERBUILD_BINARY_DIR}/MVD/build"
WORKING_DIRECTORY "${SUPERBUILD_BINARY_DIR}/MVD/build"
DEPENDS PACKAGE-${PACKAGE}-check-otb
)
list(APPEND
PACKAGE-${PACKAGE}-configure_EXTRA_DEPENDS
PACKAGE-${PACKAGE}-check-monteverdi)
else(ENABLE_MONTEVERDI)
#just add only check-otb target to extra depends
list(APPEND
PACKAGE-${PACKAGE}-configure_EXTRA_DEPENDS
PACKAGE-${PACKAGE}-check-otb)
endif(ENABLE_MONTEVERDI)
else(OUT_OF_SOURCE_BUILD)
list(APPEND
PACKAGE-${PACKAGE}-configure_EXTRA_DEPENDS
OTB)
if(ENABLE_MONTEVERDI)
list(APPEND
PACKAGE-${PACKAGE}-configure_EXTRA_DEPENDS
MVD)
endif(ENABLE_MONTEVERDI)
endif(OUT_OF_SOURCE_BUILD)
set(PACKAGE-${PACKAGE}-configure_EXTRA_DEPENDS)
add_custom_target(PACKAGE-${PACKAGE}-configure
COMMAND ${CMAKE_COMMAND}
"${PACKAGE_PROJECT_DIR}/src/PACKAGE-${PACKAGE}"
WORKING_DIRECTORY "${PACKAGE_PROJECT_DIR}/build"
DEPENDS
${PACKAGE-${PACKAGE}-configure_EXTRA_DEPENDS}
)
add_custom_target(PACKAGE-${PACKAGE}-build
COMMAND ${CMAKE_COMMAND}
"--build" "${PACKAGE_PROJECT_DIR}/build" "--target" "install"
WORKING_DIRECTORY "${PACKAGE_PROJECT_DIR}/build"
DEPENDS PACKAGE-${PACKAGE}-configure
)
add_custom_target(PACKAGE-${PACKAGE}
ALL DEPENDS
COMMAND
${MAKESELF_SCRIPT}
"--target"
"${ARCHIVE_NAME}"
"${SB_INSTALL_PREFIX}/${ARCHIVE_NAME}"
"${ARCHIVE_NAME}.run"
"${PACKAGE_LONG_NAME} ${get_version_OTB_VERSION_STRING}"
"./pkgsetup"
DEPENDS PACKAGE-${PACKAGE}-build
)
add_custom_target(PACKAGE-${PACKAGE}-clean
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_BINARY_DIR}/${PACKAGE}-PACKAGE"
COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.run"
COMMAND ${CMAKE_COMMAND} "${CMAKE_BINARY_DIR}" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
endforeach()
\ No newline at end of file
#macro: get_version
#args :
# input_file - Input cmake file where the version variable is set via cmake set() command.
# Example: ${OTB_SUPERBUILD_SOURCE_DIR}/CMake/External_itk.cmake
#match_string - A match string to filter out required set() commands.
# Example: "ITK_SB_VERSION" will get all set(ITK_SB_VERSION_MAJOR)
# set(ITK_SB_VERSION_MINOR) set(ITK_SB_VERSION_PATCH)
# cmake_var_to_check - Name of variable that has the version string stored using set(..)
# command inside the input_file.
# Example: ITK_SB_VERSION. This is same as match_string but not always
# Sample usage:
# get_version(
# "${OTB_SUPERBUILD_SOURCE_DIR}/CMake/External_itk.cmake"
# "ITK_SB_VERSION"
# ITK_SB_VERSION)
macro(get_version input_file match_string check_cmake_var)
if(EXISTS "${input_file}")
file(STRINGS "${input_file}" _version_vars REGEX "set\\\(${match_string}")
set(temp_file_name "${CMAKE_BINARY_DIR}/CMakeFiles/version_vars_${match_string}.cmake")
file(WRITE "${temp_file_name}" "#version\n")
foreach(_version_var ${_version_vars})
file(APPEND "${temp_file_name}" "${_version_var}\n")
endforeach()
include("${temp_file_name}")
if(${check_cmake_var})
set(get_version_${check_cmake_var} "${${check_cmake_var}}")
else()
message(FATAL_ERROR "macro(get_version): Cannot find ${check_cmake_var}!")
endif()
else()
message(FATAL_ERROR "macro(get_version): File '${input_file}' does not exists")
endif()
endmacro()
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