paddle2onnx.cmake 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
#
# 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.

if(NOT WITH_ONNXRUNTIME)
  return()
endif()

19
if(WITH_ARM)
20 21
  message(SEND_ERROR "The current onnxruntime backend doesn't support ARM cpu")
  return()
22
endif()
23

24
include(ExternalProject)
25

26 27
set(PADDLE2ONNX_PROJECT "extern_paddle2onnx")
set(PADDLE2ONNX_PREFIX_DIR ${THIRD_PARTY_PATH}/paddle2onnx)
28 29
set(PADDLE2ONNX_SOURCE_DIR
    ${THIRD_PARTY_PATH}/paddle2onnx/src/${PADDLE2ONNX_PROJECT})
30 31 32 33
set(PADDLE2ONNX_INSTALL_DIR ${THIRD_PARTY_PATH}/install/paddle2onnx)
set(PADDLE2ONNX_INC_DIR
    "${PADDLE2ONNX_INSTALL_DIR}/include"
    CACHE PATH "paddle2onnx include directory." FORCE)
34 35 36
set(PADDLE2ONNX_LIB_DIR
    "${PADDLE2ONNX_INSTALL_DIR}/lib"
    CACHE PATH "onnxruntime lib directory." FORCE)
37 38
set(CMAKE_BUILD_RPATH "${CMAKE_BUILD_RPATH}"
                      "${PADDLE2ONNX_INSTALL_DIR}/${LIBDIR}")
39

40 41
include_directories(${PADDLE2ONNX_INC_DIR}
)# For PADDLE2ONNX code to include internal headers.
42
if(WIN32)
43 44 45
  set(PADDLE2ONNX_SOURCE_LIB
      "${PADDLE2ONNX_SOURCE_DIR}/lib/libpaddle2onnx.dylib"
      CACHE FILEPATH "Paddle2ONNX source library." FORCE)
46
  set(PADDLE2ONNX_LIB
47 48 49 50 51
      "${PADDLE2ONNX_INSTALL_DIR}/lib/paddle2onnx.dll"
      CACHE FILEPATH "paddle2onnx library." FORCE)
  set(PADDLE2ONNX_COMPILE_LIB
      "${PADDLE2ONNX_INSTALL_DIR}/lib/paddle2onnx.lib"
      CACHE FILEPATH "paddle2onnx compile library." FORCE)
52
elseif(APPLE)
53 54 55
  set(PADDLE2ONNX_SOURCE_LIB
      "${PADDLE2ONNX_SOURCE_DIR}/lib/libpaddle2onnx.dylib"
      CACHE FILEPATH "Paddle2ONNX source library." FORCE)
56
  set(PADDLE2ONNX_LIB
57
      "${PADDLE2ONNX_INSTALL_DIR}/lib/libpaddle2onnx.dylib"
58
      CACHE FILEPATH "PADDLE2ONNX library." FORCE)
59 60 61
  set(PADDLE2ONNX_COMPILE_LIB
      "${PADDLE2ONNX_INSTALL_DIR}/lib/libpaddle2onnx.dylib"
      CACHE FILEPATH "paddle2onnx compile library." FORCE)
62
else()
63 64 65
  set(PADDLE2ONNX_SOURCE_LIB
      "${PADDLE2ONNX_SOURCE_DIR}/lib/libpaddle2onnx.so"
      CACHE FILEPATH "Paddle2ONNX source library." FORCE)
66
  set(PADDLE2ONNX_LIB
67
      "${PADDLE2ONNX_INSTALL_DIR}/lib/libpaddle2onnx.so"
68
      CACHE FILEPATH "PADDLE2ONNX library." FORCE)
69 70 71
  set(PADDLE2ONNX_COMPILE_LIB
      "${PADDLE2ONNX_INSTALL_DIR}/lib/libpaddle2onnx.so"
      CACHE FILEPATH "paddle2onnx compile library." FORCE)
W
Wilber 已提交
72
endif()
73

74 75 76 77 78 79 80 81 82 83 84 85
if(WIN32)
  set(PADDLE2ONNX_URL
      "https://github.com/PaddlePaddle/Paddle2ONNX/releases/download/v0.9.7/paddle2onnx-win-x64-0.9.7.zip"
  )
elseif(APPLE)
  set(PADDLE2ONNX_URL
      "https://github.com/PaddlePaddle/Paddle2ONNX/releases/download/v0.9.7/paddle2onnx-osx-x86_64-0.9.7.tgz"
  )
else()
  set(PADDLE2ONNX_URL
      "https://github.com/PaddlePaddle/Paddle2ONNX/releases/download/v0.9.7/paddle2onnx-linux-x64-0.9.7.tgz"
  )
86
endif()
87 88

ExternalProject_Add(
89
  ${PADDLE2ONNX_PROJECT}
90 91
  ${EXTERNAL_PROJECT_LOG_ARGS}
  URL ${PADDLE2ONNX_URL}
92
  PREFIX ${PADDLE2ONNX_PREFIX_DIR}
93 94 95
  DOWNLOAD_NO_PROGRESS 1
  CONFIGURE_COMMAND ""
  BUILD_COMMAND ""
96
  UPDATE_COMMAND ""
97 98 99 100 101
  INSTALL_COMMAND
    ${CMAKE_COMMAND} -E copy_directory ${PADDLE2ONNX_SOURCE_DIR}/lib
    ${PADDLE2ONNX_LIB_DIR} && ${CMAKE_COMMAND} -E copy_directory
    ${PADDLE2ONNX_SOURCE_DIR}/include ${PADDLE2ONNX_INC_DIR}
  BUILD_BYPRODUCTS ${PADDLE2ONNX_COMPILE_LIB})
102

103
add_library(paddle2onnx STATIC IMPORTED GLOBAL)
104 105
set_property(TARGET paddle2onnx PROPERTY IMPORTED_LOCATION
                                         ${PADDLE2ONNX_COMPILE_LIB})
106
add_dependencies(paddle2onnx ${PADDLE2ONNX_PROJECT})