CMakeLists.txt 20 KB
Newer Older
1
cmake_minimum_required(VERSION 2.8.11)
2 3 4

foreach(p
    CMP0025 # CMake 3.0
5
    CMP0042 # CMake 3.0
6
    CMP0058
7 8 9 10 11 12
    )
  if(POLICY ${p})
    cmake_policy(SET ${p} NEW)
  endif()
endforeach()

13
# CMP0046 : from CMake 3.0, old behaviour is more convenient
14 15 16
if(POLICY CMP0046)
  cmake_policy(SET CMP0046 OLD)
endif()
17

18 19 20 21 22 23
# TODO Check if OTB cmake is compatible with CMP0054 NEW policy
# CMP0054 : New policy introduce in CMake 3.1, keep old behaviour for now
if(POLICY CMP0054)
  cmake_policy(SET CMP0054 OLD)
endif()

24 25 26 27 28 29 30
project(OTB)

include(CMakeDependentOption)
#
# use ExternalProject
include(ExternalProject)

Rashad Kanavath's avatar
Rashad Kanavath committed
31 32 33 34 35
#mantis: 1193
if(APPLE)
  set(CMAKE_SYSTEM_FRAMEWORK_PATH "" CACHE PATH "" FORCE)
endif()

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
if( CMAKE_HOST_WIN32 )

  string( LENGTH "${CMAKE_CURRENT_SOURCE_DIR}" n )
  if( n GREATER 50 )
    message(
      FATAL_ERROR
      "OTB source code directory path length is too long (${n} > 50)."
      "Please move the OTB source code directory to a directory with a shorter path."
      )
  endif()

  string( LENGTH "${CMAKE_CURRENT_BINARY_DIR}" n )
  if( n GREATER 50 )
    message(
      FATAL_ERROR
      "OTB build directory path length is too long (${n} > 50)."
      "Please set the OTB build directory to a directory with a shorter path."
      )
  endif()

endif()

58 59
set(OTB_CMAKE_DIR ${OTB_SOURCE_DIR}/CMake)
set(CMAKE_MODULE_PATH ${OTB_CMAKE_DIR} ${CMAKE_MODULE_PATH})
60
include (SourceStatus)
61 62 63 64
include(PreventInSourceBuilds)
include(PreventInBuildInstalls)
include(OTBModuleMacros)
include(OTBModuleRemote)
65
include(OTBModuleTest)
66 67 68
include( i18n_qt4 )

reset_qt4_i18n_sources()
69

70 71 72 73 74 75 76 77 78 79 80 81 82 83
repository_status(${PROJECT_SOURCE_DIR} OTB_GIT_STATUS_MESSAGE)

#-----------------------------------------------------------------------------
# Configure the default OTB_DATA_ROOT for the location of OTB Data.
find_path(OTB_DATA_ROOT
  NAMES README-OTB-Data
  HINTS $ENV{OTB_DATA_ROOT} ${OTB_SOURCE_DIR}/../OTB-Data
)
mark_as_advanced(OTB_DATA_ROOT)

if(OTB_DATA_ROOT)
  repository_status(${OTB_DATA_ROOT} OTB_DATA_GIT_STATUS_MESSAGE)
endif()

84 85 86 87
set(main_project_name ${_OTBModuleMacros_DEFAULT_LABEL})

#-----------------------------------------------------------------------------
# OTB version number.
88
set(OTB_VERSION_MAJOR "5")
89
set(OTB_VERSION_MINOR "11")
90
set(OTB_VERSION_PATCH "0")
91
set(OTB_VERSION_STRING "${OTB_VERSION_MAJOR}.${OTB_VERSION_MINOR}.${OTB_VERSION_PATCH}")
92

93 94 95 96 97 98 99 100 101 102 103
# Monteverdi version number (follows OTB)
set( Monteverdi_VERSION_MAJOR ${OTB_VERSION_MAJOR} )
set( Monteverdi_VERSION_MINOR ${OTB_VERSION_MINOR} )
set( Monteverdi_VERSION_PATCH ${OTB_VERSION_PATCH} )
set( Monteverdi_VERSION_SUFFIX "" )

