File: target_link_static_libraries.cmake

package info (click to toggle)
telegram-desktop 2.6.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,024 kB
  • sloc: cpp: 411,999; xml: 34,087; python: 2,199; sh: 1,103; ansic: 861; objc: 258; javascript: 174; makefile: 46
file content (65 lines) | stat: -rw-r--r-- 2,766 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# This file is part of Desktop App Toolkit,
# a set of libraries for developing nice desktop applications.
#
# For license and copyright information please follow this link:
# https://github.com/desktop-app/legal/blob/master/LEGAL

function(target_link_static_libraries target_name)
    set(list ${ARGV})
    list(REMOVE_AT list 0)

    set(writing_now "")
    set(private_libs "")
    set(public_libs "")
    set(interface_libs "")
    set(ignore_nonexisting 0)
    set(ignored_libs "")
    foreach (entry ${list})
        if (${entry} STREQUAL "PRIVATE" OR ${entry} STREQUAL "PUBLIC" OR ${entry} STREQUAL "INTERFACE")
            set(writing_now ${entry})
        elseif (${entry} STREQUAL "IGNORE_NONEXISTING")
            set(ignore_nonexisting 1)
        else()
            find_library(static_lib_${entry} lib${entry}.a)
            set(full_path "${static_lib_${entry}}")
            if (${full_path} STREQUAL static_lib_${entry}-NOTFOUND)
                if (ignore_nonexisting)
                    if (NOT entry IN_LIST ignored_libs)
                        message(VERBOSE "Could not find static library lib${entry}.a, using shared one...")
                        list(APPEND ignored_libs ${entry})
                    endif()
                    if (APPLE)
                        find_library(shared_lib_${entry} lib${entry}.dylib)
                        set(full_path "${shared_lib_${entry}}")
                        if (${full_path} STREQUAL shared_lib_${entry}-NOTFOUND)
                            message(FATAL_ERROR "Could not find shared library lib${entry}.dylib")
                        endif()
                    else()
                        set(full_path ${entry})
                    endif()
                else()
                    message(FATAL_ERROR "Could not find static library lib${entry}.a")
                endif()
            endif()
            if ("${writing_now}" STREQUAL "PRIVATE")
                list(APPEND private_libs ${full_path})
            elseif ("${writing_now}" STREQUAL "PUBLIC")
                list(APPEND public_libs ${full_path})
            elseif ("${writing_now}" STREQUAL "INTERFACE")
                list(APPEND interface_libs ${full_path})
            else()
                message(FATAL_ERROR "Unknown frameworks scope for target ${target_name}")
            endif()
        endif()
    endforeach()

    if (NOT "${public_libs}" STREQUAL "")
        target_link_libraries(${target_name} PUBLIC ${public_libs})
    endif()
    if (NOT "${private_libs}" STREQUAL "")
        target_link_libraries(${target_name} PRIVATE ${private_libs})
    endif()
    if (NOT "${interface_libs}" STREQUAL "")
        target_link_libraries(${target_name} INTERFACE ${interface_libs})
    endif()
endfunction()