util.cmake 1.5 KB
Newer Older
L
liaogang 已提交
1
# Some common routine for paddle compile.
Z
zhangjinchao01 已提交
2 3 4 5 6 7 8

# target_circle_link_libraries
# Link libraries to target which has circle dependencies.
#
# First Argument: target name want to be linked with libraries
# Rest Arguments: libraries which link together.
function(target_circle_link_libraries TARGET_NAME)
9 10 11 12
  if(APPLE)
    set(LIBS)
    set(inArchive OFF)
    set(libsInArgn)
Y
Yu Yang 已提交
13

14 15 16 17 18 19 20 21
    foreach(arg ${ARGN})
      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")
L
liaogang 已提交
22
        endif()
23 24 25 26 27 28 29 30 31 32 33 34
        list(APPEND LIBS ${arg})
        list(APPEND libsInArgn ${arg})
      endif()
    endforeach()
    if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}"
                                                      STREQUAL "AppleClang")
      if(NOT IOS_ENABLE_BITCODE)
        list(APPEND LIBS "-undefined dynamic_lookup")
      endif()
    endif()
    list(REVERSE libsInArgn)
    target_link_libraries(${TARGET_NAME} ${LIBS} ${libsInArgn})
Y
Yu Yang 已提交
35

36 37
  else() # LINUX
    set(LIBS)
Y
Yu Yang 已提交
38

39 40 41 42 43 44 45 46 47
    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()
Y
Yu Yang 已提交
48

49 50 51
    target_link_libraries(${TARGET_NAME} "-Wl,--start-group" ${LIBS}
                          "-Wl,--end-group")
  endif()
Z
zhangjinchao01 已提交
52
endfunction()