CMakeLists.txt 3.6 KB
Newer Older
L
liaogang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
FUNCTION(generate_python_api target_name)
    ADD_CUSTOM_COMMAND(OUTPUT ${PROJ_ROOT}/paddle/py_paddle/swig_paddle.py
                              ${PROJ_ROOT}/paddle/Paddle_wrap.cxx
                              ${PROJ_ROOT}/paddle/Paddle_wrap.h
        COMMAND ${SWIG_EXECUTABLE} -python -c++ -outcurrentdir -I../ api/Paddle.swig
                && mv ${PROJ_ROOT}/paddle/swig_paddle.py ${PROJ_ROOT}/paddle/py_paddle/swig_paddle.py
        DEPENDS ${PROJ_ROOT}/paddle/api/Paddle.swig
                ${PROJ_ROOT}/paddle/api/PaddleAPI.h
                ${external_project_dependencies}
        WORKING_DIRECTORY ${PROJ_ROOT}/paddle
        COMMENT "Generate Python API from swig")
    ADD_CUSTOM_TARGET(${target_name} ALL DEPENDS
                ${PROJ_ROOT}/paddle/Paddle_wrap.cxx
                ${PROJ_ROOT}/paddle/Paddle_wrap.h
                ${PROJ_ROOT}/paddle/py_paddle/swig_paddle.py
                ${external_project_dependencies})
ENDFUNCTION(generate_python_api)

Z
zhangjinchao01 已提交
19 20 21
set(API_SOURCES
    Arguments.cpp
    ConfigParser.cpp
Y
Yu Yang 已提交
22
    Evaluator.cpp
Z
zhangjinchao01 已提交
23 24 25 26
    GradientMachine.cpp
    Matrix.cpp
    Parameter.cpp
    ParameterOptimizer.cpp
Y
Yu Yang 已提交
27
    ParameterUpdater.cpp
Z
zhangjinchao01 已提交
28 29 30 31 32 33 34 35 36 37 38 39
    SequenceGenerator.cpp
    Trainer.cpp
    Util.cpp
    Vector.cpp)
set(API_HEADER
    PaddleAPI.h
    Internal.h)

add_library(paddle_api STATIC
        ${API_SOURCES})
add_dependencies(paddle_api gen_proto_cpp)

40
list(LENGTH "${GFLAGS_LIBRARIES}" GFLAGS_LIBRARIES_LENGTH)
Z
zhangjinchao01 已提交
41

42 43 44 45 46 47 48 49
if(${GFLAGS_LIBRARIES_LENGTH} EQUAL 0 AND TARGET "${GFLAGS_LIBRARIES}")
# Because gflags compiled by cmake, so it is imported by cmake target,
# not a real library path. Get the real library path here.
message(STATUS "GFLAGS Libraries is ${GFLAGS_LIBRARIES}")
get_target_property(GFLAGS_LOCATION ${GFLAGS_LIBRARIES} LOCATION)
message(STATUS "GFLAGS Target location is ${GFLAGS_LOCATION}")
else()
set(GFLAGS_LOCATION ${GFLAGS_LIBRARIES})
Z
zhangjinchao01 已提交
50 51 52 53 54 55 56 57 58
endif()

configure_file(
    paddle_api_config.py.in
    ${PROJ_ROOT}/paddle/api/paddle_api_config.py
)

generate_python_api(python_swig_sources)

E
emailweixu 已提交
59 60
file(GLOB PY_PADDLE_PYTHON_FILES ${PROJ_ROOT}/paddle/py_paddle/*.py)

Z
zhangjinchao01 已提交
61
# TODO(yuyang18) : make wheel name calculated by cmake
62
add_custom_command(OUTPUT ${PROJ_ROOT}/paddle/dist/.timestamp
L
liaogang 已提交
63
    COMMAND env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel
64 65
    COMMAND ${CMAKE_COMMAND} -E touch dist/.timestamp
    COMMAND rm -rf py_paddle.egg-info build
Z
zhangjinchao01 已提交
66 67 68
    WORKING_DIRECTORY ${PROJ_ROOT}/paddle
    DEPENDS python_swig_sources
            paddle_parameter
H
hedaoyuan 已提交
69
            paddle_function
Z
zhangjinchao01 已提交
70 71 72 73 74 75 76
            paddle_math
            paddle_utils
            paddle_gserver
            paddle_pserver
            paddle_trainer
            paddle_api
            paddle_cuda
77
        ${PY_PADDLE_PYTHON_FILES}
Z
zhangjinchao01 已提交
78 79
)

80 81 82
install(DIRECTORY ${PROJ_ROOT}/paddle/dist/
    DESTINATION opt/paddle/share/wheels
)
Z
zhangjinchao01 已提交
83 84

add_custom_target(python_api_wheel ALL DEPENDS
85
  ${PROJ_ROOT}/paddle/dist/.timestamp)
Y
Yu Yang 已提交
86 87 88 89 90 91 92 93 94
add_dependencies(python_api_wheel python_swig_sources
  paddle_parameter
  paddle_math
  paddle_utils
  paddle_gserver
  paddle_pserver
  paddle_trainer
  paddle_api
  paddle_cuda)
Z
zhangjinchao01 已提交
95 96

if(WITH_TESTING)
97 98 99 100 101 102 103 104 105 106 107 108 109 110
    IF(NOT PY_PIP_FOUND)
        SET(PIP_SOURCES_DIR ${PYTHON_SOURCES_DIR}/pip)
        ExternalProject_Add(pip
            ${EXTERNAL_PROJECT_LOG_ARGS}
            GIT_REPOSITORY      https://github.com/pypa/pip.git
            GIT_TAG             9.0.1
            PREFIX              ${PIP_SOURCES_DIR}
            CONFIGURE_COMMAND   ""
            BUILD_COMMAND       ""
            INSTALL_COMMAND     env ${py_env} ${PYTHON_EXECUTABLE} setup.py install
            BUILD_IN_SOURCE     1
            DEPENDS python setuptools python_api_wheel
        )
    ENDIF()
Z
zhangjinchao01 已提交
111 112
    add_subdirectory(test)
endif()