set( Monteverdi_VERSION_STRING
  "${Monteverdi_VERSION_MAJOR}.${Monteverdi_VERSION_MINOR}.${Monteverdi_VERSION_PATCH}${Monteverdi_VERSION_SUFFIX}"
  )

#-----------------------------------------------------------------------------
104 105
string(TIMESTAMP OTB_BUILD_TIMESTAMP)

106 107 108 109 110 111 112 113 114 115 116 117 118
if(NOT OTB_INSTALL_RUNTIME_DIR)
  set(OTB_INSTALL_RUNTIME_DIR bin)
endif()
if(NOT OTB_INSTALL_LIBRARY_DIR)
  set(OTB_INSTALL_LIBRARY_DIR lib)
endif()
if(NOT OTB_INSTALL_ARCHIVE_DIR)
  set(OTB_INSTALL_ARCHIVE_DIR lib)
endif()
if(NOT OTB_INSTALL_INCLUDE_DIR)
  set(OTB_INSTALL_INCLUDE_DIR include/OTB-${OTB_VERSION_MAJOR}.${OTB_VERSION_MINOR})
endif()
if(NOT OTB_INSTALL_APP_DIR)
119
  set(OTB_INSTALL_APP_DIR "lib/otb/applications")
120 121
endif()
if(NOT OTB_INSTALL_PYTHON_DIR)
122
  set(OTB_INSTALL_PYTHON_DIR "lib/otb/python")
123 124
endif()
if(NOT OTB_INSTALL_JAVA_DIR)
125
  set(OTB_INSTALL_JAVA_DIR "lib/otb/java")
126 127 128 129 130 131 132 133 134 135 136
endif()
if(NOT OTB_INSTALL_DATA_DIR)
  set(OTB_INSTALL_DATA_DIR share/OTB-${OTB_VERSION_MAJOR}.${OTB_VERSION_MINOR})
endif()
if(NOT OTB_INSTALL_DOC_DIR)
  set(OTB_INSTALL_DOC_DIR share/doc/OTB-${OTB_VERSION_MAJOR}.${OTB_VERSION_MINOR})
endif()
if(NOT OTB_INSTALL_PACKAGE_DIR)
  set(OTB_INSTALL_PACKAGE_DIR "${OTB_INSTALL_LIBRARY_DIR}/cmake/OTB-${OTB_VERSION_MAJOR}.${OTB_VERSION_MINOR}")
endif()

137 138 139
#convert path to native for reconfiguring otbcli.bat.in
file(TO_NATIVE_PATH "${OTB_INSTALL_APP_DIR}" OTB_INSTALL_APP_DIR_NATIVE)

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
# Override CMake's built-in add_* commands: assign LABELS to tests and targets
# automatically. Depends on the CMake variable otb-module being set to the
# "current" module when add_* is called.
macro(verify_otb_module_is_set)
  if("" STREQUAL "${otb-module}")
    message(FATAL_ERROR "CMake variable otb-module is not set")
  endif()
endmacro()

#-----------------------------------------------------------------------------
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "Setting build type to 'Release' as none was specified.")
  set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
  # Set the possible values of build type for cmake-gui
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()


#-----------------------------------------------------------------------------
# Enable running cppcheck for each module on its source and test directories.
option(OTB_CPPCHECK_TEST "Run cppcheck for static code analysis" OFF)
mark_as_advanced(OTB_CPPCHECK_TEST)

#-----------------------------------------------------------------------------
# Forbid downloading resources from the network during a build. This helps
# when building on systems without network connectivity to determine which
# resources much be obtained manually and made available to the build.
option(OTB_FORBID_DOWNLOADS "Do not download source code or data from the network" OFF)
mark_as_advanced(OTB_FORBID_DOWNLOADS)
macro(otb_download_attempt_check _name)
  if(OTB_FORBID_DOWNLOADS)
    message(SEND_ERROR "Attempted to download ${_name} when OTB_FORBID_DOWNLOADS is ON")
  endif()
