CMakeLists.txt 6.7 KB
Newer Older
1
#
2
# Copyright (C) 2005-2020 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
cmake_minimum_required(VERSION 3.10.2)
22 23 24 25 26 27 28 29

project(OTBPackaging)

include(CMakeParseArguments)
include(CMakeDetermineSystem)
include(GetPrerequisites)
include(CTest)

30
#setting this variable prints a lot of debug information
31 32 33
set(PKG_DEBUG OFF)
#set( PKG_DEBUG 1)

34
set(CMAKE_BUILD_TYPE Release)
35 36 37 38 39 40 41

#user-defined variables and option
option(OTB_WRAP_PYTHON "include python bindings in package" ON)
set(SUPERBUILD_BINARY_DIR "" CACHE PATH "path to superbuild binary directory")
set(SUPERBUILD_INSTALL_DIR "" CACHE PATH "path to superbuild install directory")
set(DOWNLOAD_LOCATION "" CACHE PATH "path to superbuild download archives")

42 43
#variables based on above user-defined variables
if ( NOT OTB_BINARY_DIR )
44
  set(OTB_BINARY_DIR "${SUPERBUILD_BINARY_DIR}/OTB/build")
45
endif()
46
set(QT_TRANSLATIONS_DIR "${SUPERBUILD_INSTALL_DIR}/translations")
47
get_filename_component(PACKAGE_OTB_SRC_DIR ${OTBPackaging_SOURCE_DIR} PATH)
48
set(SUPERBUILD_SOURCE_DIR "${PACKAGE_OTB_SRC_DIR}/SuperBuild")
49 50 51 52 53 54 55


set(LINUX FALSE)
if( "${CMAKE_SYSTEM_NAME}"  MATCHES "Linux")
  set(LINUX TRUE)
endif()

56 57 58 59
find_program(FILE_COMMAND NAMES  "file")
find_program(READLINK NAMES "readlink")
find_program(ZIP_EXECUTABLE NAMES 7z 7za)

60 61 62
if ( NOT CMAKE_INSTALL_PREFIX )
  set(CMAKE_INSTALL_PREFIX "${SUPERBUILD_INSTALL_DIR}")
endif()
63 64

#set CMAKE_MODULE_PATH to be the current source directory.
65
# This will allow including all cmake files without full path and .cmake extension!
66 67 68 69 70 71
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})

#include superbuild_macro for get_version()
include(${SUPERBUILD_SOURCE_DIR}/CMake/SuperBuild_Macro.cmake)

#include superbuild_macro for OTB_TARGET_SYSTEM_ARCH_IS_X64 value
72 73
# This maybe deleted as it might be done with cmake_host_system_information
# https://cmake.org/cmake/help/v3.10/command/cmake_host_system_information.html?highlight=sse
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
include(${PACKAGE_OTB_SRC_DIR}/CMake/OTBCheckTargetSystemArch.cmake)

# get itk version from External_itk.cmake if not on mingw
# because mxe has different version
get_version(
  INPUT_FILE   "${SUPERBUILD_SOURCE_DIR}/CMake/External_itk.cmake"
  MATCH_STRINGS "SB_ITK_VERSION_MAJOR" "SB_ITK_VERSION_MINOR"
  PREFIX PKG
  )
set(PKG_ITK_SB_VERSION "${PKG_SB_ITK_VERSION_MAJOR}.${PKG_SB_ITK_VERSION_MINOR}")

#get version of OTB from source_dir/CMakeLists.txt
get_version(
  INPUT_FILE   "${PACKAGE_OTB_SRC_DIR}/CMakeLists.txt"
  MATCH_STRINGS "OTB_VERSION_MAJOR" "OTB_VERSION_MINOR" "OTB_VERSION_PATCH"
  PREFIX PKG
  )

set(PKG_OTB_VERSION_STRING ${PKG_OTB_VERSION_MAJOR}.${PKG_OTB_VERSION_MINOR}.${PKG_OTB_VERSION_PATCH})

set(PACKAGE_LONG_NAME OrfeoToolBox)
set(NAME_SUFFIX "" CACHE STRING "extra suffix for package name")
set(PACKAGE_NAME OTB)
if(APPLE)
  set(PACKAGE_PLATFORM_NAME "Darwin")
elseif(WIN32)
100
  set(PACKAGE_PLATFORM_NAME "Win")
101 102 103 104 105 106 107 108 109 110
elseif(LINUX)
  set(PACKAGE_PLATFORM_NAME "Linux")
endif()
set(PACKAGE_ARCH "32")
if(OTB_TARGET_SYSTEM_ARCH_IS_X64)
set(PACKAGE_ARCH "64")
endif()

