CMakeLists.txt 3.1 KB
Newer Older
Z
zhangjinchao01 已提交
1 2 3
set(API_SOURCES
    Arguments.cpp
    ConfigParser.cpp
Y
Yu Yang 已提交
4
    Evaluator.cpp
Z
zhangjinchao01 已提交
5 6 7 8
    GradientMachine.cpp
    Matrix.cpp
    Parameter.cpp
    ParameterOptimizer.cpp
Y
Yu Yang 已提交
9
    ParameterUpdater.cpp
Z
zhangjinchao01 已提交
10 11 12 13 14 15 16 17
    SequenceGenerator.cpp
    Trainer.cpp
    Util.cpp
    Vector.cpp)
set(API_HEADER
    PaddleAPI.h
    Internal.h)

L
liaogang 已提交
18
add_library(paddle_api STATIC ${API_SOURCES})
Z
zhangjinchao01 已提交
19 20
add_dependencies(paddle_api gen_proto_cpp)

L
liaogang 已提交
21 22
INCLUDE(${SWIG_USE_FILE})
INCLUDE_DIRECTORIES(${PROJ_ROOT}/paddle)
Z
zhangjinchao01 已提交
23

L
liaogang 已提交
24 25 26
FILE(GLOB PY_PADDLE_PYTHON_FILES ${PROJ_ROOT}/paddle/py_paddle/*.py)

SET_SOURCE_FILES_PROPERTIES(Paddle.i PROPERTIES CPLUSPLUS ON)
Z
zhangjinchao01 已提交
27

L
liaogang 已提交
28
SET(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR})
H
hedaoyuan 已提交
29
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -Wall")
30 31 32 33
IF(WITH_COVERAGE)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
ENDIF(WITH_COVERAGE)

L
liaogang 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46
SET(SWIG_MODULE_swig_paddle_EXTRA_DEPS
    paddle_parameter
    paddle_function
    paddle_math
    paddle_utils
    paddle_gserver
    paddle_pserver
    paddle_api
    paddle_cuda
    paddle_trainer_lib
    paddle_network
    paddle_proto
    ${external_project_dependencies}
Z
zhangjinchao01 已提交
47 48
)

L
liaogang 已提交
49
IF(APPLE)
L
liaogang 已提交
50
    SET(MACOS_LD_FLAGS "-undefined dynamic_lookup -Wl,-all_load")
L
liaogang 已提交
51
ELSE(APPLE)
52 53
    SET(START_GROUP "-Xlinker -start-group")
    SET(END_GROUP "-Xlinker -end-group")
L
liaogang 已提交
54 55
    SET(ARCHIVE_START "-Wl,--whole-archive")
    SET(ARCHIVE_END "-Wl,--no-whole-archive")
L
liaogang 已提交
56
ENDIF(APPLE)
Z
zhangjinchao01 已提交
57

L
liaogang 已提交
58 59
SWIG_ADD_MODULE(swig_paddle python Paddle.i)
SWIG_LINK_LIBRARIES(swig_paddle
L
liaogang 已提交
60
    ${MACOS_LD_FLAGS}
61
    ${START_GROUP}
L
liaogang 已提交
62
    ${ARCHIVE_START}
L
liaogang 已提交
63 64 65
    paddle_gserver
    paddle_function
    ${METRIC_LIBS}
L
liaogang 已提交
66
    ${ARCHIVE_END}
67 68 69 70 71 72 73 74 75 76 77 78 79
    paddle_pserver
    paddle_trainer_lib
    paddle_network
    paddle_parameter
    paddle_math
    paddle_utils
    paddle_proto
    paddle_cuda
    paddle_api
    ${CMAKE_DL_LIBS}
    ${EXTERNAL_LIBS}
    ${CMAKE_THREAD_LIBS_INIT}
    ${START_END}
L
liaogang 已提交
80
)
E
emailweixu 已提交
81

L
liaogang 已提交
82 83 84
add_custom_command(OUTPUT ${PROJ_ROOT}/paddle/py_paddle/_swig_paddle.so
    COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/swig_paddle.py ${PROJ_ROOT}/paddle/py_paddle
    COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/_swig_paddle.so ${PROJ_ROOT}/paddle/py_paddle
L
liaogang 已提交
85
    COMMAND env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel
86 87
    COMMAND ${CMAKE_COMMAND} -E touch dist/.timestamp
    COMMAND rm -rf py_paddle.egg-info build
Z
zhangjinchao01 已提交
88
    WORKING_DIRECTORY ${PROJ_ROOT}/paddle
L
liaogang 已提交
89
    DEPENDS _swig_paddle
Z
zhangjinchao01 已提交
90 91
)

L
liaogang 已提交
92 93
# TODO(yuyang18) : make wheel name calculated by cmake
add_custom_target(python_api_wheel ALL DEPENDS ${PROJ_ROOT}/paddle/py_paddle/_swig_paddle.so)
Z
zhangjinchao01 已提交
94

Y
Yi Wang 已提交
95
install(DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/dist/
Y
Yi Wang 已提交
96 97
    DESTINATION opt/paddle/share/wheels
)
Z
zhangjinchao01 已提交
98 99

if(WITH_TESTING)
100 101 102 103 104 105 106 107 108 109 110 111 112 113
    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 已提交
114 115
    add_subdirectory(test)
endif()