CMakeLists.txt 6.67 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 21 22 23 24 25 26 27 28 29
#
# 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.
#

cmake_minimum_required(VERSION 3.3.0)

project(OTBPackaging)

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

30
#setting this variable prints a lot of debug information
31 32 33 34 35 36 37 38 39 40 41
set(PKG_DEBUG OFF)
#set( PKG_DEBUG 1)

set(CMAKE_BUILD_TYPE    Release)

#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 44 45 46
#variables based on above user-defined variables
message( "OTB_BINARY_DIR=${OTB_BINARY_DIR}" )
if ( NOT OTB_BINARY_DIR )
  set(OTB_BINARY_DIR            "${SUPERBUILD_BINARY_DIR}/OTB/build")
endif()
47 48 49 50 51 52 53 54 55 56
set(QT_TRANSLATIONS_DIR       "${SUPERBUILD_INSTALL_DIR}/translations")
get_filename_component(PACKAGE_OTB_SRC_DIR ${OTBPackaging_SOURCE_DIR} PATH)
set(SUPERBUILD_SOURCE_DIR     "${PACKAGE_OTB_SRC_DIR}/SuperBuild")


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

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

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

#set CMAKE_MODULE_PATH to be the current source directory.
66
# This will allow including all cmake files without full path and .cmake extension!
67 68 69 70 71 72 73 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
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
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)
99
  set(PACKAGE_PLATFORM_NAME "Win")
100 101 102 103 104 105 106 107 108 109
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
110
set(PKG_STAGE_DIR ${PACKAGE_NAME}-${PKG_OTB_VERSION_STRING}-${PACKAGE_PLATFORM_NAME}${PACKAGE_ARCH}${NAME_SUFFIX})
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

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)
134 135
include(detect_using_file_command)
include(install_otbapp_wrapper_scripts)
136
include(cleanup_package)
137 138 139 140

# below functions include many install commands which are installing
# files under PKG_STAGE_DIR
include(install_include_dirs)
141
include(install_importlibs)
142
include(install_python_bindings)
143 144 145 146 147 148 149 150 151
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)

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

# 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()

165 166
check_cmake_variables()

167
cleanup_package()
168

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

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

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

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

#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
198
  process_file_recurse(${pfile})
199 200 201 202
endforeach()

install_include_dirs()

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

install_python_bindings()

207 208
install_share_dirs()

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

install_qtdev_files()

install_vstudio_files()

installer_files()

create_package()
218

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




227 228 229 230 231 232 233 234 235
#TODO: dummy targets. to be removed after merge
add_custom_target(
    PACKAGE-OTB
    COMMAND
    "${CMAKE_COMMAND}" --build . --target install
    WORKING_DIRECTORY
    "${CMAKE_BINARY_DIR}"
    COMMENT "dummy target PACKAGE-OTB"
    )