CMakeLists.txt 3.9 KB
Newer Older
Y
Yu Yang 已提交
1 2 3 4 5 6
if (WITH_DOUBLE)
  set(PADDLE_FLOAT_TYPE double)
else ()
  set(PADDLE_FLOAT_TYPE float)
endif()

7 8 9 10 11 12 13 14 15 16
execute_process(
  COMMAND ${GIT_EXECUTABLE} log --pretty=format:%H -1
  WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
  OUTPUT_VARIABLE PADDLE_GIT_COMMIT
  RESULT_VARIABLE PADDLE_GIT_COMMIT_RESULT
  ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT PADDLE_GIT_COMMIT)
  set(PADDLE_GIT_COMMIT "no commit information")
endif()

Y
Yu Yang 已提交
17 18 19 20
# config.h used for C-API. It will store Paddle building configuration as a
# header. Make user just include PaddleCAPI.h then can get building
# configuration without explicitly set -DPADDLE_WITH_DOUBLE when building their
# libraries.
Y
Yu Yang 已提交
21 22
configure_file(config.h.in config.h @ONLY)

Y
Yu Yang 已提交
23 24
# PaddleCAPI.h is the only header we exposed. It currently only used for model
# inference.
Y
Yu Yang 已提交
25
file(GLOB CAPI_HEADERS *.h)
Y
Yu Yang 已提交
26
set(CAPI_PRIVATE_HEADER capi_private.h)
Y
Yu Yang 已提交
27
list(REMOVE_ITEM CAPI_HEADERS ${CAPI_PRIVATE_HEADER})
Y
Yu Yang 已提交
28 29
file(GLOB CAPI_SOURCES *.cpp)

Y
Yu Yang 已提交
30
# building paddle_capi
Y
Yu Yang 已提交
31 32
add_library(paddle_capi STATIC ${CAPI_HEADERS} ${CAPI_PRIVATE_HEADER}
  ${CAPI_SOURCES})
Y
Yu Yang 已提交
33 34

target_include_directories(paddle_capi PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
Y
Yu Yang 已提交
35

Y
Yu Yang 已提交
36 37
add_style_check_target(paddle_capi ${CAPI_SOURCES} ${CAPI_HEADER}
  ${CAPI_PRIVATE_HEADER})
Y
Yu Yang 已提交
38

Y
Yu Yang 已提交
39
add_dependencies(paddle_capi paddle_proto)
Y
Yu Yang 已提交
40

41
# TODO: paddle_capi_whole will be removed.
42 43 44
set(PADDLE_CAPI_LAYERS_LIBS
    paddle_function
    paddle_gserver)
45
if(MOBILE_INFERENCE)
46 47 48 49 50 51
  set(PADDLE_CAPI_ENGINE_LIBS
      paddle_utils
      paddle_parameter
      paddle_math
      paddle_cuda
      paddle_proto)
52
else()
53 54 55 56 57 58 59 60
  set(PADDLE_CAPI_ENGINE_LIBS
      paddle_utils
      paddle_parameter
      paddle_math
      paddle_cuda
      paddle_proto
      paddle_pserver
      paddle_network)
61
endif()
62
set(PADDLE_CAPI_INFER_LIBS ${PADDLE_CAPI_LAYERS_LIBS} ${PADDLE_CAPI_ENGINE_LIBS})
H
hedaoyuan 已提交
63
cc_library(paddle_capi_whole DEPS paddle_capi ${PADDLE_CAPI_INFER_LIBS})
64

65
# Link the static library for inference
66 67
cc_library(paddle_capi_engine DEPS paddle_capi ${PADDLE_CAPI_ENGINE_LIBS})
cc_library(paddle_capi_layers DEPS ${PADDLE_CAPI_LAYERS_LIBS})
68 69

# Link the shared library for inference
70
if(NOT IOS)
71
  set(LINK_FLAGS "-Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/paddle_capi.map")
72
  add_library(paddle_capi_shared SHARED ${CAPI_SOURCES})
73
  set_target_properties(paddle_capi_shared	PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
74
  target_include_directories(paddle_capi_shared PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
H
hedaoyuan 已提交
75
  link_paddle_exe(paddle_capi_shared)
76
endif()
Y
Yu Yang 已提交
77

Y
Yu Yang 已提交
78
# install library & headers.
Y
Yu Yang 已提交
79
install(FILES ${CAPI_HEADERS} DESTINATION include/paddle)
80
install(FILES paddle_capi.map DESTINATION include/paddle)
Y
Yu Yang 已提交
81
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h DESTINATION include/paddle)
82
if(ANDROID)
H
hedaoyuan 已提交
83
  install(TARGETS paddle_capi_whole paddle_capi_engine paddle_capi_layers paddle_capi_shared
84 85
          ARCHIVE DESTINATION lib/${ANDROID_ABI}
          LIBRARY DESTINATION lib/${ANDROID_ABI})
86 87
  execute_process(
    COMMAND ${GIT_EXECUTABLE} log --pretty=oneline -1
88
    WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    OUTPUT_VARIABLE GIT_COMMITS_LIST
    RESULT_VARIABLE GIT_COMMITS_LIST_RESULT
    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  if(${GIT_COMMITS_LIST_RESULT})
    set(GIT_COMMITS_LIST "No commits.")
  endif()
  install(CODE "FILE(WRITE ${CMAKE_INSTALL_PREFIX}/lib/${ANDROID_ABI}/BUILD.txt
          \"Compiler:\n\"
          \"\\t${CMAKE_C_COMPILER}\\n\"
          \"\\t${CMAKE_CXX_COMPILER}\\n\"
          \"Compiler Flags:\\n\"
          \"\\t${CMAKE_F_FLAGS}\\n\"
          \"\\t${CMAKE_CXX_FLAGS}\\n\"
          \"Android API: ${CMAKE_SYSTEM_VERSION}\\n\"
          \"Lastest commit:\\n\"
          \"\\t${GIT_COMMITS_LIST}\\n\"
      )"
  )
107
else(ANDROID)
H
hedaoyuan 已提交
108
  install(TARGETS paddle_capi_whole paddle_capi_engine paddle_capi_layers ARCHIVE DESTINATION lib)
109 110 111
  if(NOT IOS)
    install(TARGETS paddle_capi_shared DESTINATION lib)
  endif()
112
endif(ANDROID)
Y
Yu Yang 已提交
113 114

# this variable used for unittest
Y
Yu Yang 已提交
115 116 117 118 119 120 121
set(PADDLE_CAPI_INC_PATH
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR})

if (WITH_TESTING)
  add_subdirectory(tests)
endif()