OTBModuleExternal.cmake 4.83 KB
Newer Older
1
#
Julien Michel's avatar
Julien Michel committed
2
# Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#
# This file is part of Orfeo Toolbox
#
#     https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

21 22 23 24 25
#Adapted from ITKModuleExternal.cmake
# This file ensures the appropriate variables are set up for a project extending
# OTB before including OTBModuleMacros. This is the preferred way to build an
# OTB module outside of the OTB source tree.

26 27
option(OTB_BUILD_MODULE_AS_STANDALONE "Build module as a standalone cmake project" OFF)

28 29 30 31 32 33 34
if(NOT OTB_FOUND)
  message(FATAL_ERROR "OTB must be found before module macros can be used.")
endif()
if(NOT OTB_VERSION VERSION_GREATER "5.2")
  message(FATAL_ERROR "Requires OTB 5.4 or later to work.")
endif()
if(NOT EXISTS ${OTB_CMAKE_DIR}/OTBModuleMacros.cmake)
35 36 37
  if(NOT OTB_BUILD_MODULE_AS_STANDALONE)
    message(FATAL_ERROR "Modules can only be built against an OTB build tree; they cannot be built against an OTB install tree. You can build your module as a standalone CMake project instead, by activating the BUILD_MODULE_AS_STANDALONE option. Beware that dependency between remote modules will NOT be tracked.")
  endif()
38 39
endif()

40
if(OTB_BUILD_MODULE_AS_STANDALONE)
41
  message(STATUS "You are building this module as a standalone CMake project. Beware that dependencies to other remote modules will not be tracked.")
42
  include(OTBStandaloneModuleMacros)
43
  otb_module_impl()
44 45 46 47 48 49 50 51 52 53 54 55
else()
  
  # Setup build locations.
  if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OTB_DIR}/bin)
  endif()
  if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OTB_DIR}/lib)
  endif()
  if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OTB_DIR}/lib)
  endif()
56

57 58 59 60 61 62 63 64 65 66 67 68 69 70
  # OTB installation structure
  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_DATA_DIR)
71
    set(OTB_INSTALL_DATA_DIR share/otb)
72 73
  endif()
  if(NOT OTB_INSTALL_DOC_DIR)
74
    set(OTB_INSTALL_DOC_DIR share/doc/otb)
75 76 77 78
  endif()
  if(NOT OTB_INSTALL_PACKAGE_DIR)
    set(OTB_INSTALL_PACKAGE_DIR "lib/cmake/OTB-${OTB_VERSION_MAJOR}.${OTB_VERSION_MINOR}")
  endif()
79 80 81
  if(NOT OTB_INSTALL_APP_DIR)
    set(OTB_INSTALL_APP_DIR lib/otb/applications)
  endif()
82

83 84 85 86 87 88 89
  # Use OTB's flags.
  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}")
  option(BUILD_SHARED_LIBS "Build OTB with shared libraries." ${OTB_BUILD_SHARED})
90

91 92 93 94 95 96
  # Add the OTB_MODULES_DIR to the CMAKE_MODULE_PATH and then use the binary
  # directory for the project to write out new ones to.
  if(OTB_MODULES_DIR)
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${OTB_MODULES_DIR})
  endif()
  set(OTB_MODULES_DIR "${OTB_DIR}/${OTB_INSTALL_PACKAGE_DIR}/Modules")
97

98 99 100 101 102
  #include(OTBExternalData)
  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt)
    include(CTest)
    include(OTBModuleTest)
  endif()
103

104 105 106 107 108 109 110 111
  include(OTBModuleMacros)
  include(otb-module.cmake)
  set(${otb-module}-targets ${otb-module}Targets)
  set(${otb-module}-targets-install "\${OTB_INSTALL_PREFIX}/${OTB_INSTALL_PACKAGE_DIR}/${otb-module}Targets.cmake")
  set(${otb-module}_TARGETS_FILE_INSTALL "${${otb-module}-targets-install}")
  set(${otb-module}-targets-build "${OTB_DIR}/${OTB_INSTALL_PACKAGE_DIR}/Modules/${otb-module}Targets.cmake")
  set(${otb-module}_TARGETS_FILE_BUILD "${${otb-module}-targets-build}")
  otb_module_impl()
112

113 114 115 116
  if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/CMakeLists.txt AND NOT ${otb-module}_NO_SRC AND "${${otb-module}-targets}")
    install(EXPORT ${${otb-module}-targets} DESTINATION "${OTB_INSTALL_PACKAGE_DIR}/Modules"
      COMPONENT Development)
  endif()
117

118 119 120 121
  set(OTB_TEST_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Testing/Temporary")
  if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
    add_subdirectory(test)
  endif()
122

123
endif()