lite.cmake 6.8 KB
Newer Older
石晓伟 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2019 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.

W
Wilber 已提交
15 16
if(NOT LINUX)
  message("Paddle-lite will not build because the required Linux do not exist.")
石晓伟 已提交
17 18 19 20
  set(WITH_LITE OFF)
  return()
endif()

21 22 23 24
if(XPU_SDK_ROOT)
  set(LITE_WITH_XPU ON)
  include_directories("${XPU_SDK_ROOT}/XTDK/include")
  include_directories("${XPU_SDK_ROOT}/XTCL/include")
W
Wilber 已提交
25
  add_definitions(-DLITE_SUBGRAPH_WITH_XPU)
26 27
  LINK_DIRECTORIES("${XPU_SDK_ROOT}/XTDK/shlib/")
  LINK_DIRECTORIES("${XPU_SDK_ROOT}/XTDK/runtime/shlib/")
W
Wilber 已提交
28 29
  set(XPURT_LIB ${XPU_SDK_ROOT}/XTDK/runtime/shlib/libxpurt.so)
  set(XPUAPI_LIB ${XPU_SDK_ROOT}/XTDK/shlib/libxpuapi.so)
30 31
endif()

石晓伟 已提交
32 33 34 35 36 37
if (NOT LITE_SOURCE_DIR OR NOT LITE_BINARY_DIR)
  include(ExternalProject)
  set(LITE_PROJECT extern_lite)
  set(LITE_SOURCES_DIR ${THIRD_PARTY_PATH}/lite)
  set(LITE_INSTALL_DIR ${THIRD_PARTY_PATH}/install/lite)

38
  if(NOT LITE_GIT_TAG)
W
Wilber 已提交
39
    set(LITE_GIT_TAG release/v2.7)
40 41 42 43
  endif()

  if(NOT CUDA_ARCH_NAME)
    set(CUDA_ARCH_NAME "Auto")
44 45
  endif()

石晓伟 已提交
46
  # No quotes, so cmake can resolve it as a command with arguments.
W
Wilber 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  if(WITH_ARM)
    set(LITE_BUILD_COMMAND $(MAKE) publish_inference -j)
    message(WARNING "BUILD_COMMAND: ${LITE_BUILD_COMMAND}")
    set(LITE_OPTIONAL_ARGS -DWITH_MKL=OFF
                           -DLITE_WITH_CUDA=OFF
                           -DWITH_MKLDNN=OFF
                           -DLITE_WITH_X86=OFF
                           -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=ON
                           -DLITE_WITH_PROFILE=OFF
                           -DARM_TARGET_OS=armlinux
                           -DWITH_LITE=ON
                           -DWITH_PYTHON=OFF
                           -DWITH_TESTING=OFF
                           -DLITE_BUILD_EXTRA=ON
                           -DLITE_WITH_XPU=${LITE_WITH_XPU}
                           -DXPU_SDK_ROOT=${XPU_SDK_ROOT}
                           -DLITE_WITH_ARM=ON)
    ExternalProject_Add(
石晓伟 已提交
65 66 67
      ${LITE_PROJECT}
      ${EXTERNAL_PROJECT_LOG_ARGS}
      GIT_REPOSITORY      "https://github.com/PaddlePaddle/Paddle-Lite.git"
68
      GIT_TAG             ${LITE_GIT_TAG}
石晓伟 已提交
69
      PREFIX              ${LITE_SOURCES_DIR}
W
Wilber 已提交
70
      PATCH_COMMAND       mkdir -p ${LITE_SOURCES_DIR}/src/extern_lite-build/lite/gen_code && touch ${LITE_SOURCES_DIR}/src/extern_lite-build/lite/gen_code/__generated_code__.cc
石晓伟 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
      UPDATE_COMMAND      ""
      BUILD_COMMAND       ${LITE_BUILD_COMMAND}
      INSTALL_COMMAND     ""
      CMAKE_ARGS          -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
                          -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
                          -DCMAKE_CXX_FLAGS=${LITE_CMAKE_CXX_FLAGS}
                          -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
                          -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}
                          -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
                          -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
                          -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
                          -DCMAKE_POSITION_INDEPENDENT_CODE=ON
                          -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
                          ${EXTERNAL_OPTIONAL_ARGS}
                          ${LITE_OPTIONAL_ARGS}
