CMakeLists.txt 6.13 KB
Newer Older
1 2 3 4 5
# cpack has a built-in target called 'package'. In our case we create two standalone installers with
# and uses a custom target named packages.

# stop generation of msvc packages for windows. 04-apr-2016. point OTB.

6 7 8 9 10 11 12
##### check if standalone project ######
if(NOT PROJECT_NAME)
  cmake_minimum_required(VERSION 2.6)
  include(CMakeParseArguments)
  project(OTBPackaging)
endif()

13
option(GENERATE_PACKAGE "Generate OTB package" OFF)
14 15
option(GENERATE_XDK "Generate XDK for OTB development" OFF)

16 17 18
set(OUT_OF_SOURCE_BUILD FALSE)
if(PROJECT_NAME STREQUAL "OTBPackaging")
  set(OUT_OF_SOURCE_BUILD TRUE)
19
  set(GENERATE_PACKAGE ON)
20
endif()
21 22 23 24 25 26

if(NOT GENERATE_PACKAGE AND NOT GENERATE_XDK)
  #well. we don't have any businees here. Let's move on..
  return()
endif()

27 28 29 30 31 32 33 34 35 36
if(WIN32 OR CMAKE_CROSSCOMPILING)
  if(NOT MXE_TARGET_DIR)
    message(FATAL_ERROR "you must set MXE_TARGET_DIR")
  endif()

  if(NOT OTB_SOURCE_DIR)
    message(FATAL_ERROR "you must set OTB_SOURCE_DIR")
  endif()
endif()

37 38
include(${CMAKE_CURRENT_SOURCE_DIR}/PMacros.cmake)

39 40 41 42
if(OUT_OF_SOURCE_BUILD)
  if(BUILD_TESTING)
    include(CTest)
  endif()
43 44 45
  if(WIN32 OR CMAKE_CROSSCOMPILING)
    set(Monteverdi_SOURCE_DIR "" CACHE PATH "monteverdi source directory")
    set(Monteverdi_BINARY_DIR "" CACHE PATH "monteverdi binary directory")
46
    set(MONTEVERDI_INSTALL_DIR "" CACHE PATH "monteverdi install directory")
47
    set(OTB_INSTALL_DIR "" CACHE PATH "otb install directory")
48 49 50 51 52 53
  else()
    set(SUPERBUILD_BINARY_DIR "" CACHE PATH "path to superbuild binary directory")
    set(SUPERBUILD_INSTALL_DIR "" CACHE PATH "path to superbuild install directory")
    option(ENABLE_MONTEVERDI "enable monteverdi" ON)
    set(DOWNLOAD_LOCATION "" CACHE PATH "path to superbuild binary directory")
  endif()
54
else(OUT_OF_SOURCE_BUILD)
55 56 57
  # SUPERBUILD_BINARY_DIR is only set in Packaging/CMakeLists.txt and not available
  # in the parent scope like others. So we need to set it as CMAKE_BINARY_DIR
  # if doing packages from source tree.
58
  set(SUPERBUILD_BINARY_DIR ${CMAKE_BINARY_DIR})
59
  set(SUPERBUILD_INSTALL_DIR ${SB_INSTALL_PREFIX})
60 61
  if(WIN32 OR CMAKE_CROSSCOMPILING)
    set(MONTEVERDI_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
62
    set(OTB_INSTALL_DIR "${OTB_MODULES_DIR}/../../../..")
63 64
  endif()
endif(OUT_OF_SOURCE_BUILD)
65

66 67 68 69 70 71 72 73
get_filename_component(SUPERBUILD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} PATH)
get_filename_component(OTB_SOURCE_DIR ${SUPERBUILD_SOURCE_DIR} PATH)

if(WIN32 OR CMAKE_CROSSCOMPILING)
  foreach(req
      Monteverdi_SOURCE_DIR
      Monteverdi_BINARY_DIR
      MONTEVERDI_INSTALL_DIR
74
      OTB_INSTALL_DIR
75 76
      )
    if(NOT DEFINED ${req} OR "${${req}}" STREQUAL "")
77
      message(FATAL_ERROR "you must set ${req}")
78 79 80
    endif()
    set(vars "${vars}  ${req}=[${${req}}]\n")
  endforeach(req)
81 82 83 84 85 86

  find_program(ZIP_EXECUTABLE zip)
  if(NOT ZIP_EXECUTABLE)
    message(FATAL_ERROR "Cannot find zip executable. Please add it to your path")
  endif()

87 88 89 90 91 92 93 94
else() #Unix like
  foreach(req
      SUPERBUILD_BINARY_DIR
      SUPERBUILD_INSTALL_DIR
      SUPERBUILD_SOURCE_DIR
      OTB_SOURCE_DIR
      )
    if(NOT DEFINED ${req} OR "${${req}}" STREQUAL "")
95
      message(FATAL_ERROR "you must set ${req}")
96 97 98
    endif()
    set(vars "${vars}  ${req}=[${${req}}]\n")
  endforeach(req)
99 100
endif()

101 102

if(WIN32 OR CMAKE_CROSSCOMPILING)
103
  set(CMAKE_INSTALL_PREFIX "${MONTEVERDI_INSTALL_DIR}")
