CMakeLists.txt 3.4 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
set(FLUID_CORE_NAME "libpaddle")
24

Z
zhangjinchao01 已提交
25
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in
26
               ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
27 28 29

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

30 31 32 33 34 35 36
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}
37 38 39
    COMMAND cmake -E copy $<TARGET_FILE:libpaddle> ${FLUID_CORE}
    COMMAND cmake -E copy $<TARGET_LINKER_FILE:libpaddle> ${FLUID_CORE_LIB}
    DEPENDS libpaddle)
40 41 42 43
else()
  set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.so)
  add_custom_command(
    OUTPUT ${FLUID_CORE}
44 45
    COMMAND cmake -E copy $<TARGET_FILE:libpaddle> ${FLUID_CORE}
    DEPENDS libpaddle)
46
endif()
47 48 49

set(FLUID_CORE_DEPS ${FLUID_CORE})

50
add_custom_target(copy_libpaddle ALL DEPENDS ${FLUID_CORE_DEPS})
51

52 53 54 55 56 57 58 59
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
60
    COMMENT "Packing whl packages------>>>"
61 62
    DEPENDS copy_libpaddle ${FLUID_CORE} framework_py_proto profiler_py_proto
            pass_desc_py_proto ${PY_FILES})
63
else()
64 65
  add_custom_command(
    OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
66 67 68
    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
69
    COMMENT "Packing whl packages------>>>"
70 71
    DEPENDS copy_libpaddle ${FLUID_CORE} framework_py_proto profiler_py_proto
            pass_desc_py_proto ${PY_FILES})
72
endif()
Z
zhangjinchao01 已提交
73

74 75
add_custom_target(paddle_python ALL
                  DEPENDS ${PADDLE_PYTHON_BUILD_DIR}/.timestamp)
Z
zhangjinchao01 已提交
76

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

79
if(WITH_TESTING)
80 81
  add_subdirectory(paddle/reader/tests)
  add_subdirectory(paddle/dataset/tests)
82
  add_subdirectory(paddle/tests)
L
Luo Tao 已提交
83
  add_subdirectory(paddle/fluid/tests)
84
  add_subdirectory(paddle/fluid/contrib/tests)
W
WangZhen 已提交
85
  add_subdirectory(paddle/fluid/contrib/slim/tests)
86
endif()
Y
Yu Yang 已提交
87
install(DIRECTORY ${PADDLE_PYTHON_PACKAGE_DIR}
88
        DESTINATION opt/paddle/share/wheels)
89

90 91 92 93 94
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 已提交
95
endif()
96 97 98
if(LINUX
   AND NOT WITH_SW
   AND NOT WITH_ARM)
99 100
  find_program(PATCHELF_EXECUTABLE patchelf)
  if(NOT PATCHELF_EXECUTABLE)
101 102 103
    message(
      FATAL_ERROR "patchelf not found, please install it.\n"
                  "For Ubuntu, the command is: apt-get install -y patchelf.")
104
  endif()
W
Wilber 已提交
105
endif()