External_gdal.cmake 5.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#
# Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
#
# 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
INCLUDE_ONCE_MACRO(GDAL)
22

23
SETUP_SUPERBUILD(GDAL)
24 25

# declare dependencies
26
ADDTO_DEPENDENCIES_IF_NOT_SYSTEM(GDAL CURL OPENJPEG TIFF GEOTIFF PNG JPEG SQLITE GEOS ZLIB EXPAT HDF5 NETCDF HDF4)
27 28 29 30 31 32 33 34 35 36 37

ADD_SUPERBUILD_CONFIGURE_VAR(GDAL TIFF_ROOT     --with-libtiff)
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL GEOTIFF_ROOT  --with-geotiff)
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL PNG_ROOT      --with-png)
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL JPEG_ROOT     --with-jpeg)
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL OPENJPEG_ROOT --with-openjpeg)
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL SQLITE_ROOT   --with-sqlite3)
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL ZLIB_ROOT     --with-libz)
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL EXPAT_ROOT    --with-expat)
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL CURL_ROOT     --with-curl "/bin/curl-config")
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL GEOS_ROOT     --with-geos "/bin/geos-config")
38 39 40
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL HDF5_ROOT     --with-hdf5)
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL NETCDF_ROOT   --with-netcdf)
ADD_SUPERBUILD_CONFIGURE_VAR(GDAL HDF4_ROOT     --with-hdf4)
41 42 43 44 45

set(GDAL_CONFIGURE_COMMAND)
set(GDAL_BUILD_COMMAND)
set(GDAL_INSTALL_COMMAND)

46 47 48 49
set(GDAL_SB_EXTRA_OPTIONS "" CACHE STRING "Extra options to be passed to GDAL configure script")
mark_as_advanced(GDAL_SB_EXTRA_OPTIONS)
#Convert GDAL_SB_EXTRA_OPTIONS to a list to allow to add multiple instructions to the CONFIGURE_COMMAND
separate_arguments(GDAL_SB_EXTRA_OPTIONS)
50

51
if(UNIX)
52
  #we don't do any framework build on osx. So let's be sure on case of gdal
53
  if(APPLE)
54
    list(APPEND GDAL_SB_CONFIG "--with-macosx-framework=no")
55 56
  endif()

57 58
  # PATCH_COMMAND ${CMAKE_COMMAND} -E touch ${GDAL_SB_SRC}/config.rpath
  # COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/patches/GDAL/GNUmakefile ${GDAL_SB_SRC}/swig/python/GNUmakefile
59 60 61 62 63 64 65

  list(APPEND GDAL_SB_CONFIG "--with-libkml=no")
  if(OTB_USE_LIBKML)
    #RK: disabled libkml. Here are in External_otb.cmake
    #ADDTO_DEPENDENCIES_IF_NOT_SYSTEM(LIBKML)
    #ADD_SUPERBUILD_CONFIGURE_VAR(GDAL LIBKML_ROOT     --with-libkml)
  endif()
66

67
  set(GDAL_CONFIGURE_COMMAND  "${SB_ENV_CONFIGURE_CMD};${GDAL_SB_SRC}/configure"
68
    ${SB_CONFIGURE_ARGS}
69 70 71 72 73 74 75 76 77 78 79 80
    --with-cfitsio=no
    --with-dods-root=no
    --with-ecw=no
    --with-epsilon=no
    --with-fme=no
    --with-gif=no
    --with-grass=no
    --with-gta=no
    --with-idb=no
    --with-ingres=no
    --with-jp2mrsid=no
    --with-kakadu=no
81
    --with-jasper=no
82 83 84 85 86 87 88 89
    --with-libgrass=no
    --with-mrsid=no
    --with-msg=no
    --with-mysql=no
    --with-oci=no
    --with-odbc=no
    --with-ogdi=no
    --with-pam
90
    --with-pcidsk=yes
91 92 93 94 95 96 97 98 99 100
    --with-pcraster=no
    --with-pcre=no
    --with-perl=no
    --with-php=no
    --with-python=no
    --with-qhull=internal
    --with-sde=no
    --with-spatialite=no
    --with-xerces=no
    --with-xml2=no
101
    --with-pg=no
102
    --with-webp=no
103
    --with-threads=yes
104
    --with-freexl=no
105 106
    ${GDAL_SB_CONFIG}
    ${GDAL_SB_EXTRA_OPTIONS}
107
    )
