提交 738b6894 编写于 作者: Y Yu Yang

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.
上级 0ad0e4ac
...@@ -14,6 +14,7 @@ find_package(CUDA QUIET) ...@@ -14,6 +14,7 @@ find_package(CUDA QUIET)
find_package(Protobuf REQUIRED) find_package(Protobuf REQUIRED)
find_package(PythonLibs 2.7 REQUIRED) find_package(PythonLibs 2.7 REQUIRED)
find_package(PythonInterp 2.7 REQUIRED) find_package(PythonInterp 2.7 REQUIRED)
find_package(ZLIB REQUIRED)
find_package(NumPy) find_package(NumPy)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
find_package(Glog) find_package(Glog)
......
# 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. # Some common routine for paddle compile.
# target_circle_link_libraries # target_circle_link_libraries
...@@ -23,17 +7,46 @@ endif() ...@@ -23,17 +7,46 @@ endif()
# Rest Arguments: libraries which link together. # Rest Arguments: libraries which link together.
function(target_circle_link_libraries TARGET_NAME) function(target_circle_link_libraries TARGET_NAME)
if(APPLE) if(APPLE)
set(LIBS)
set(inArchive OFF)
set(libsInArgn)
foreach(arg ${ARGN}) 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() endforeach()
list(REVERSE libsInArgn)
target_link_libraries(${TARGET_NAME} target_link_libraries(${TARGET_NAME}
${OSX_LIBRARIES} -lz) ${LIBS}
else() ${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} target_link_libraries(${TARGET_NAME}
${GROUP_START} "-Wl,--start-group"
${ARGN} ${LIBS}
-lz "-Wl,--end-group")
${GROUP_END})
endif() endif()
endfunction() endfunction()
...@@ -65,20 +78,20 @@ function(link_paddle_exe TARGET_NAME) ...@@ -65,20 +78,20 @@ function(link_paddle_exe TARGET_NAME)
if(PADDLE_WITH_INTERNAL) if(PADDLE_WITH_INTERNAL)
set(INTERAL_LIBS paddle_internal_gserver paddle_internal_parameter) set(INTERAL_LIBS paddle_internal_gserver paddle_internal_parameter)
target_circle_link_libraries(${TARGET_NAME} target_circle_link_libraries(${TARGET_NAME}
${ARCHIVE_START} ARCHIVE_START
paddle_internal_gserver paddle_internal_gserver
paddle_internal_owlqn paddle_internal_owlqn
${ARCHIVE_END} ARCHIVE_END
paddle_internal_parameter) paddle_internal_parameter)
else() else()
set(INTERAL_LIBS "") set(INTERAL_LIBS "")
endif() endif()
target_circle_link_libraries(${TARGET_NAME} target_circle_link_libraries(${TARGET_NAME}
${ARCHIVE_START} ARCHIVE_START
paddle_gserver paddle_gserver
${METRIC_LIBS} ${METRIC_LIBS}
${ARCHIVE_END} ARCHIVE_END
paddle_pserver paddle_pserver
paddle_trainer_lib paddle_trainer_lib
paddle_network paddle_network
...@@ -92,7 +105,8 @@ function(link_paddle_exe TARGET_NAME) ...@@ -92,7 +105,8 @@ function(link_paddle_exe TARGET_NAME)
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
${CBLAS_LIBS} ${CBLAS_LIBS}
${CMAKE_DL_LIBS} ${CMAKE_DL_LIBS}
${INTERAL_LIBS}) ${INTERAL_LIBS}
${ZLIB_LIBRARIES})
if(WITH_PYTHON) if(WITH_PYTHON)
target_link_libraries(${TARGET_NAME} target_link_libraries(${TARGET_NAME}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册