From 738b6894bce2b84c87431f1f84edbde7be4f4f24 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Mon, 12 Sep 2016 22:13:25 +0800 Subject: [PATCH] Make whole-archive to less library * Also make use cmake find to zlib. * circle link in osx, use reverse link all libs instead. But maybe osx just don't care circle link. --- CMakeLists.txt | 1 + cmake/util.cmake | 70 +++++++++++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 007f1f18bb..99c6c0d373 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ find_package(CUDA QUIET) find_package(Protobuf REQUIRED) find_package(PythonLibs 2.7 REQUIRED) find_package(PythonInterp 2.7 REQUIRED) +find_package(ZLIB REQUIRED) find_package(NumPy) find_package(Threads REQUIRED) find_package(Glog) diff --git a/cmake/util.cmake b/cmake/util.cmake index f3227d27c5..a91e1d5643 100644 --- a/cmake/util.cmake +++ b/cmake/util.cmake @@ -1,19 +1,3 @@ -# MAC OS does not contain start-up and whole-archive args -if(APPLE) - set(GROUP_START "") - set(GROUP_END "") - - set(ARCHIVE_START "") - set(ARCHIVE_END "") -else() - set(GROUP_START "-Wl,--start-group") - set(GROUP_END "-Wl,--end-group") - - set(ARCHIVE_START "-Wl,--whole-archive") - set(ARCHIVE_END "-Wl,--no-whole-archive") -endif() - - # Some common routine for paddle compile. # target_circle_link_libraries @@ -23,17 +7,46 @@ endif() # Rest Arguments: libraries which link together. function(target_circle_link_libraries TARGET_NAME) if(APPLE) + set(LIBS) + set(inArchive OFF) + set(libsInArgn) + foreach(arg ${ARGN}) - list(APPEND OSX_LIBRARIES "-Wl,-force_load" "${arg}") + if(${arg} STREQUAL "ARCHIVE_START") + set(inArchive ON) + elseif(${arg} STREQUAL "ARCHIVE_END") + set(inArchive OFF) + else() + if(inArchive) + list(APPEND LIBS "-Wl,-force_load") + endif() + list(APPEND LIBS ${arg}) + list(APPEND libsInArgn ${arg}) + endif() endforeach() + + list(REVERSE libsInArgn) target_link_libraries(${TARGET_NAME} - ${OSX_LIBRARIES} -lz) - else() + ${LIBS} + ${libsInArgn}) + + else() # LINUX + set(LIBS) + + foreach(arg ${ARGN}) + if(${arg} STREQUAL "ARCHIVE_START") + list(APPEND LIBS "-Wl,--whole-archive") + elseif(${arg} STREQUAL "ARCHIVE_END") + list(APPEND LIBS "-Wl,--no-whole-archive") + else() + list(APPEND LIBS ${arg}) + endif() + endforeach() + target_link_libraries(${TARGET_NAME} - ${GROUP_START} - ${ARGN} - -lz - ${GROUP_END}) + "-Wl,--start-group" + ${LIBS} + "-Wl,--end-group") endif() endfunction() @@ -65,20 +78,20 @@ function(link_paddle_exe TARGET_NAME) if(PADDLE_WITH_INTERNAL) set(INTERAL_LIBS paddle_internal_gserver paddle_internal_parameter) target_circle_link_libraries(${TARGET_NAME} - ${ARCHIVE_START} + ARCHIVE_START paddle_internal_gserver paddle_internal_owlqn - ${ARCHIVE_END} + ARCHIVE_END paddle_internal_parameter) else() set(INTERAL_LIBS "") endif() target_circle_link_libraries(${TARGET_NAME} - ${ARCHIVE_START} + ARCHIVE_START paddle_gserver ${METRIC_LIBS} - ${ARCHIVE_END} + ARCHIVE_END paddle_pserver paddle_trainer_lib paddle_network @@ -92,7 +105,8 @@ function(link_paddle_exe TARGET_NAME) ${CMAKE_THREAD_LIBS_INIT} ${CBLAS_LIBS} ${CMAKE_DL_LIBS} - ${INTERAL_LIBS}) + ${INTERAL_LIBS} + ${ZLIB_LIBRARIES}) if(WITH_PYTHON) target_link_libraries(${TARGET_NAME} -- GitLab