CMakeLists.txt 5.0 KB
Newer Older
X
Xin Pan 已提交
1
file(GLOB UTILS_PY_FILES . ./paddle/legacy/utils/*.py)
2
file(GLOB_RECURSE FLUID_PY_FILES ./paddle/fluid/*.py)
3
set(PY_FILES paddle/__init__.py ${UTILS_PY_FILES} ${FLUID_PY_FILES})
H
Helin Wang 已提交
4

T
typhoonzero 已提交
5
if(WITH_GPU)
6
  set(PACKAGE_NAME "paddlepaddle-gpu")
7
elseif(WITH_MLU)
8
  set(PACKAGE_NAME "paddlepaddle-mlu")
9
elseif(WITH_ROCM)
10
  set(PACKAGE_NAME "paddlepaddle-rocm")
11
elseif(WITH_ASCEND_CL)
12
  set(PACKAGE_NAME "paddlepaddle-npu")
13
elseif(WITH_XPU)
14
  set(PACKAGE_NAME "paddlepaddle-xpu")
15
elseif(WITH_IPU)
16
  set(PACKAGE_NAME "paddlepaddle-ipu")
T
typhoonzero 已提交
17
else()
18
  set(PACKAGE_NAME "paddlepaddle")
T
typhoonzero 已提交
19 20
endif()

21 22
set(SETUP_LOG_FILE "setup.py.log")

23 24 25 26
set(FLUID_CORE_NAME "core")
if(WITH_AVX AND AVX_FOUND)
  set(FLUID_CORE_NAME "${FLUID_CORE_NAME}_avx")
  if(NOT DEFINED NOAVX_CORE_FILE OR NOAVX_CORE_FILE STREQUAL "")
27 28 29
    message(
      STATUS
        "MESSAGE: This is just a message for publishing release.
30 31
      You are building AVX version without NOAVX core.
      So the wheel package may fail on NOAVX machine.
32
      You can add -DNOAVX_CORE_FILE=/path/to/your/core_noavx.* in cmake command
33 34
      to get a full wheel package to resolve this warning.
      While, this version will still work on local machine.")
35 36 37 38 39 40 41 42 43 44 45
  endif()

  if(NOAVX_CORE_FILE AND NOT EXISTS "${NOAVX_CORE_FILE}")
    message(FATAL_ERROR "The file ${NOAVX_CORE_FILE} does not exist!")
  endif()

  set(HAS_NOAVX_CORE ON)
else()
  set(FLUID_CORE_NAME "${FLUID_CORE_NAME}_noavx")
endif()

Z
zhangjinchao01 已提交
46
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in
47
               ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
48 49 50

set(FLUID_DST_DIR ${PADDLE_BINARY_DIR}/python/paddle/fluid/)

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
if(WIN32)
  # Python would use the .pyd by default under Windows series platform
  set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.pyd)
  set(FLUID_CORE_LIB ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.lib)

  add_custom_command(
    OUTPUT ${FLUID_CORE}
    COMMAND cmake -E copy $<TARGET_FILE:paddle_pybind> ${FLUID_CORE}
    COMMAND cmake -E copy $<TARGET_LINKER_FILE:paddle_pybind> ${FLUID_CORE_LIB}
    DEPENDS paddle_pybind)

  set(FLUID_NOAVX_CORE ${FLUID_DST_DIR}/core_noavx.pyd)
else()
  set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.so)
  add_custom_command(
    OUTPUT ${FLUID_CORE}
    COMMAND cmake -E copy $<TARGET_FILE:paddle_pybind> ${FLUID_CORE}
    DEPENDS paddle_pybind)

  set(FLUID_NOAVX_CORE ${FLUID_DST_DIR}/core_noavx.so)
endif()
72 73 74 75 76 77 78 79

set(FLUID_CORE_DEPS ${FLUID_CORE})

if(HAS_NOAVX_CORE AND EXISTS "${NOAVX_CORE_FILE}")
  get_filename_component(NOAVX_CORE_NAME ${NOAVX_CORE_FILE} NAME)
  get_filename_component(NOAVX_CORE_EXT ${NOAVX_CORE_FILE} EXT)
  if(WIN32)
    if(NOT NOAVX_CORE_EXT STREQUAL ".pyd")
80 81 82 83
      message(
        FATAL_ERROR
          "Wrong file ${NOAVX_CORE_NAME}, the ext does not match windows *.pyd!"
      )
84 85 86
    endif()
  else()
    if(NOT NOAVX_CORE_EXT STREQUAL ".so")
87 88 89
      message(
        FATAL_ERROR
          "Wrong file ${NOAVX_CORE_NAME}, the ext does not match *.so!")
90 91
    endif()
  endif()
92 93 94 95
  add_custom_command(
    OUTPUT ${FLUID_NOAVX_CORE}
    COMMAND cmake -E copy ${NOAVX_CORE_FILE} ${FLUID_NOAVX_CORE}
    DEPENDS paddle_pybind)
96 97 98 99
  list(APPEND FLUID_CORE_DEPS ${FLUID_NOAVX_CORE})
endif()

add_custom_target(copy_paddle_pybind ALL DEPENDS ${FLUID_CORE_DEPS})
100

101 102 103 104 105 106 107 108
if(WIN32)
  add_custom_command(
    OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
    COMMAND
      ${CMAKE_COMMAND} -E copy_directory ${PADDLE_SOURCE_DIR}/python/paddle
      ${PADDLE_BINARY_DIR}/python/paddle/
    COMMAND ${CMAKE_COMMAND} -E env ${py_env} ${PYTHON_EXECUTABLE} setup.py
            bdist_wheel
109
    COMMENT "Packing whl packages------>>>"
110 111
    DEPENDS copy_paddle_pybind ${FLUID_CORE} framework_py_proto
            profiler_py_proto pass_desc_py_proto ${PY_FILES})
112
else()
113 114
  add_custom_command(
    OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
115 116 117
    COMMAND touch stub.cc
    COMMAND cp -r ${PADDLE_SOURCE_DIR}/python/paddle ${PADDLE_BINARY_DIR}/python
    COMMAND env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel
118
    COMMENT "Packing whl packages------>>>"
119 120 121
    DEPENDS copy_paddle_pybind ${FLUID_CORE} framework_py_proto
            profiler_py_proto pass_desc_py_proto ${PY_FILES})
endif()
Z
zhangjinchao01 已提交
122

123 124
add_custom_target(paddle_python ALL
                  DEPENDS ${PADDLE_PYTHON_BUILD_DIR}/.timestamp)
Z
zhangjinchao01 已提交
125

Y
Yu Yang 已提交
126 127
set(PADDLE_PYTHON_PACKAGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/dist/)

128
if(WITH_TESTING)
129 130
  add_subdirectory(paddle/reader/tests)
  add_subdirectory(paddle/dataset/tests)
131
  add_subdirectory(paddle/tests)
L
Luo Tao 已提交
132
  add_subdirectory(paddle/fluid/tests)
133
  add_subdirectory(paddle/fluid/contrib/tests)
W
WangZhen 已提交
134
  add_subdirectory(paddle/fluid/contrib/slim/tests)
135
endif()
Y
Yu Yang 已提交
136
install(DIRECTORY ${PADDLE_PYTHON_PACKAGE_DIR}
137
        DESTINATION opt/paddle/share/wheels)
138

139 140 141 142 143
if(APPLE)
  find_program(INSTALL_NAME_TOOL_EXECUTABLE install_name_tool)
  if(NOT INSTALL_NAME_TOOL_EXECUTABLE)
    message(FATAL_ERROR "install_name_tool not found, please check.\n")
  endif()
D
dzhwinter 已提交
144
endif()
145 146 147
if(LINUX
   AND NOT WITH_SW
   AND NOT WITH_ARM)
148 149
  find_program(PATCHELF_EXECUTABLE patchelf)
  if(NOT PATCHELF_EXECUTABLE)
150 151 152
    message(
      FATAL_ERROR "patchelf not found, please install it.\n"
                  "For Ubuntu, the command is: apt-get install -y patchelf.")
153
  endif()
W
Wilber 已提交
154
endif()