util.cmake 1.7 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)
L
liaogang 已提交
9
    if(APPLE)
Y
Yu Yang 已提交
10 11 12 13
        set(LIBS)
        set(inArchive OFF)
        set(libsInArgn)

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

L
liaogang 已提交
50
        target_link_libraries(${TARGET_NAME}
Y
Yu Yang 已提交
51 52 53
                "-Wl,--start-group"
                ${LIBS}
                "-Wl,--end-group")
L
liaogang 已提交
54
    endif()
Z
zhangjinchao01 已提交
55
endfunction()