aboutsummaryrefslogtreecommitdiff
path: root/toolchain/specifydependencies.cmake
blob: 453a77211fabcdc66cb817f864a751d991906e67 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

function(list_dependencies target libs)
    execute_process(COMMAND readelf --wide --dynamic ${target} ERROR_VARIABLE readelf_errors OUTPUT_VARIABLE out RESULT_VARIABLE result)

    if (NOT result EQUAL 0)
        message(FATAL_ERROR "readelf failed on ${target} exit(${result}): ${readelf_errors}")
    endif()

    string(REPLACE "\n" ";" lines "${out}")
    set(extralibs ${${libs}})
    foreach(line ${lines})
        string(REGEX MATCH ".*\\(NEEDED\\) +Shared library: +\\[(.+)\\]$" matched ${line})
        set(currentLib ${CMAKE_MATCH_1})

        if(NOT ${currentLib} MATCHES "libQt5.*" AND matched)
            find_file(ourlib-${currentLib} ${currentLib} HINTS ${OUTPUT_DIR} ${EXPORT_DIR} ${ECM_ADDITIONAL_FIND_ROOT_PATH} NO_DEFAULT_PATH PATH_SUFFIXES lib)

            if(ourlib-${currentLib})
                list(APPEND extralibs "${ourlib-${currentLib}}")
            else()
                message(STATUS "could not find ${currentLib} in ${OUTPUT_DIR} ${EXPORT_DIR} ${ECM_ADDITIONAL_FIND_ROOT_PATH}")
            endif()
        endif()
    endforeach()
    set(${libs} ${extralibs} PARENT_SCOPE)
endfunction()

list_dependencies(${TARGET} extralibs)

function(contains_library libpath IS_EQUAL)
    get_filename_component (name ${libpath} NAME)
    unset (IS_EQUAL PARENT_SCOPE)

    foreach (extralib ${extralibs})
        get_filename_component (extralibname ${extralib} NAME)
        if (${extralibname} STREQUAL ${name})
            set (IS_EQUAL TRUE PARENT_SCOPE)
            break()
        endif()
    endforeach()
endfunction()

if (ANDROID_EXTRA_LIBS)
    foreach (extralib ${ANDROID_EXTRA_LIBS})
        contains_library(${extralib} IS_EQUAL)

        if (IS_EQUAL)
            message (STATUS "found duplicate, skipping: " ${extralib})
        else()
            message(STATUS "manually specified extra library: " ${extralib})
            list(APPEND extralibs ${extralib})
        endif()
    endforeach()
endif()

set(extraplugins)
foreach(folder "plugins" "share" "lib/qml") #now we check for folders with extra stuff
    set(plugin "${EXPORT_DIR}/${folder}")
    if(EXISTS "${plugin}")
        list(APPEND extraplugins "${plugin}")
    endif()
endforeach()

if(EXISTS "module-plugins")
    file(READ "module-plugins" moduleplugins)
    foreach(module ${moduleplugins})
        list_dependencies(${module} extralibs)
    endforeach()
    list(REMOVE_DUPLICATES extralibs)
endif()

if(extralibs)
    string(REPLACE ";" "," extralibs "${extralibs}")
    set(extralibs "\"android-extra-libs\": \"${extralibs}\",")
endif()

if(extraplugins)
    string(REPLACE ";" "," extraplugins "${extraplugins}")
    set(extraplugins "\"android-extra-plugins\": \"${extraplugins}\",")
endif()

file(READ "${INPUT_FILE}" CONTENTS)
file(READ "stl" stl_contents)

file(READ "ranlib" ranlib_contents)
string(REGEX MATCH ".+/toolchains/(.+)-([^\\-]+)/prebuilt/.*/bin/(.*)-ranlib" x ${ranlib_contents})

if (USE_LLVM)
  string(REPLACE "##ANDROID_TOOL_PREFIX##" "llvm" NEWCONTENTS "${CONTENTS}")
  string(REPLACE "##ANDROID_COMPILER_PREFIX##" "llvm" NEWCONTENTS "${NEWCONTENTS}")
  string(REPLACE "##USE_LLVM##" true NEWCONTENTS "${NEWCONTENTS}")
else()
  string(REPLACE "##ANDROID_TOOL_PREFIX##" "${CMAKE_MATCH_1}" NEWCONTENTS "${CONTENTS}")
  string(REPLACE "##ANDROID_COMPILER_PREFIX##" "${CMAKE_MATCH_3}" NEWCONTENTS "${NEWCONTENTS}")
  string(REPLACE "##USE_LLVM##" false NEWCONTENTS "${NEWCONTENTS}")
endif()

string(REPLACE "##ANDROID_TOOLCHAIN_VERSION##" "${CMAKE_MATCH_2}" NEWCONTENTS "${NEWCONTENTS}") # not used when USE_LLVM is set

string(REPLACE "##EXTRALIBS##" "${extralibs}" NEWCONTENTS "${NEWCONTENTS}")
string(REPLACE "##EXTRAPLUGINS##" "${extraplugins}" NEWCONTENTS "${NEWCONTENTS}")
string(REPLACE "##CMAKE_CXX_STANDARD_LIBRARIES##" "${stl_contents}" NEWCONTENTS "${NEWCONTENTS}")
file(WRITE "${OUTPUT_FILE}" ${NEWCONTENTS})