patch_cmake_files.cmake 2.5 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
#
# 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.
#
20 21 22 23 24
function(patch_cmake_files)
  cmake_parse_arguments(PATCH  "" "NAME;VERSION;MATCH_STRING;REPLACE_VAR" "" ${ARGN} )

  set(PATCH_DIR_NAME ${PATCH_NAME}-${PATCH_VERSION})
  set(PATCH_DIR "${SUPERBUILD_INSTALL_DIR}/lib/cmake/${PATCH_DIR_NAME}")
25
  set(PATCH_STAGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/patched/${PATCH_DIR_NAME})
26 27 28 29 30 31 32 33 34 35 36 37 38 39

  ##message("COPY ${PATCH_DIR} to ${PATCH_STAGE_DIR} for patching")

  execute_process(
    COMMAND ${CMAKE_COMMAND} -E make_directory "${PATCH_STAGE_DIR}"
    COMMAND ${CMAKE_COMMAND} -E copy_directory "${PATCH_DIR}" "${PATCH_STAGE_DIR}"
    )

  set(DIR_LIST "${PATCH_STAGE_DIR}|${PATCH_STAGE_DIR}/Modules")

  execute_process(COMMAND ${CMAKE_COMMAND}
    -DP_DIRS=${DIR_LIST}
    -DP_MATCH=${PATCH_MATCH_STRING}
    -DP_REPLACE=${PATCH_REPLACE_VAR}
40
    -P ${CMAKE_CURRENT_SOURCE_DIR}/post_install.cmake
41 42 43 44 45 46 47 48 49
    RESULT_VARIABLE patch_${PATCH_NAME}_cmake_rv
    )

  if(patch_${PATCH_NAME}_cmake_rv)
    message(FATAL_ERROR "    execute_process() failed.")
  endif()

  install_without_message("${PATCH_STAGE_DIR}" "lib/cmake")

50 51 52 53 54 55 56 57 58 59 60 61
  # file( GLOB otb_opengl
  #   "${SUPERBUILD_INSTALL_DIR}/lib/cmake/OTB*/Modules/OTBOpenGL.cmake" )
  # if(EXISTS ${otb_opengl})
  #   file(STRINGS "${otb_opengl}" otb_opengl_cmake)
  #   set(otb_opengl_cmake_NEW)
  #   foreach(line ${otb_opengl_cmake})
  #     if( NOT line MATCHES "/usr")
  # 	list(APPEND otb_opengl_cmake_NEW "${line}\n")
  #     endif()
  #   endforeach()
  # endif()
  # file(WRITE "${otb_opengl}" ${otb_opengl_cmake_NEW})
62 63 64

  #patch for ABI compatibility
  if(EXISTS "${PATCH_STAGE_DIR}/UseOTB.cmake")
65 66 67 68 69 70 71
    file(APPEND "${PATCH_STAGE_DIR}/UseOTB.cmake" 
"\n\n# ABI compatibility \
\nif ( CMAKE_CXX_COMPILER_ID STREQUAL \"GNU\") \
\n  if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0 ) \
\n    add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) \
\n  endif() \
\nendif()" )
72 73
  endif()

74
  
75
endfunction()