W
Wilber 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    )
  else()
    set(LITE_BUILD_COMMAND $(MAKE) publish_inference -j)
    set(LITE_OPTIONAL_ARGS -DWITH_MKL=ON
                           -DLITE_WITH_CUDA=${WITH_GPU}
                           -DWITH_MKLDNN=OFF
                           -DLITE_WITH_X86=ON
                           -DLITE_WITH_PROFILE=OFF
                           -DWITH_LITE=OFF
                           -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=OFF
                           -DWITH_PYTHON=OFF
                           -DWITH_TESTING=OFF
                           -DLITE_BUILD_EXTRA=ON
                           -DCUDNN_ROOT=${CUDNN_ROOT}
                           -DLITE_WITH_STATIC_CUDA=OFF
                           -DCUDA_ARCH_NAME=${CUDA_ARCH_NAME}
                           -DLITE_WITH_XPU=${LITE_WITH_XPU}
                           -DXPU_SDK_ROOT=${XPU_SDK_ROOT}
                           -DLITE_WITH_ARM=OFF)

    ExternalProject_Add(
        ${LITE_PROJECT}
        ${EXTERNAL_PROJECT_LOG_ARGS}
        GIT_REPOSITORY      "https://github.com/PaddlePaddle/Paddle-Lite.git"
        GIT_TAG             ${LITE_GIT_TAG}
        PREFIX              ${LITE_SOURCES_DIR}
        UPDATE_COMMAND      ""
        BUILD_COMMAND       ${LITE_BUILD_COMMAND}
        INSTALL_COMMAND     ""
        CMAKE_ARGS          -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
                            -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
                            -DCMAKE_CXX_FLAGS=${LITE_CMAKE_CXX_FLAGS}
                            -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
                            -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}
                            -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
                            -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
                            -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
                            -DCMAKE_POSITION_INDEPENDENT_CODE=ON
                            -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
                            ${EXTERNAL_OPTIONAL_ARGS}
                            ${LITE_OPTIONAL_ARGS}
    )
  endif()
石晓伟 已提交
129 130 131 132 133 134 135
  ExternalProject_Get_property(${LITE_PROJECT} BINARY_DIR)
  ExternalProject_Get_property(${LITE_PROJECT} SOURCE_DIR)
  set(LITE_BINARY_DIR ${BINARY_DIR})
  set(LITE_SOURCE_DIR ${SOURCE_DIR})

endif()

W
Wilber 已提交
136 137 138 139 140 141
if (WITH_ARM)
  set(LITE_OUTPUT_BIN_DIR inference_lite_lib.armlinux.armv8)
else()
  set(LITE_OUTPUT_BIN_DIR inference_lite_lib)
endif()

石晓伟 已提交
142 143 144 145 146
message(STATUS "Paddle-lite BINARY_DIR: ${LITE_BINARY_DIR}")
message(STATUS "Paddle-lite SOURCE_DIR: ${LITE_SOURCE_DIR}")
include_directories(${LITE_SOURCE_DIR})
include_directories(${LITE_BINARY_DIR})

147
function(external_lite_libs alias path)
148
  add_library(${alias} SHARED IMPORTED GLOBAL)
石晓伟 已提交
149 150 151 152 153 154 155
  SET_PROPERTY(TARGET ${alias} PROPERTY IMPORTED_LOCATION
               ${path})
  if (LITE_PROJECT)
    add_dependencies(${alias} ${LITE_PROJECT})
  endif()
endfunction()

W
Wilber 已提交
156 157
external_lite_libs(lite_full_static ${LITE_BINARY_DIR}/${LITE_OUTPUT_BIN_DIR}/cxx/lib/libpaddle_full_api_shared.so)
set(LITE_SHARED_LIB ${LITE_BINARY_DIR}/${LITE_OUTPUT_BIN_DIR}/cxx/lib/libpaddle_full_api_shared.so)
石晓伟 已提交
158 159

add_definitions(-DPADDLE_WITH_LITE)
160
add_definitions(-DLITE_WITH_LOG)