endmacro()

# TODO : handle shared libs on windows
option(BUILD_SHARED_LIBS "Build OTB with shared libraries." ON)
set(OTB_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})

180 181 182 183 184 185 186
if(MSVC)
  option(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS "Build OTB with shared libraries." ON)
  set(OTB_CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ${CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS})
else()
  set(OTB_CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF)
endif()

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
#-----------------------------------------------------------------------------
# Option to activate deprecated classes
option(OTB_USE_DEPRECATED "Turn on the use and test of deprecated classes" OFF)
mark_as_advanced(OTB_USE_DEPRECATED)

#-----------------------------------------------------------------------------
# SHOW_ALL_MSG_DEBUG option
option(OTB_SHOW_ALL_MSG_DEBUG "Show all debug messages (very verbose)" OFF)
mark_as_advanced(OTB_SHOW_ALL_MSG_DEBUG)

include(OTBSetStandardCompilerFlags)
#---------------------------------------------------------------
# run try compiles and tests for OTB

# TODO check if we need this
#include(otbTestFriendTemplatedFunction)

204 205 206 207 208
set(CMAKE_C_FLAGS "${OTB_REQUIRED_C_FLAGS} ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${OTB_REQUIRED_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${OTB_REQUIRED_LINK_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${OTB_REQUIRED_LINK_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${OTB_REQUIRED_LINK_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
209

210
# detect some C++11 keywords
211
include(OTBCheckCpp11Keywords)
212

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
# TODO BUILD_TESTING is created by default by CTest.cmake, and is ON by default.
option(BUILD_TESTING "Build the testing tree." OFF)

include(CTest)

include( CppcheckTargets )

# Setup build locations.
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OTB_BINARY_DIR}/bin)
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OTB_BINARY_DIR}/lib)
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OTB_BINARY_DIR}/lib)
endif()
set(OTB_MODULES_DIR "${OTB_BINARY_DIR}/${OTB_INSTALL_PACKAGE_DIR}/Modules")

#-----------------------------------------------------------------------------
# OTB uses KWStyle for checking the coding style
#include(${OTB_SOURCE_DIR}/Utilities/KWStyle/KWStyle.cmake)

#-----------------------------------------------------------------------------
237 238
# By default, OTB does not build the Examples that are illustrated in the Software Guide
option(BUILD_EXAMPLES "Build the Examples directory." OFF)
239 240 241 242

#----------------------------------------------------------------------------
set(OTB_TEST_OUTPUT_DIR "${OTB_BINARY_DIR}/Testing/Temporary")

243 244 245
option(OTB_DATA_USE_LARGEINPUT "Use Large inputs images test." OFF)
mark_as_advanced(OTB_DATA_USE_LARGEINPUT)
if(OTB_DATA_USE_LARGEINPUT)
246 247 248 249
  find_path(OTB_DATA_LARGEINPUT_ROOT
    NAMES OTBData.readme
    HINTS $ENV{OTB_DATA_LARGEINPUT_ROOT}
  )
250 251 252
  mark_as_advanced(OTB_DATA_LARGEINPUT_ROOT)
endif()

253 254 255 256 257 258 259 260 261 262 263 264 265
# Small macro to copy a file and rename it
macro(otb_copy_rename _input _output)
  execute_process(
    COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_input}" "${_output}"
    RESULT_VARIABLE _err_code
    OUTPUT_QUIET
    ERROR_QUIET
    )
  if(_err_code)
    message(FATAL_ERROR "Failed to copy file ${_input} to ${_output}")
  endif()
endmacro()

266 267 268
#Generate cmake variables with a set of largeinput data used in tests
include(OTBManageLargeInputPaths)