# This directory is important.
# We stage/keep files that goes into final package in this directory
111
set(PKG_STAGE_DIR ${PACKAGE_NAME}-${PKG_OTB_VERSION_STRING}-${PACKAGE_PLATFORM_NAME}${PACKAGE_ARCH}${NAME_SUFFIX})
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

set(PATCHELF_PROGRAM "${CMAKE_BINARY_DIR}/PATCHELF/src/patchelf/src/patchelf")
include(External_patchelf)

include(PackageGlobals)

# Note that MANY or ALL of function use global variables set in this CMakeLists.txt
# The order in which the functions in these "included" files are called is only important.
# We tried not to share variables which are created inside functions or macro. In such cases,
# function return the value. 

include(setif_value_in_list)
include(get_variables_ending_with)
include(clear_cmakecache_variables)
include(check_cmake_variables)
include(configure_loader)
include(search_library)
include(prepare_search_dirs)
include(prepare_file_list)
include(process_file_recurse)
include(install_without_message)
include(install_rule)
include(isfile_symlink)
135 136
include(detect_using_file_command)
include(install_otbapp_wrapper_scripts)
137
include(cleanup_package)
138 139 140 141

# below functions include many install commands which are installing
# files under PKG_STAGE_DIR
include(install_include_dirs)
142
include(install_importlibs)
143
include(install_python_bindings)
144 145 146 147 148 149 150 151 152
include(install_share_dirs)
include(install_cmake_files)
include(install_qtdev_files)
include(install_vstudio_files)
include(installer_files)
include(create_package)

configure_loader(LOADER_PROGRAM LOADER_ARGS LOADER_REGEX)

153 154 155 156 157 158 159 160 161 162 163 164 165

# creation of package is different from windows and unix like
# WE KEEP THIS VARIABLE HERE BECAUSE IT IS USED IN
# cleanup_package, create_package, testing.cmake
# and check_cmake_variables

# THIS IS JUST TO AVOID DUPLICATION
if(WIN32)
  set(PACKAGE_OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PKG_STAGE_DIR}.zip")
else()
  set(PACKAGE_OUTPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PKG_STAGE_DIR}.run")
endif()

166 167
check_cmake_variables()

168
cleanup_package()
169

170
set(HAVE_QT FALSE CACHE INTERNAL "HAVE_QT")
171
if(EXISTS "${SUPERBUILD_INSTALL_DIR}/bin/otbApplicationLauncherQt${EXE_EXT}")
172
  set(HAVE_QT TRUE)
173 174 175 176 177 178 179
endif()

set(HAVE_MVD FALSE  CACHE INTERNAL "HAVE_MVD")
if(EXISTS "${SUPERBUILD_INSTALL_DIR}/bin/monteverdi${EXE_EXT}")
  set(HAVE_MVD TRUE)
endif()

180
set(HAVE_PYTHON FALSE CACHE INTERNAL "Python wrappings")
181 182 183 184
if(EXISTS "${SUPERBUILD_INSTALL_DIR}/lib/otb/python/_otbApplication${PYMODULE_EXT}")
  set(HAVE_PYTHON TRUE)
endif()

185
#only for *nix
186 187 188
if(UNIX)
  file(WRITE ${CMAKE_BINARY_DIR}/make_symlinks   "#!/bin/sh\n")
endif()
189 190 191 192 193 194 195 196 197 198

#remove all *_USED|*_RESOLVED variables from CMakeCache.txt
clear_cmakecache_variables()

set(PKG_SEARCHDIRS)
prepare_search_dirs(PKG_SEARCHDIRS)

set(PKG_PEFILES)
prepare_file_list(PKG_PEFILES)
foreach(pfile ${PKG_PEFILES})
Guillaume Pasero's avatar
Guillaume Pasero committed
199
  process_file_recurse(${pfile})
200 201 202 203
endforeach()

install_include_dirs()

Rashad Kanavath's avatar
Rashad Kanavath committed
204
install_importlibs()
205 206 207

install_python_bindings()

208 209
install_share_dirs()

210
install_cmake_files()
211 212 213 214 215 216 217 218

install_qtdev_files()

install_vstudio_files()

installer_files()

create_package()
219

220 221 222 223
if(BUILD_TESTING)
  enable_testing()
  include(testing.cmake)
endif()
224 225 226 227 228 229

add_custom_target( PACKAGE-OTB
      COMMAND "${CMAKE_COMMAND}" --build . --target install
      WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
      COMMENT "PACKAGE-OTB"
      )