From 9b5d41b63697ea9f126b57d28e8d3940d09ce55a Mon Sep 17 00:00:00 2001 From: Luo Tao Date: Tue, 30 Jan 2018 17:37:26 +0800 Subject: [PATCH 1/4] make inference_lib_dist --- cmake/external/eigen.cmake | 12 +++++++----- cmake/external/gflags.cmake | 9 ++++++++- cmake/external/glog.cmake | 9 ++++++++- cmake/external/protobuf.cmake | 9 ++++++++- paddle/framework/CMakeLists.txt | 13 +++++++------ paddle/inference/CMakeLists.txt | 13 +++++++++---- paddle/memory/CMakeLists.txt | 12 ++++++------ paddle/platform/CMakeLists.txt | 14 +++++++------- paddle/string/CMakeLists.txt | 11 ++++++----- 9 files changed, 66 insertions(+), 36 deletions(-) diff --git a/cmake/external/eigen.cmake b/cmake/external/eigen.cmake index d49c8d601102c..eb6c0cef5746e 100644 --- a/cmake/external/eigen.cmake +++ b/cmake/external/eigen.cmake @@ -29,8 +29,10 @@ add_dependencies(eigen3 extern_eigen3) LIST(APPEND external_project_dependencies eigen3) -IF(NOT WITH_C_API AND WITH_FLUID) - INSTALL(FILES ${EIGEN_INCLUDE_DIR}/Eigen/Core DESTINATION third_party/eigen3/Eigen) - INSTALL(DIRECTORY ${EIGEN_INCLUDE_DIR}/Eigen/src DESTINATION third_party/eigen3/Eigen) - INSTALL(DIRECTORY ${EIGEN_INCLUDE_DIR}/unsupported/Eigen DESTINATION third_party/eigen3/unsupported) -ENDIF() +set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/eigen3") +add_custom_target(eigen3_lib + COMMAND mkdir -p "${lib_dir}/Eigen" "${lib_dir}/unsupported" + COMMAND cp "${EIGEN_INCLUDE_DIR}/Eigen/Core" "${lib_dir}/Eigen" + COMMAND cp -r "${EIGEN_INCLUDE_DIR}/Eigen/src" "${lib_dir}/Eigen" + COMMAND cp -r "${EIGEN_INCLUDE_DIR}/unsupported/Eigen" "${lib_dir}/unsupported" +) diff --git a/cmake/external/gflags.cmake b/cmake/external/gflags.cmake index 60946304541a2..9cbc376ba0edc 100644 --- a/cmake/external/gflags.cmake +++ b/cmake/external/gflags.cmake @@ -52,7 +52,7 @@ ADD_DEPENDENCIES(gflags extern_gflags) LIST(APPEND external_project_dependencies gflags) -IF(WITH_C_API OR WITH_FLUID) +IF(WITH_C_API) INSTALL(DIRECTORY ${GFLAGS_INCLUDE_DIR} DESTINATION third_party/gflags) IF(ANDROID) INSTALL(FILES ${GFLAGS_LIBRARIES} DESTINATION third_party/gflags/lib/${ANDROID_ABI}) @@ -60,3 +60,10 @@ IF(WITH_C_API OR WITH_FLUID) INSTALL(FILES ${GFLAGS_LIBRARIES} DESTINATION third_party/gflags/lib) ENDIF() ENDIF() + +set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/gflags") +add_custom_target(gflags_lib + COMMAND mkdir -p "${lib_dir}/lib" + COMMAND cp -r "${GFLAGS_INCLUDE_DIR}" "${lib_dir}" + COMMAND cp "${GFLAGS_LIBRARIES}" "${lib_dir}/lib" +) diff --git a/cmake/external/glog.cmake b/cmake/external/glog.cmake index 382fbda3b5cfe..0031225a6cb63 100644 --- a/cmake/external/glog.cmake +++ b/cmake/external/glog.cmake @@ -68,7 +68,7 @@ LINK_LIBRARIES(glog gflags) LIST(APPEND external_project_dependencies glog) -IF(WITH_C_API OR WITH_FLUID) +IF(WITH_C_API) INSTALL(DIRECTORY ${GLOG_INCLUDE_DIR} DESTINATION third_party/glog) IF(ANDROID) INSTALL(FILES ${GLOG_LIBRARIES} DESTINATION third_party/glog/lib/${ANDROID_ABI}) @@ -76,3 +76,10 @@ IF(WITH_C_API OR WITH_FLUID) INSTALL(FILES ${GLOG_LIBRARIES} DESTINATION third_party/glog/lib) ENDIF() ENDIF() + +set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/glog") +add_custom_target(glog_lib + COMMAND mkdir -p "${lib_dir}/lib" + COMMAND cp -r "${GLOG_INCLUDE_DIR}" "${lib_dir}" + COMMAND cp "${GLOG_LIBRARIES}" "${lib_dir}/lib" +) diff --git a/cmake/external/protobuf.cmake b/cmake/external/protobuf.cmake index 365a370a9cfb7..ff3d38a691a99 100644 --- a/cmake/external/protobuf.cmake +++ b/cmake/external/protobuf.cmake @@ -250,7 +250,7 @@ IF(NOT PROTOBUF_FOUND) SET(PROTOBUF_PROTOC_LIBRARY ${extern_protobuf_PROTOC_LIBRARY} CACHE FILEPATH "protoc library." FORCE) - IF(WITH_C_API OR WITH_FLUID) + IF(WITH_C_API) INSTALL(DIRECTORY ${PROTOBUF_INCLUDE_DIR} DESTINATION third_party/protobuf) IF(ANDROID) INSTALL(FILES ${PROTOBUF_LITE_LIBRARY} DESTINATION third_party/protobuf/lib/${ANDROID_ABI}) @@ -259,6 +259,13 @@ IF(NOT PROTOBUF_FOUND) ENDIF() ENDIF() + set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/protobuf") + add_custom_target(protobuf_lib + COMMAND mkdir -p "${lib_dir}/lib" + COMMAND cp -r "${PROTOBUF_INCLUDE_DIR}" "${lib_dir}" + COMMAND cp "${PROTOBUF_LITE_LIBRARY}" "${lib_dir}/lib" + ) + IF(CMAKE_CROSSCOMPILING) PROMPT_PROTOBUF_LIB(protobuf_host extern_protobuf) ELSE() diff --git a/paddle/framework/CMakeLists.txt b/paddle/framework/CMakeLists.txt index 8c28709a68bec..d394fa5d10d50 100644 --- a/paddle/framework/CMakeLists.txt +++ b/paddle/framework/CMakeLists.txt @@ -92,11 +92,12 @@ cc_test(init_test SRCS init_test.cc DEPS init) cc_test(op_kernel_type_test SRCS op_kernel_type_test.cc DEPS place device_context framework_proto) cc_test(cow_ptr_tests SRCS details/cow_ptr_test.cc) -if(NOT WITH_C_API AND WITH_FLUID) - file(GLOB FRAMEWORK_HEADERS *.h) - install(FILES ${FRAMEWORK_HEADERS} DESTINATION include/paddle/framework) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/framework.pb.h DESTINATION include/paddle/framework) - install(FILES details/cow_ptr.h details/op_registry.h DESTINATION include/paddle/framework/details) -endif() +set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/framework") +add_custom_target(framework_lib DEPENDS framework_py_proto + COMMAND mkdir -p "${lib_dir}/details" + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${lib_dir}" + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/details/*.h" "${lib_dir}/details" + COMMAND cp "${CMAKE_CURRENT_BINARY_DIR}/framework.pb.h" "${lib_dir}" +) cc_test(channel_test SRCS channel_test.cc) diff --git a/paddle/inference/CMakeLists.txt b/paddle/inference/CMakeLists.txt index 683aaee42a4f0..58c0c59380e71 100644 --- a/paddle/inference/CMakeLists.txt +++ b/paddle/inference/CMakeLists.txt @@ -19,10 +19,15 @@ target_circle_link_libraries(paddle_fluid_shared SET_TARGET_PROPERTIES(paddle_fluid_shared PROPERTIES OUTPUT_NAME paddle_fluid) # install library & headers -if(NOT WITH_C_API AND WITH_FLUID) - install(FILES io.h DESTINATION include/paddle/inference) - install(TARGETS paddle_fluid_shared DESTINATION lib) -endif() +set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/inference") +add_custom_target(inference_lib DEPENDS paddle_fluid_shared + COMMAND mkdir -p "${lib_dir}" + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${lib_dir}" + COMMAND cp "${CMAKE_CURRENT_BINARY_DIR}/libpaddle_fluid.so" "${lib_dir}" +) +add_custom_target(inference_lib_dist DEPENDS + inference_lib framework_lib memory_lib platform_lib string_lib + gflags_lib glog_lib protobuf_lib eigen3_lib) add_executable(example example.cc) if(APPLE) diff --git a/paddle/memory/CMakeLists.txt b/paddle/memory/CMakeLists.txt index 496098f804238..fad49346f2318 100644 --- a/paddle/memory/CMakeLists.txt +++ b/paddle/memory/CMakeLists.txt @@ -15,9 +15,9 @@ cc_library(paddle_memory cc_test(memory_test SRCS memory_test.cc DEPS place paddle_memory) -if(NOT WITH_C_API AND WITH_FLUID) - file(GLOB MEMORY_HEADERS *.h) - file(GLOB MEMORY_DETAIL_HEADERS detail/*.h) - install(FILES ${MEMORY_HEADERS} DESTINATION include/paddle/memory) - install(FILES ${MEMORY_DETAIL_HEADERS} DESTINATION include/paddle/memory/detail) -endif() +set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/memory") +add_custom_target(memory_lib + COMMAND mkdir -p "${lib_dir}/detail" + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${lib_dir}" + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/detail/*.h" "${lib_dir}/detail" +) diff --git a/paddle/platform/CMakeLists.txt b/paddle/platform/CMakeLists.txt index d68caea99719b..d70530aadb8d2 100644 --- a/paddle/platform/CMakeLists.txt +++ b/paddle/platform/CMakeLists.txt @@ -40,10 +40,10 @@ nv_test(nccl_test SRCS nccl_test.cu DEPS dynload_cuda gpu_info device_context) cc_library(profiler SRCS profiler.cc DEPS device_context) cc_test(profiler_test SRCS profiler_test.cc DEPS profiler) -if(NOT WITH_C_API AND WITH_FLUID) - file(GLOB PLATFORM_HEADERS *.h) - file(GLOB PLATFORM_dynload_HEADERS dynload/*.h) - install(FILES ${PLATFORM_HEADERS} DESTINATION include/paddle/platform) - install(FILES ${PLATFORM_HEADERS} DESTINATION include/paddle/platform/dynload) - install(FILES details/device_ptr_cast.h DESTINATION include/paddle/platform/details) -endif() +set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/platform") +add_custom_target(platform_lib + COMMAND mkdir -p "${lib_dir}/dynload" "${lib_dir}/details" + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${lib_dir}" + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/dynload/*.h" "${lib_dir}/dynload" + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/details/*.h" "${lib_dir}/details" +) diff --git a/paddle/string/CMakeLists.txt b/paddle/string/CMakeLists.txt index 751776dbb5c00..234a9a6d036fb 100644 --- a/paddle/string/CMakeLists.txt +++ b/paddle/string/CMakeLists.txt @@ -3,8 +3,9 @@ cc_test(stringpiece_test SRCS piece_test.cc DEPS stringpiece glog gflags) cc_test(stringprintf_test SRCS printf_test.cc DEPS glog gflags) cc_test(to_string_test SRCS to_string_test.cc) -if(NOT WITH_C_API AND WITH_FLUID) - file(GLOB STRING_HEADERS *.h) - install(FILES ${STRING_HEADERS} DESTINATION include/paddle/string) - install(FILES tinyformat/tinyformat.h DESTINATION include/paddle/string/tinyformat) -endif() +set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/string") +add_custom_target(string_lib + COMMAND mkdir -p "${lib_dir}/tinyformat" + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${lib_dir}" + COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/tinyformat/*.h" "${lib_dir}/tinyformat" +) From 55b5f29ea44cc5e94061dd4a92e6cbf11d7f2346 Mon Sep 17 00:00:00 2001 From: Luo Tao Date: Tue, 30 Jan 2018 21:14:48 +0800 Subject: [PATCH 2/4] refine paddle_fluid_shared library --- paddle/inference/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/inference/CMakeLists.txt b/paddle/inference/CMakeLists.txt index 58c0c59380e71..3f587fa790d1d 100644 --- a/paddle/inference/CMakeLists.txt +++ b/paddle/inference/CMakeLists.txt @@ -13,8 +13,8 @@ add_library(paddle_fluid_shared SHARED io.cc) target_circle_link_libraries(paddle_fluid_shared ARCHIVE_START ${GLOB_OP_LIB} - ARCHIVE_END - ${FLUID_CORE_MODULES}) + ${FLUID_CORE_MODULES} + ARCHIVE_END) SET_TARGET_PROPERTIES(paddle_fluid_shared PROPERTIES OUTPUT_NAME paddle_fluid) From 59e4dd579770df7e0fb7208a11517784a7b02b4e Mon Sep 17 00:00:00 2001 From: Luo Tao Date: Tue, 6 Feb 2018 14:17:35 +0800 Subject: [PATCH 3/4] add independent inference_lib.cmake --- CMakeLists.txt | 1 + cmake/external/eigen.cmake | 8 ---- cmake/external/gflags.cmake | 7 ---- cmake/external/glog.cmake | 7 ---- cmake/external/protobuf.cmake | 7 ---- cmake/inference_lib.cmake | 74 +++++++++++++++++++++++++++++++++ paddle/framework/CMakeLists.txt | 8 ---- paddle/inference/CMakeLists.txt | 11 ----- paddle/memory/CMakeLists.txt | 7 ---- paddle/platform/CMakeLists.txt | 8 ---- paddle/string/CMakeLists.txt | 7 ---- 11 files changed, 75 insertions(+), 70 deletions(-) create mode 100644 cmake/inference_lib.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 49334279f6dc8..3a21574b855bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,6 +156,7 @@ include(rdma) # set rdma libraries include(flags) # set paddle compile flags include(version) # set PADDLE_VERSION include(coveralls) # set code coverage +include(inference_lib) # add paddle fluid inference libraries include_directories("${PADDLE_SOURCE_DIR}") diff --git a/cmake/external/eigen.cmake b/cmake/external/eigen.cmake index eb6c0cef5746e..6a701e076c953 100644 --- a/cmake/external/eigen.cmake +++ b/cmake/external/eigen.cmake @@ -28,11 +28,3 @@ endif() add_dependencies(eigen3 extern_eigen3) LIST(APPEND external_project_dependencies eigen3) - -set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/eigen3") -add_custom_target(eigen3_lib - COMMAND mkdir -p "${lib_dir}/Eigen" "${lib_dir}/unsupported" - COMMAND cp "${EIGEN_INCLUDE_DIR}/Eigen/Core" "${lib_dir}/Eigen" - COMMAND cp -r "${EIGEN_INCLUDE_DIR}/Eigen/src" "${lib_dir}/Eigen" - COMMAND cp -r "${EIGEN_INCLUDE_DIR}/unsupported/Eigen" "${lib_dir}/unsupported" -) diff --git a/cmake/external/gflags.cmake b/cmake/external/gflags.cmake index 9cbc376ba0edc..d4f252bb9f64c 100644 --- a/cmake/external/gflags.cmake +++ b/cmake/external/gflags.cmake @@ -60,10 +60,3 @@ IF(WITH_C_API) INSTALL(FILES ${GFLAGS_LIBRARIES} DESTINATION third_party/gflags/lib) ENDIF() ENDIF() - -set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/gflags") -add_custom_target(gflags_lib - COMMAND mkdir -p "${lib_dir}/lib" - COMMAND cp -r "${GFLAGS_INCLUDE_DIR}" "${lib_dir}" - COMMAND cp "${GFLAGS_LIBRARIES}" "${lib_dir}/lib" -) diff --git a/cmake/external/glog.cmake b/cmake/external/glog.cmake index 0031225a6cb63..0c6b3aafcb4e9 100644 --- a/cmake/external/glog.cmake +++ b/cmake/external/glog.cmake @@ -76,10 +76,3 @@ IF(WITH_C_API) INSTALL(FILES ${GLOG_LIBRARIES} DESTINATION third_party/glog/lib) ENDIF() ENDIF() - -set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/glog") -add_custom_target(glog_lib - COMMAND mkdir -p "${lib_dir}/lib" - COMMAND cp -r "${GLOG_INCLUDE_DIR}" "${lib_dir}" - COMMAND cp "${GLOG_LIBRARIES}" "${lib_dir}/lib" -) diff --git a/cmake/external/protobuf.cmake b/cmake/external/protobuf.cmake index ff3d38a691a99..ff5855052daba 100644 --- a/cmake/external/protobuf.cmake +++ b/cmake/external/protobuf.cmake @@ -259,13 +259,6 @@ IF(NOT PROTOBUF_FOUND) ENDIF() ENDIF() - set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/protobuf") - add_custom_target(protobuf_lib - COMMAND mkdir -p "${lib_dir}/lib" - COMMAND cp -r "${PROTOBUF_INCLUDE_DIR}" "${lib_dir}" - COMMAND cp "${PROTOBUF_LITE_LIBRARY}" "${lib_dir}/lib" - ) - IF(CMAKE_CROSSCOMPILING) PROMPT_PROTOBUF_LIB(protobuf_host extern_protobuf) ELSE() diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake new file mode 100644 index 0000000000000..d71fbce38207a --- /dev/null +++ b/cmake/inference_lib.cmake @@ -0,0 +1,74 @@ +# make package for paddle fluid shared and static library +# third party +set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/eigen3") +add_custom_target(eigen3_lib + COMMAND mkdir -p "${lib_dir}/Eigen" "${lib_dir}/unsupported" + COMMAND cp "${EIGEN_INCLUDE_DIR}/Eigen/Core" "${lib_dir}/Eigen" + COMMAND cp -r "${EIGEN_INCLUDE_DIR}/Eigen/src" "${lib_dir}/Eigen" + COMMAND cp -r "${EIGEN_INCLUDE_DIR}/unsupported/Eigen" "${lib_dir}/unsupported" +) + +set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/gflags") +add_custom_target(gflags_lib + COMMAND mkdir -p "${lib_dir}/lib" + COMMAND cp -r "${GFLAGS_INCLUDE_DIR}" "${lib_dir}" + COMMAND cp "${GFLAGS_LIBRARIES}" "${lib_dir}/lib" +) + +set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/glog") +add_custom_target(glog_lib + COMMAND mkdir -p "${lib_dir}/lib" + COMMAND cp -r "${GLOG_INCLUDE_DIR}" "${lib_dir}" + COMMAND cp "${GLOG_LIBRARIES}" "${lib_dir}/lib" +) + +IF(NOT PROTOBUF_FOUND) + set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/protobuf") + add_custom_target(protobuf_lib + COMMAND mkdir -p "${lib_dir}/lib" + COMMAND cp -r "${PROTOBUF_INCLUDE_DIR}" "${lib_dir}" + COMMAND cp "${PROTOBUF_LITE_LIBRARY}" "${lib_dir}/lib" + ) +ENDIF(NOT PROTOBUF_FOUND) + +# paddle fluid module +set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/framework") +add_custom_target(framework_lib DEPENDS framework_py_proto + COMMAND mkdir -p "${lib_dir}/details" + COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/framework/*.h" "${lib_dir}" + COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/framework/details/*.h" "${lib_dir}/details" + COMMAND cp "${PADDLE_BINARY_DIR}/paddle/framework/framework.pb.h" "${lib_dir}" +) + +set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/memory") +add_custom_target(memory_lib + COMMAND mkdir -p "${lib_dir}/detail" + COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/memory/*.h" "${lib_dir}" + COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/memory/detail/*.h" "${lib_dir}/detail" +) + +set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/inference") +add_custom_target(inference_lib DEPENDS paddle_fluid_shared + COMMAND mkdir -p "${lib_dir}" + COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/inference/*.h" "${lib_dir}" + COMMAND cp "${PADDLE_BINARY_DIR}/paddle/inference/libpaddle_fluid.so" "${lib_dir}" +) + +set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/platform") +add_custom_target(platform_lib + COMMAND mkdir -p "${lib_dir}/dynload" "${lib_dir}/details" + COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/platform/*.h" "${lib_dir}" + COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/platform/dynload/*.h" "${lib_dir}/dynload" + COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/platform/details/*.h" "${lib_dir}/details" +) + +set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/string") +add_custom_target(string_lib + COMMAND mkdir -p "${lib_dir}/tinyformat" + COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/string/*.h" "${lib_dir}" + COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/string/tinyformat/*.h" "${lib_dir}/tinyformat" +) + +add_custom_target(inference_lib_dist DEPENDS + inference_lib framework_lib memory_lib platform_lib string_lib + gflags_lib glog_lib protobuf_lib eigen3_lib) diff --git a/paddle/framework/CMakeLists.txt b/paddle/framework/CMakeLists.txt index a2a0be08d9425..8b3768b23190c 100644 --- a/paddle/framework/CMakeLists.txt +++ b/paddle/framework/CMakeLists.txt @@ -92,12 +92,4 @@ cc_test(init_test SRCS init_test.cc DEPS init) cc_test(op_kernel_type_test SRCS op_kernel_type_test.cc DEPS place device_context framework_proto) cc_test(cow_ptr_tests SRCS details/cow_ptr_test.cc) -set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/framework") -add_custom_target(framework_lib DEPENDS framework_py_proto - COMMAND mkdir -p "${lib_dir}/details" - COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${lib_dir}" - COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/details/*.h" "${lib_dir}/details" - COMMAND cp "${CMAKE_CURRENT_BINARY_DIR}/framework.pb.h" "${lib_dir}" -) - cc_test(channel_test SRCS channel_test.cc) diff --git a/paddle/inference/CMakeLists.txt b/paddle/inference/CMakeLists.txt index e8e0ee210718b..654a6119bdc85 100644 --- a/paddle/inference/CMakeLists.txt +++ b/paddle/inference/CMakeLists.txt @@ -18,17 +18,6 @@ target_circle_link_libraries(paddle_fluid_shared SET_TARGET_PROPERTIES(paddle_fluid_shared PROPERTIES OUTPUT_NAME paddle_fluid) -# install library & headers -set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/inference") -add_custom_target(inference_lib DEPENDS paddle_fluid_shared - COMMAND mkdir -p "${lib_dir}" - COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${lib_dir}" - COMMAND cp "${CMAKE_CURRENT_BINARY_DIR}/libpaddle_fluid.so" "${lib_dir}" -) -add_custom_target(inference_lib_dist DEPENDS - inference_lib framework_lib memory_lib platform_lib string_lib - gflags_lib glog_lib protobuf_lib eigen3_lib) - if(WITH_TESTING) add_subdirectory(tests/book) endif() diff --git a/paddle/memory/CMakeLists.txt b/paddle/memory/CMakeLists.txt index fad49346f2318..1a61c484823b2 100644 --- a/paddle/memory/CMakeLists.txt +++ b/paddle/memory/CMakeLists.txt @@ -14,10 +14,3 @@ cc_library(paddle_memory system_allocator) cc_test(memory_test SRCS memory_test.cc DEPS place paddle_memory) - -set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/memory") -add_custom_target(memory_lib - COMMAND mkdir -p "${lib_dir}/detail" - COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${lib_dir}" - COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/detail/*.h" "${lib_dir}/detail" -) diff --git a/paddle/platform/CMakeLists.txt b/paddle/platform/CMakeLists.txt index d70530aadb8d2..5ce4b3de39d93 100644 --- a/paddle/platform/CMakeLists.txt +++ b/paddle/platform/CMakeLists.txt @@ -39,11 +39,3 @@ nv_test(nccl_test SRCS nccl_test.cu DEPS dynload_cuda gpu_info device_context) cc_library(profiler SRCS profiler.cc DEPS device_context) cc_test(profiler_test SRCS profiler_test.cc DEPS profiler) - -set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/platform") -add_custom_target(platform_lib - COMMAND mkdir -p "${lib_dir}/dynload" "${lib_dir}/details" - COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${lib_dir}" - COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/dynload/*.h" "${lib_dir}/dynload" - COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/details/*.h" "${lib_dir}/details" -) diff --git a/paddle/string/CMakeLists.txt b/paddle/string/CMakeLists.txt index 234a9a6d036fb..1fe7f42ca1c69 100644 --- a/paddle/string/CMakeLists.txt +++ b/paddle/string/CMakeLists.txt @@ -2,10 +2,3 @@ cc_library(stringpiece SRCS piece.cc) cc_test(stringpiece_test SRCS piece_test.cc DEPS stringpiece glog gflags) cc_test(stringprintf_test SRCS printf_test.cc DEPS glog gflags) cc_test(to_string_test SRCS to_string_test.cc) - -set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/string") -add_custom_target(string_lib - COMMAND mkdir -p "${lib_dir}/tinyformat" - COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${lib_dir}" - COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/tinyformat/*.h" "${lib_dir}/tinyformat" -) From f28dc9a68d9db8f711410a60fc57030cfc68ad6e Mon Sep 17 00:00:00 2001 From: Luo Tao Date: Tue, 6 Feb 2018 22:13:27 +0800 Subject: [PATCH 4/4] refine inference_lib.cmake --- cmake/inference_lib.cmake | 114 ++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index d71fbce38207a..7d53554358497 100644 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -1,72 +1,88 @@ # make package for paddle fluid shared and static library +function(copy TARGET) + set(options "") + set(oneValueArgs "") + set(multiValueArgs SRCS DSTS DEPS) + cmake_parse_arguments(copy_lib "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + list(LENGTH copy_lib_SRCS copy_lib_SRCS_len) + list(LENGTH copy_lib_DSTS copy_lib_DSTS_len) + if(NOT ${copy_lib_SRCS_len} EQUAL ${copy_lib_DSTS_len}) + message(FATAL_ERROR "${TARGET} source numbers are not equal to destination numbers") + endif() + math(EXPR len "${copy_lib_SRCS_len} - 1") + + add_custom_target(${TARGET} DEPENDS ${copy_lib_DEPS}) + foreach(index RANGE ${len}) + list(GET copy_lib_SRCS ${index} src) + list(GET copy_lib_DSTS ${index} dst) + add_custom_command(TARGET ${TARGET} PRE_BUILD COMMAND mkdir -p "${dst}") + if(IS_DIRECTORY ${src}) + add_custom_command(TARGET ${TARGET} PRE_BUILD COMMAND cp -r "${src}" "${dst}") + else() + add_custom_command(TARGET ${TARGET} PRE_BUILD COMMAND cp "${src}" "${dst}") + endif() + endforeach() +endfunction() + # third party -set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/eigen3") -add_custom_target(eigen3_lib - COMMAND mkdir -p "${lib_dir}/Eigen" "${lib_dir}/unsupported" - COMMAND cp "${EIGEN_INCLUDE_DIR}/Eigen/Core" "${lib_dir}/Eigen" - COMMAND cp -r "${EIGEN_INCLUDE_DIR}/Eigen/src" "${lib_dir}/Eigen" - COMMAND cp -r "${EIGEN_INCLUDE_DIR}/unsupported/Eigen" "${lib_dir}/unsupported" +set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/eigen3") +copy(eigen3_lib + SRCS ${EIGEN_INCLUDE_DIR}/Eigen/Core ${EIGEN_INCLUDE_DIR}/Eigen/src ${EIGEN_INCLUDE_DIR}/unsupported/Eigen + DSTS ${dst_dir}/Eigen ${dst_dir}/Eigen ${dst_dir}/unsupported ) -set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/gflags") -add_custom_target(gflags_lib - COMMAND mkdir -p "${lib_dir}/lib" - COMMAND cp -r "${GFLAGS_INCLUDE_DIR}" "${lib_dir}" - COMMAND cp "${GFLAGS_LIBRARIES}" "${lib_dir}/lib" +set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/gflags") +copy(gflags_lib + SRCS ${GFLAGS_INCLUDE_DIR} ${GFLAGS_LIBRARIES} + DSTS ${dst_dir} ${dst_dir}/lib ) -set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/glog") -add_custom_target(glog_lib - COMMAND mkdir -p "${lib_dir}/lib" - COMMAND cp -r "${GLOG_INCLUDE_DIR}" "${lib_dir}" - COMMAND cp "${GLOG_LIBRARIES}" "${lib_dir}/lib" +set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/glog") +copy(glog_lib + SRCS ${GLOG_INCLUDE_DIR} ${GLOG_LIBRARIES} + DSTS ${dst_dir} ${dst_dir}/lib ) IF(NOT PROTOBUF_FOUND) - set(lib_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/protobuf") - add_custom_target(protobuf_lib - COMMAND mkdir -p "${lib_dir}/lib" - COMMAND cp -r "${PROTOBUF_INCLUDE_DIR}" "${lib_dir}" - COMMAND cp "${PROTOBUF_LITE_LIBRARY}" "${lib_dir}/lib" + set(dst_dir "${CMAKE_INSTALL_PREFIX}/third_party/install/protobuf") + copy(protobuf_lib + SRCS ${PROTOBUF_INCLUDE_DIR} ${PROTOBUF_LITE_LIBRARY} + DSTS ${dst_dir} ${dst_dir}/lib ) ENDIF(NOT PROTOBUF_FOUND) # paddle fluid module -set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/framework") -add_custom_target(framework_lib DEPENDS framework_py_proto - COMMAND mkdir -p "${lib_dir}/details" - COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/framework/*.h" "${lib_dir}" - COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/framework/details/*.h" "${lib_dir}/details" - COMMAND cp "${PADDLE_BINARY_DIR}/paddle/framework/framework.pb.h" "${lib_dir}" +set(src_dir "${PADDLE_SOURCE_DIR}/paddle") +set(dst_dir "${CMAKE_INSTALL_PREFIX}/paddle") +set(module "framework") +copy(framework_lib DEPS framework_py_proto + SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/details/*.h ${PADDLE_BINARY_DIR}/paddle/framework/framework.pb.h + DSTS ${dst_dir}/${module} ${dst_dir}/${module}/details ${dst_dir}/${module} ) -set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/memory") -add_custom_target(memory_lib - COMMAND mkdir -p "${lib_dir}/detail" - COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/memory/*.h" "${lib_dir}" - COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/memory/detail/*.h" "${lib_dir}/detail" +set(module "memory") +copy(memory_lib + SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/detail/*.h + DSTS ${dst_dir}/${module} ${dst_dir}/${module}/detail ) -set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/inference") -add_custom_target(inference_lib DEPENDS paddle_fluid_shared - COMMAND mkdir -p "${lib_dir}" - COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/inference/*.h" "${lib_dir}" - COMMAND cp "${PADDLE_BINARY_DIR}/paddle/inference/libpaddle_fluid.so" "${lib_dir}" +set(module "inference") +copy(inference_lib DEPENDS paddle_fluid_shared + SRCS ${src_dir}/${module}/*.h ${PADDLE_BINARY_DIR}/paddle/inference/libpaddle_fluid.so + DSTS ${dst_dir}/${module} ${dst_dir}/${module} ) -set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/platform") -add_custom_target(platform_lib - COMMAND mkdir -p "${lib_dir}/dynload" "${lib_dir}/details" - COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/platform/*.h" "${lib_dir}" - COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/platform/dynload/*.h" "${lib_dir}/dynload" - COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/platform/details/*.h" "${lib_dir}/details" -) +set(module "platform") +copy(platform_lib + SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/dynload/*.h ${src_dir}/${module}/details/*.h + DSTS ${dst_dir}/${module} ${dst_dir}/${module}/dynload ${dst_dir}/${module}/details +) -set(lib_dir "${CMAKE_INSTALL_PREFIX}/paddle/string") -add_custom_target(string_lib - COMMAND mkdir -p "${lib_dir}/tinyformat" - COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/string/*.h" "${lib_dir}" - COMMAND cp "${PADDLE_SOURCE_DIR}/paddle/string/tinyformat/*.h" "${lib_dir}/tinyformat" +set(module "string") +copy(string_lib + SRCS ${src_dir}/${module}/*.h ${src_dir}/${module}/tinyformat/*.h + DSTS ${dst_dir}/${module} ${dst_dir}/${module}/tinyformat ) add_custom_target(inference_lib_dist DEPENDS