104 105 106
else()
  set(CMAKE_INSTALL_PREFIX "${SUPERBUILD_INSTALL_DIR}")
endif()
107 108 109

set(PACKAGE_NAME OTB)
set(PACKAGE_LONG_NAME OrfeoToolBox)
110 111 112 113 114 115 116 117
if(WIN32 OR CMAKE_CROSSCOMPILING)
  set(PACKAGE_PLATFORM_NAME "win")
  if(MXE_TARGET_DIR MATCHES "i686")
    set(MXE_ARCH "i686")
    set(PACKAGE_ARCH "32")
  elseif(MXE_TARGET_DIR MATCHES "x86_64")
    set(MXE_ARCH "x86_64")
    set(PACKAGE_ARCH "64") #helper for ARCHIVE_NAME
118
  endif()
119 120 121 122 123 124 125 126 127 128 129 130 131 132
  get_filename_component(MXE_MXEROOT ${MXE_TARGET_DIR} PATH)
  get_filename_component(MXE_MXEROOT ${MXE_MXEROOT} PATH)
  set(PACKAGE_VERSION_STRING ${OTB_VERSION_MAJOR}.${OTB_VERSION_MINOR}.${OTB_VERSION_PATCH})
else() #(WIN32 OR CMAKE_CROSSCOMPILING)
  if(UNIX)
    set(PACKAGE_ARCH 32)
    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
      set(PACKAGE_ARCH 64)
    endif()
    if(APPLE)
      set(PACKAGE_PLATFORM_NAME "Darwin")
    else()
      set(PACKAGE_PLATFORM_NAME "Linux")
    endif()
133
    get_version("${SUPERBUILD_SOURCE_DIR}/CMake/External_itk.cmake" "ITK_SB_VERSION" ITK_SB_VERSION)
134 135
  endif(UNIX)
endif() #(WIN32 OR CMAKE_CROSSCOMPILING)
136

137 138 139
get_version("${OTB_SOURCE_DIR}/CMakeLists.txt" "OTB_VERSION_" OTB_VERSION_STRING)
set(PACKAGE_VERSION_STRING ${get_version_OTB_VERSION_STRING})

140
include(${SUPERBUILD_SOURCE_DIR}/CMake/External_pkgtools.cmake)
141

142 143 144 145
set(EXTRA_CACHE_CONFIG
  "set(CMAKE_CROSSCOMPILING ON)
   set(MXE_ARCH \"${MXE_ARCH}\")
   set(MXE_MXEROOT \"${MXE_MXEROOT}\")")
146

147 148 149 150 151 152
#guess install directory from OTB_MODULES_DIR
#copy of cmake variables not needed.
if(WIN32 OR CMAKE_CROSSCOMPILING)
  set(Monteverdi_SOURCE_DIR       "${Monteverdi_SOURCE_DIR}")
  set(Monteverdi_BINARY_DIR       "${Monteverdi_BINARY_DIR}")
  set(MONTEVERDI_INSTALL_DIR      "${MONTEVERDI_INSTALL_DIR}")
153
  set(OTB_INSTALL_DIR             "${OTB_INSTALL_DIR}")
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
  set(DEPENDENCIES_INSTALL_DIR    "${MXE_MXEROOT}/usr/${MXE_ARCH}-w64-mingw32.shared")
  set(QT_PLUGINS_DIR              "${DEPENDENCIES_INSTALL_DIR}/qt/plugins")
  set(QT_TRANSLATIONS_DIR         "${DEPENDENCIES_INSTALL_DIR}/qt/translations")
  set(ITK_VERSION_STRING)
  else() #unixes
    set(Monteverdi_SOURCE_DIR     "${SUPERBUILD_BINARY_DIR}/MVD/src/MVD")
    set(Monteverdi_BINARY_DIR     "${SUPERBUILD_BINARY_DIR}/MVD/build")
    set(MONTEVERDI_INSTALL_DIR    "${SUPERBUILD_INSTALL_DIR}")
    set(QT_PLUGINS_DIR            "${SUPERBUILD_INSTALL_DIR}/plugins")
    set(QT_TRANSLATIONS_DIR       "${SUPERBUILD_INSTALL_DIR}/translations")
    set(OTB_INSTALL_DIR           "${SUPERBUILD_BINARY_DIR}/OTB/build")
    set(DEPENDENCIES_INSTALL_DIR  "${SUPERBUILD_INSTALL_DIR}")
    set(ITK_VERSION_STRING        "${get_version_ITK_SB_VERSION}")
    set(EXTRA_CACHE_CONFIG)
  endif()
169

170 171 172 173
macro_setup_cmake_sources(OTB)
if(GENERATE_XDK)
  macro_setup_cmake_sources(XDK)
endif()
174

175 176
set(PACKAGE-configure_DEPENDS PACKAGE-TOOLS)
macro_update_dependencies_list(PACKAGE-configure_DEPENDS)
177

178 179 180 181
macro_create_targets_for_package(OTB)
if(GENERATE_XDK)
macro_create_targets_for_package(XDK)
endif()