CMakeLists.txt 3.4 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()

Y
Yu Yang 已提交
7 8 9 10
# 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 已提交
11 12
configure_file(config.h.in config.h @ONLY)

Y
Yu Yang 已提交
13 14
# PaddleCAPI.h is the only header we exposed. It currently only used for model
# inference.
Y
Yu Yang 已提交
15
file(GLOB CAPI_HEADERS *.h)
Y
Yu Yang 已提交
16
set(CAPI_PRIVATE_HEADER capi_private.h)
Y
Yu Yang 已提交
17
list(REMOVE_ITEM CAPI_HEADERS ${CAPI_PRIVATE_HEADER})
Y
Yu Yang 已提交
18 19
file(GLOB CAPI_SOURCES *.cpp)

Y
Yu Yang 已提交
20
# building paddle_capi
Y
Yu Yang 已提交
21 22
add_library(paddle_capi STATIC ${CAPI_HEADERS} ${CAPI_PRIVATE_HEADER}
  ${CAPI_SOURCES})
Y
Yu Yang 已提交
23 24

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

Y
Yu Yang 已提交
26 27
add_style_check_target(paddle_capi ${CAPI_SOURCES} ${CAPI_HEADER}
  ${CAPI_PRIVATE_HEADER})
Y
Yu Yang 已提交
28

Y
Yu Yang 已提交
29
add_dependencies(paddle_capi paddle_proto)
Y
Yu Yang 已提交
30

31
# TODO: paddle_capi_whole will be removed.
32
set(PADDLE_CAPI_INFER_LIBS
33 34 35 36 37 38
    paddle_utils
    paddle_parameter
    paddle_math
    paddle_cuda
    paddle_function
    paddle_gserver
39
    paddle_proto)
40
cc_library(paddle_capi_whole DEPS paddle_capi ${PADDLE_CAPI_INFER_LIBS})
41

42
# Link the static library for inference
H
hedaoyuan 已提交
43 44
cc_library(paddle_capi_engine DEPS paddle_capi paddle_utils paddle_parameter paddle_math paddle_cuda paddle_proto)
cc_library(paddle_capi_layers DEPS paddle_function paddle_gserver)
45 46

# Link the shared library for inference
47
if(NOT IOS)
48 49
  set(LINK_FLAGS " -Wl,--retain-symbols-file ${CMAKE_CURRENT_SOURCE_DIR}/export.sym -Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/export.map")
  # TODO: merge mkl into paddle_capi_shared
50
  add_library(paddle_capi_shared SHARED ${CAPI_SOURCES})
51
  set_target_properties(paddle_capi_shared	PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
52
  target_include_directories(paddle_capi_shared PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
H
hedaoyuan 已提交
53
  link_paddle_exe(paddle_capi_shared)
54
endif()
Y
Yu Yang 已提交
55

Y
Yu Yang 已提交
56
# install library & headers.
Y
Yu Yang 已提交
57
install(FILES ${CAPI_HEADERS} DESTINATION include/paddle)
Y
Yu Yang 已提交
58
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h DESTINATION include/paddle)
59
if(ANDROID)
H
hedaoyuan 已提交
60
  install(TARGETS paddle_capi_whole paddle_capi_engine paddle_capi_layers paddle_capi_shared
61 62
          ARCHIVE DESTINATION lib/${ANDROID_ABI}
          LIBRARY DESTINATION lib/${ANDROID_ABI})
63 64
  execute_process(
    COMMAND ${GIT_EXECUTABLE} log --pretty=oneline -1
65
    WORKING_DIRECTORY ${PADDLE_SOURCE_DIR}
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    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\"
      )"
  )
84
else(ANDROID)
H
hedaoyuan 已提交
85
  install(TARGETS paddle_capi_whole paddle_capi_engine paddle_capi_layers ARCHIVE DESTINATION lib)
86 87 88
  if(NOT IOS)
    install(TARGETS paddle_capi_shared DESTINATION lib)
  endif()
89
endif(ANDROID)
Y
Yu Yang 已提交
90 91

# this variable used for unittest
Y
Yu Yang 已提交
92 93 94 95 96 97 98
set(PADDLE_CAPI_INC_PATH
  ${CMAKE_CURRENT_BINARY_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR})

if (WITH_TESTING)
  add_subdirectory(tests)
endif()