CMakeLists.txt 3.3 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})
Y
Yu Yang 已提交
19
add_dependencies(paddle_api paddle_proto paddle_trainer_lib)
Z
zhangjinchao01 已提交
20

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

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

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

Y
Yiqun Liu 已提交
28 29 30 31 32 33 34 35 36 37
SET(SWIG_NEED_FLAGS
    -ftls-model=global-dynamic
    -Wno-parentheses-equality
    -Wno-self-assign
    -Wno-maybe-uninitialized
    -Wno-missing-field-initializers)
  FOREACH(flag ${SWIG_NEED_FLAGS})
  safe_set_cxxflag(SWIG_CXX_FLAGS ${flag})
ENDFOREACH()

L
liaogang 已提交
38
SET(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR})
Y
Yiqun Liu 已提交
39
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SWIG_CXX_FLAGS}")
40

L
liaogang 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53
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}
54
    ${RDMA_LIBS}
Z
zhangjinchao01 已提交
55 56
)

L
liaogang 已提交
57
IF(APPLE)
58
    SET(MACOS_LD_FLAGS "-undefined dynamic_lookup -Wl,-all_load -framework CoreFoundation -framework Security")
L
liaogang 已提交
59
ELSE(APPLE)
60 61
    SET(START_GROUP "-Xlinker -start-group")
    SET(END_GROUP "-Xlinker -end-group")
L
liaogang 已提交
62 63
    SET(ARCHIVE_START "-Wl,--whole-archive")
    SET(ARCHIVE_END "-Wl,--no-whole-archive")
L
liaogang 已提交
64
ENDIF(APPLE)
Z
zhangjinchao01 已提交
65

L
liaogang 已提交
66 67
SWIG_ADD_MODULE(swig_paddle python Paddle.i)
SWIG_LINK_LIBRARIES(swig_paddle
L
liaogang 已提交
68
    ${MACOS_LD_FLAGS}
69
    ${START_GROUP}
L
liaogang 已提交
70
    ${ARCHIVE_START}
L
liaogang 已提交
71 72 73
    paddle_gserver
    paddle_function
    ${METRIC_LIBS}
L
liaogang 已提交
74
    ${ARCHIVE_END}
75 76 77 78
    paddle_pserver
    paddle_trainer_lib
    paddle_network
    paddle_parameter
G
gongweibao 已提交
79
    paddle_optimizer
80 81 82 83 84 85 86 87
    paddle_math
    paddle_utils
    paddle_proto
    paddle_cuda
    paddle_api
    ${CMAKE_DL_LIBS}
    ${EXTERNAL_LIBS}
    ${CMAKE_THREAD_LIBS_INIT}
88
    ${RDMA_LD_FLAGS}
89
    ${START_END}
L
liaogang 已提交
90
)
E
emailweixu 已提交
91

92 93 94 95 96
add_custom_command(OUTPUT ${PADDLE_BINARY_DIR}/python/py_paddle/_swig_paddle.so
    COMMAND ${CMAKE_COMMAND} -E make_directory ${PADDLE_BINARY_DIR}/python/py_paddle
    COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/swig_paddle.py ${PADDLE_BINARY_DIR}/python/py_paddle
    COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/_swig_paddle.so ${PADDLE_BINARY_DIR}/python/py_paddle
    COMMAND ${CMAKE_COMMAND} -E touch ${PADDLE_BINARY_DIR}/.timestamp
97
    WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}/paddle
L
liaogang 已提交
98
    DEPENDS _swig_paddle
Z
zhangjinchao01 已提交
99 100
)

L
liaogang 已提交
101
# TODO(yuyang18) : make wheel name calculated by cmake
102
add_custom_target(python_api_wheel ALL DEPENDS ${PADDLE_BINARY_DIR}/python/py_paddle/_swig_paddle.so)
Z
zhangjinchao01 已提交
103 104

if(WITH_TESTING)
105 106 107 108 109 110 111 112 113 114 115
    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
116
            #DEPENDS python setuptools python_api_wheel
117 118
        )
    ENDIF()
Z
zhangjinchao01 已提交
119 120
    add_subdirectory(test)
endif()