269 270 271 272
set(BASELINE       ${OTB_DATA_ROOT}/Baseline/OTB/Images)
set(BASELINE_FILES ${OTB_DATA_ROOT}/Baseline/OTB/Files)
set(INPUTDATA      ${OTB_DATA_ROOT}/Input)
set(TEMP           ${OTB_BINARY_DIR}/Testing/Temporary)
Julien Malik's avatar
Julien Malik committed
273
set(EXAMPLEDATA    ${OTB_DATA_ROOT}/Examples)
274 275
set(OTBAPP_BASELINE       ${OTB_DATA_ROOT}/Baseline/OTB-Applications/Images)
set(OTBAPP_BASELINE_FILES ${OTB_DATA_ROOT}/Baseline/OTB-Applications/Files)
276

Julien Malik's avatar
Julien Malik committed
277
set(NOTOL      0.0)
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
set(EPSILON_1  0.1)
set(EPSILON_2  0.01)
set(EPSILON_3  0.001)
set(EPSILON_4  0.0001)
set(EPSILON_5  0.00001)
set(EPSILON_6  0.000001)
set(EPSILON_7  0.0000001)
set(EPSILON_8  0.00000001)
set(EPSILON_9  0.000000001)
set(EPSILON_10 0.0000000001)
set(EPSILON_11 0.00000000001)
set(EPSILON_12 0.000000000001)
set(EPSILON_13 0.0000000000001)
set(EPSILON_14 0.00000000000001)
set(EPSILON_15 0.000000000000001)

# Location of OTB Example Data.
295
set(OTB_EXAMPLE_DATA_ROOT "${OTB_SOURCE_DIR}/Examples/Data")
296 297 298 299 300 301 302 303 304 305 306 307 308

#----------------------------------------------------------------------
# Make sure remote modules are downloaded before sorting out the module
# dependencies.
add_subdirectory(Modules/Remote)

# Enable modules according to user inputs and the module dependency DAG.
include(OTBModuleEnablement)