108 109
  #set(GDAL_BUILD_COMMAND ${CMAKE_MAKE_PROGRAM})
  #set(GDAL_INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install)
110

111
else(MSVC)
112
  configure_file(
113 114
    ${CMAKE_SOURCE_DIR}/patches/GDAL/nmake_gdal_extra.opt.in
    ${CMAKE_BINARY_DIR}/nmake_gdal_extra.opt)
115 116

  foreach(opt_line ${GDAL_SB_EXTRA_OPTIONS})
117
    file(APPEND "${CMAKE_BINARY_DIR}/nmake_gdal_extra.opt" "${opt_line}\r\n")
118
  endforeach()
119
  
120
  if(OTB_TARGET_SYSTEM_ARCH_IS_X64)
121
    file(APPEND "${CMAKE_BINARY_DIR}/nmake_gdal_extra.opt" "WIN64=YES\r\n")
122 123
  endif()
  
124
  set(GDAL_CONFIGURE_COMMAND ${CMAKE_COMMAND} -E touch  ${CMAKE_BINARY_DIR}/configure)
125 126 127 128 129 130 131 132 133 134
  set(GDAL_BUILD_COMMAND nmake
    /f ${GDAL_SB_SRC}/makefile.vc
    MSVC_VER=${MSVC_VERSION}
    EXT_NMAKE_OPT=${CMAKE_BINARY_DIR}/nmake_gdal_extra.opt
    )
  set(GDAL_INSTALL_COMMAND nmake
    /f ${GDAL_SB_SRC}/makefile.vc devinstall
    MSVC_VER=${MSVC_VERSION}
    EXT_NMAKE_OPT=${CMAKE_BINARY_DIR}/nmake_gdal_extra.opt
    )
135

136
endif()
137 138 139

ExternalProject_Add(GDAL
  PREFIX GDAL
140 141
  URL "http://download.osgeo.org/gdal/2.2.1/gdal-2.2.1.tar.gz"
  URL_MD5 785acf2b0cbf9d56d37c9044d0ee2505
142 143 144 145 146 147 148 149
  SOURCE_DIR ${GDAL_SB_SRC}
  BINARY_DIR ${GDAL_SB_SRC}
  INSTALL_DIR ${SB_INSTALL_PREFIX}
  DOWNLOAD_DIR ${DOWNLOAD_LOCATION}
  DEPENDS ${GDAL_DEPENDENCIES}
  CONFIGURE_COMMAND ${GDAL_CONFIGURE_COMMAND}
  BUILD_COMMAND ${GDAL_BUILD_COMMAND}
  INSTALL_COMMAND ${GDAL_INSTALL_COMMAND}
150
  LOG_DOWNLOAD 1
151
  LOG_CONFIGURE 1
152 153
  LOG_BUILD 1
  LOG_INSTALL 1
154 155
  )

156
SUPERBUILD_PATCH_SOURCE(GDAL)
157 158 159 160 161 162

set(_SB_GDAL_INCLUDE_DIR ${SB_INSTALL_PREFIX}/include)
if(WIN32)
  set(_SB_GDAL_LIBRARY ${SB_INSTALL_PREFIX}/lib/gdal_i.lib)
elseif(UNIX)
  set(_SB_GDAL_LIBRARY ${SB_INSTALL_PREFIX}/lib/libgdal${CMAKE_SHARED_LIBRARY_SUFFIX})
163
endif()