CMakeLists.txt 4.3 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
H
Helin Wang 已提交
4
  ${UTILS_PY_FILES}
5
  ${FLUID_PY_FILES})
H
Helin Wang 已提交
6

T
typhoonzero 已提交
7
if(WITH_GPU)
T
update  
typhoonzero 已提交
8
  SET(PACKAGE_NAME "paddlepaddle-gpu")
T
typhoonzero 已提交
9 10 11 12
else()
  SET(PACKAGE_NAME "paddlepaddle")
endif()

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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 "")
    message(WARNING "You are building AVX version without NOAVX core, \
      and the wheel package may fail on NOAVX machine.")
  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 已提交
30 31
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in
    ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
32 33 34

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

P
peizhilin 已提交
35 36
IF(WIN32)
    # Python would use the .pyd by default under Windows series platform
37 38
    set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.pyd)
    set(FLUID_NOAVX_CORE ${FLUID_DST_DIR}/core_noavx.pyd)
P
peizhilin 已提交
39
ELSE()
40 41
    set(FLUID_CORE ${FLUID_DST_DIR}/${FLUID_CORE_NAME}.so)
    set(FLUID_NOAVX_CORE ${FLUID_DST_DIR}/core_noavx.so)
P
peizhilin 已提交
42
ENDIF()
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

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")
      message(FATAL_ERROR "Wrong file ${NOAVX_CORE_NAME}, the ext does not match windows *.pyd!")
    endif()
  else()
    if(NOT NOAVX_CORE_EXT STREQUAL ".so")
      message(FATAL_ERROR "Wrong file ${NOAVX_CORE_NAME}, the ext does not match *.so!")
    endif()
  endif()
  add_custom_command(OUTPUT ${FLUID_NOAVX_CORE}
    COMMAND cmake -E copy ${NOAVX_CORE_FILE} ${FLUID_NOAVX_CORE} DEPENDS paddle_pybind)
  list(APPEND FLUID_CORE_DEPS ${FLUID_NOAVX_CORE})
endif()

P
peizhilin 已提交
63 64 65
add_custom_command(OUTPUT ${FLUID_CORE}
        COMMAND cmake -E copy $<TARGET_FILE:paddle_pybind> ${FLUID_CORE}
        DEPENDS paddle_pybind)
66
add_custom_target(copy_paddle_pybind ALL DEPENDS ${FLUID_CORE_DEPS})
67

P
peizhilin 已提交
68
IF(WIN32)
P
peizhilin 已提交
69 70 71 72 73
    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
            COMMAND ${CMAKE_COMMAND} -E touch ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
            COMMAND ${CMAKE_COMMAND} -E remove_directory ${PADDLE_PYTHON_BUILD_DIR}/lib-python
74
            DEPENDS copy_paddle_pybind ${FLUID_CORE} framework_py_proto profiler_py_proto ${PY_FILES})
P
peizhilin 已提交
75 76 77 78 79 80 81 82
ELSE(WIN32)
	add_custom_command(OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
		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
		COMMAND ${CMAKE_COMMAND} -E touch ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
		COMMAND ${CMAKE_COMMAND} -E remove_directory ${PADDLE_PYTHON_BUILD_DIR}/lib-python
		COMMAND ${CMAKE_COMMAND} -E copy_directory ${PADDLE_PYTHON_BUILD_DIR}/lib* ${PADDLE_PYTHON_BUILD_DIR}/lib-python
83
		DEPENDS copy_paddle_pybind ${FLUID_CORE} framework_py_proto profiler_py_proto ${PY_FILES})
P
peizhilin 已提交
84
ENDIF()
Z
zhangjinchao01 已提交
85

86
add_custom_target(paddle_python ALL DEPENDS ${PADDLE_PYTHON_BUILD_DIR}/.timestamp)
Z
zhangjinchao01 已提交
87

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

90
if (WITH_TESTING)
91 92
  add_subdirectory(paddle/reader/tests)
  add_subdirectory(paddle/dataset/tests)
L
Luo Tao 已提交
93
  add_subdirectory(paddle/fluid/tests)
94
  add_subdirectory(paddle/fluid/contrib/tests)
W
WangZhen 已提交
95
  add_subdirectory(paddle/fluid/contrib/slim/tests)
96
endif()
Y
Yu Yang 已提交
97
install(DIRECTORY ${PADDLE_PYTHON_PACKAGE_DIR}
Z
zhangjinchao01 已提交
98 99
    DESTINATION opt/paddle/share/wheels
)
100

101 102 103 104 105
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 已提交
106 107
endif()
if(LINUX)
108 109 110 111 112
  find_program(PATCHELF_EXECUTABLE patchelf)
  if(NOT PATCHELF_EXECUTABLE)
    message(FATAL_ERROR "patchelf not found, please install it.\n"
            "For Ubuntu, the command is: apt-get install -y patchelf.")
  endif()
D
dzhwinter 已提交
113
endif(LINUX)