#----------------------------------------------------------------------
# Generate OTBConfig.cmake for the build tree.
set(OTB_CONFIG_CODE "
set(OTB_MODULES_DIR \"${OTB_MODULES_DIR}\")")
309 310
set(OTB_CONFIG_CMAKE_DIR "${OTB_SOURCE_DIR}/CMake")
set(OTB_USE_FILE "${OTB_CONFIG_CMAKE_DIR}/UseOTB.cmake")
311 312 313 314 315 316
if(OTB_WRAP_PYTHON)
set(OTB_CONFIG_CODE "${OTB_CONFIG_CODE}
set(OTB_PYTHONPATH \"${OTB_BINARY_DIR}/${OTB_INSTALL_PYTHON_DIR}\")")
endif()

set(OTB_CONFIG_APPLICATION_PATH "${OTB_BINARY_DIR}/${OTB_INSTALL_APP_DIR}")
317 318 319
set(OTB_CONFIG_TARGETS_CONDITION " AND NOT OTB_BINARY_DIR")
set(OTB_CONFIG_TARGETS_FILE "${OTB_BINARY_DIR}/OTBTargets.cmake")
set(OTB_CONFIG_MODULE_API_FILE "${OTB_SOURCE_DIR}/CMake/OTBModuleAPI.cmake")
320
set(OTB_CONFIG_APPLI_MACROS_FILE "${OTB_SOURCE_DIR}/CMake/OTBApplicationMacros.cmake")
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
configure_file(CMake/OTBConfig.cmake.in OTBConfig.cmake @ONLY)

# Generate OTBConfig.cmake for the install tree.
set(OTB_CONFIG_CODE "
# Compute the installation prefix from this OTBConfig.cmake file location.
get_filename_component(OTB_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
# Construct the proper number of get_filename_component(... PATH)
# calls to compute the installation prefix.
string(REGEX REPLACE "/" ";" _count "${OTB_INSTALL_PACKAGE_DIR}")
foreach(p ${_count})
  set(OTB_CONFIG_CODE "${OTB_CONFIG_CODE}
get_filename_component(OTB_INSTALL_PREFIX \"\${OTB_INSTALL_PREFIX}\" PATH)")
endforeach()
set(OTB_CONFIG_CODE "${OTB_CONFIG_CODE}
set(OTB_MODULES_DIR \"\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PACKAGE_DIR}/Modules\")")
set(OTB_USE_FILE "\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PACKAGE_DIR}/UseOTB.cmake")
337
set(OTB_CONFIG_CMAKE_DIR "\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PACKAGE_DIR}")
338 339 340 341 342
if(OTB_WRAP_PYTHON)
set(OTB_CONFIG_CODE "${OTB_CONFIG_CODE}
set(OTB_PYTHONPATH \"\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PYTHON_DIR}\")")
endif()
set(OTB_CONFIG_APPLICATION_PATH "\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_APP_DIR}")
343 344 345
set(OTB_CONFIG_TARGETS_CONDITION "")
set(OTB_CONFIG_TARGETS_FILE "\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PACKAGE_DIR}/OTBTargets.cmake")
set(OTB_CONFIG_MODULE_API_FILE "\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PACKAGE_DIR}/OTBModuleAPI.cmake")
346
set(OTB_CONFIG_APPLI_MACROS_FILE "\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PACKAGE_DIR}/OTBApplicationMacros.cmake")
347 348 349 350 351 352 353 354 355 356 357 358 359 360

configure_file(CMake/OTBConfig.cmake.in CMakeFiles/OTBConfig.cmake @ONLY)

# TODO : port unscrustify scripts from ITK to OTB ?
# #----------------------------------------------------------------------------
# # Configure maintenance scripts
# configure_file(Utilities/Maintenance/doSingleKWStyleUncrustifyFix.sh.in
#   Utilities/Maintenance/doSingleKWStyleUncrustifyFix.sh @ONLY)

#-----------------------------------------------------------------------------
configure_file(CMake/OTBConfigVersion.cmake.in OTBConfigVersion.cmake @ONLY)

install(FILES ${OTB_BINARY_DIR}/CMakeFiles/OTBConfig.cmake
              ${OTB_BINARY_DIR}/OTBConfigVersion.cmake
361
              CMake/OTBApplicationMacros.cmake
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
              CMake/OTBModuleAPI.cmake
              CMake/UseOTB.cmake
  DESTINATION ${OTB_INSTALL_PACKAGE_DIR}
  COMPONENT Development)
get_property(OTBTargets_MODULES GLOBAL PROPERTY OTBTargets_MODULES)
if(OTBTargets_MODULES)
  install(EXPORT OTBTargets DESTINATION ${OTB_INSTALL_PACKAGE_DIR}
          COMPONENT Development)
else()
  set(CMAKE_CONFIGURABLE_FILE_CONTENT "# No targets!")
  configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in
                 ${OTB_BINARY_DIR}/CMakeFiles/OTBTargets.cmake @ONLY)
  install(FILES ${OTB_BINARY_DIR}/CMakeFiles/OTBTargets.cmake
          DESTINATION ${OTB_INSTALL_PACKAGE_DIR} COMPONENT Development)
endif()

378 379 380 381
# install FindXXX.cmake
file(GLOB OTB_FIND_PACKAGE_SCRIPTS CMake/Find*.cmake)
install(FILES ${OTB_FIND_PACKAGE_SCRIPTS} DESTINATION ${OTB_INSTALL_PACKAGE_DIR} COMPONENT Development)

382 383 384 385
# TODO : install release notes, copyright notice, ...
# install(FILES "LICENSE" "NOTICE" "README.txt" DESTINATION ${OTB_INSTALL_DOC_DIR} COMPONENT Runtime)
install(FILES "LICENSE" DESTINATION ${OTB_INSTALL_DOC_DIR} COMPONENT Runtime)

386 387 388 389
# Configure and install VERSION file
configure_file(VERSION VERSION @ONLY)
install(FILES ${OTB_BINARY_DIR}/VERSION DESTINATION ${OTB_INSTALL_DOC_DIR} COMPONENT Runtime)

390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
if(BUILD_TESTING)
  add_subdirectory(Utilities/InstallTest)
endif()
#-----------------------------------------------------------------------------
# The subdirectories added below this line should use only the public
# interface with find_package(ITK). Set ITK_DIR to use this ITK build.
set(OTB_DIR "${OTB_BINARY_DIR}")

if(BUILD_EXAMPLES)
  add_subdirectory(Examples)
endif()

#----------------------------------------------------------------------
# Provide an option for generating documentation.
add_subdirectory(Utilities/Doxygen)

406 407
add_subdirectory(Utilities/Completion)

408
#----------------------------------------------------------------------------
409 410 411 412 413 414 415 416 417 418
# Provide a target to generate the SuperBuild archive (only for Unix)
if(UNIX)
  add_custom_target(SuperBuild-archive
    COMMAND ./SuperbuildDownloadList.sh
      ${OTB_BINARY_DIR}/Download
      ${OTB_BINARY_DIR}
    WORKING_DIRECTORY ${OTB_SOURCE_DIR}/Utilities/Maintenance
    )
endif()

419 420 421
# TODO cleanup
# Create target to download data from the OTBData group. This must come after
# all tests have been added that reference the group, so we put it last.
422

423
#-----------------------------------------------------------------------------
424 425
# uninstall target
configure_file(
426 427
    "${CMAKE_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in"
    "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
428 429 430 431 432
    IMMEDIATE @ONLY)

add_custom_target(uninstall
  COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake_uninstall.cmake)

433 434 435 436 437 438 439 440 441 442 443
# #-----------------------------------------------------------------------------
# # Packaging options for Windows packages
# if(WIN32 OR CMAKE_CROSSCOMPILING)
#   option(GENERATE_PACKAGE "Generate OTB package" OFF)
#   option(GENERATE_XDK "Generate XDK for OTB development" OFF)
#   if(GENERATE_PACKAGE OR GENERATE_XDK)
#     set(MXE_TARGET_DIR "" CACHE PATH "path to mxe directory")
#     set(PACKAGE_OTB_SRC_DIR ${OTB_SOURCE_DIR})
#     add_subdirectory(${OTB_SOURCE_DIR}/SuperBuild/Packaging ${CMAKE_BINARY_DIR}/Packaging)
#   endif() # (GENERATE_PACKAGE OR GENERATE_XDK)
# endif() # (WIN32 OR CMAKE_CROSSCOMPILING)
444 445

#-----------------------------------------------------------------------------
446 447 448
#macro to put a fixed space between key, value  in summary
macro(get_white_spaces var res)
  string(LENGTH "${var}" len)
449
  math(EXPR required_spaces "23 - ${len}")
450 451 452 453 454 455
  set(${res})
  foreach(loop_var RANGE ${required_spaces})
    set(${res} "${${res}} ")
  endforeach()
endmacro()

456
message("\n======================= Begin of OTB cmake summary =======================\n")
457

458 459 460
if(OTB_GIT_STATUS_MESSAGE)
  message( ${OTB_GIT_STATUS_MESSAGE})
endif()
461 462 463
if(OTB_DATA_GIT_STATUS_MESSAGE)
  message( ${OTB_DATA_GIT_STATUS_MESSAGE})
endif()
464

465 466 467 468
set(option_list ${OTB_MODULE_ACTIVATION_OPTION_LIST})
list(SORT option_list)

foreach(otb_option
469 470 471
    CMAKE_SOURCE_DIR
    CMAKE_BINARY_DIR
    CMAKE_INSTALL_PREFIX
472 473 474 475 476 477 478 479
    CMAKE_COMMAND
    CMAKE_C_COMPILER
    CMAKE_CXX_COMPILER
    CMAKE_MAKE_PROGRAM
    CMAKE_GENERATOR
    CMAKE_BUILD_TYPE
    CMAKE_C_FLAGS
    CMAKE_CXX_FLAGS
480
    OTB_HAS_CXX11
481 482 483
    ${option_list}
    OTB_WRAP_PYTHON
    OTB_WRAP_JAVA
484
    OTB_DATA_ROOT
485 486 487 488 489 490 491 492 493 494 495
    )
    get_white_spaces("${otb_option}" spaces)
  message("${otb_option} ${spaces} = ${${otb_option}}")
endforeach()

# set(modules_list_for_summary "${OTB_MODULES_ENABLED}")
# list(SORT modules_list_for_summary)
# string(REPLACE ";" " " modules_list_for_summary "${modules_list_for_summary}")
# message("OTB_MODULES_ENABLED      = ${modules_list_for_summary}")
# unset(modules_list_for_summary)

496
list(REMOVE_ITEM option_list "OTB_USE_6S" "OTB_USE_SIFTFAST" "OTB_USE_QT4")
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
foreach(item ${option_list})
  if(NOT ${item})
    list(REMOVE_ITEM option_list "${item}" )
  endif()
endforeach()

#To report non-optional dependencies inside summary
list(APPEND option_list Boost)
list(APPEND option_list GDAL)
list(APPEND option_list GEOTIFF)
list(APPEND option_list ITK)
list(APPEND option_list OSSIM)
list(APPEND option_list TINYXML)

#RK
#Q: Why these two guys here? we already have option_list
#A: Because cmake case sensitivity with variables.

515 516 517
if(OTB_USE_QT4)
  list(APPEND option_list QT)
endif()
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
#sort again!
list(SORT option_list)

foreach(dep ${option_list})

  string(REGEX REPLACE "OTB_USE_" "" dep ${dep})

  unset(var1_key)
  unset(var2_key)
  unset(var3_key)

  unset(var1_val)
  unset(var2_val)
  unset(var3_val)

  set(var1_key "${dep}")
  if(${dep}_VERSION_STRING)
    set(var1_val ${${dep}_VERSION_STRING})
  endif()
  if(NOT var1_val)
    if(${dep}_VERSION)
      set(var1_val ${${dep}_VERSION})
    endif()
  endif()

543
  if(DEFINED ${dep}_DIR)
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
    set(var2_key  ${dep}_DIR)
    set(var2_val ${${dep}_DIR})
  else()
    if(${dep}_INCLUDE_DIR)
      set(var2_key  ${dep}_INCLUDE_DIR)
      set(var2_val ${${dep}_INCLUDE_DIR})
    elseif(${dep}_INCLUDE_DIRS)
      set(var2_key  ${dep}_INCLUDE_DIRS)
      set(var2_val ${${dep}_INCLUDE_DIRS})
    endif()
    if(${dep}_LIBRARY)
      set(var3_key  ${dep}_LIBRARY)
      set(var3_val ${${dep}_LIBRARY})
    elseif(${dep}_LIBRARIES)
      set(var3_key  ${dep}_LIBRARIES)
      set(var3_val ${${dep}_LIBRARIES})
    endif()
  endif()

  get_white_spaces("${var1_key}" insert_spaces1)
  get_white_spaces("${var2_key}" insert_spaces2)
  get_white_spaces("${var3_key}" insert_spaces3)

  message("${var1_key} ${insert_spaces1} = ${var1_val}")
  if(var2_val)
    message("${var2_key} ${insert_spaces2} = ${var2_val}")
  endif()
  if(var3_val)
    message("${var3_key} ${insert_spaces3} = ${var3_val}")
  endif()

endforeach()

577
message("\nCMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator\n")
578

579
message("======================= End of OTB cmake summary =======================")
580 581 582

#don't need this one anymore. so unset it.
unset(option_list)
583 584 585 586

#----------------------------------------------------------------------------
# I18N
add_subdirectory( i18n )