diff options
| author | manuel <manuel@mausz.at> | 2016-11-24 21:27:41 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2016-11-24 21:27:41 +0100 |
| commit | 8cdf8dec703d882b46ca50a769fabb95ffc48e2c (patch) | |
| tree | f7fe8233508f79d3dc94f8f445ce6342e7dfbdbb /project/cmake/scripts/common/HandleDepends.cmake | |
| parent | 5823b05feb29a59510c32a9c28ca18b50b9b6399 (diff) | |
| download | kodi-pvr-build-8cdf8dec703d882b46ca50a769fabb95ffc48e2c.tar.gz kodi-pvr-build-8cdf8dec703d882b46ca50a769fabb95ffc48e2c.tar.bz2 kodi-pvr-build-8cdf8dec703d882b46ca50a769fabb95ffc48e2c.zip | |
sync with upstream
Diffstat (limited to 'project/cmake/scripts/common/HandleDepends.cmake')
| -rw-r--r-- | project/cmake/scripts/common/HandleDepends.cmake | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/project/cmake/scripts/common/HandleDepends.cmake b/project/cmake/scripts/common/HandleDepends.cmake new file mode 100644 index 0000000..880ccdf --- /dev/null +++ b/project/cmake/scripts/common/HandleDepends.cmake | |||
| @@ -0,0 +1,219 @@ | |||
| 1 | include(${CORE_SOURCE_DIR}/project/cmake/scripts/common/CheckTargetPlatform.cmake) | ||
| 2 | |||
| 3 | # handle addon depends | ||
| 4 | function(add_addon_depends addon searchpath) | ||
| 5 | # input: string addon string searchpath | ||
| 6 | |||
| 7 | set(OUTPUT_DIR ${ADDON_DEPENDS_PATH}) | ||
| 8 | # look for platform-specific dependencies | ||
| 9 | file(GLOB_RECURSE cmake_input_files ${searchpath}/${CORE_SYSTEM_NAME}/*.txt) | ||
| 10 | file(GLOB_RECURSE cmake_input_files2 ${searchpath}/common/*.txt) | ||
| 11 | list(APPEND cmake_input_files ${cmake_input_files2}) | ||
| 12 | |||
| 13 | foreach(file ${cmake_input_files}) | ||
| 14 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${file}) | ||
| 15 | if(NOT (file MATCHES CMakeLists.txt OR | ||
| 16 | file MATCHES install.txt OR | ||
| 17 | file MATCHES noinstall.txt OR | ||
| 18 | file MATCHES flags.txt OR | ||
| 19 | file MATCHES deps.txt OR | ||
| 20 | file MATCHES platforms.txt)) | ||
| 21 | message(STATUS "Processing ${file}") | ||
| 22 | file(STRINGS ${file} def) | ||
| 23 | string(REPLACE " " ";" def ${def}) | ||
| 24 | list(LENGTH def deflength) | ||
| 25 | get_filename_component(dir ${file} DIRECTORY) | ||
| 26 | |||
| 27 | # get the id of the dependency | ||
| 28 | if(NOT "${def}" STREQUAL "") | ||
| 29 | # read the id from the file | ||
| 30 | list(GET def 0 id) | ||
| 31 | else() | ||
| 32 | # read the id from the filename | ||
| 33 | get_filename_component(id ${file} NAME_WE) | ||
| 34 | endif() | ||
| 35 | |||
| 36 | # check if the dependency has a platforms.txt | ||
| 37 | set(platform_found FALSE) | ||
| 38 | check_target_platform(${dir} ${CORE_SYSTEM_NAME} platform_found) | ||
| 39 | |||
| 40 | if(${platform_found} AND NOT TARGET ${id}) | ||
| 41 | # determine the download URL of the dependency | ||
| 42 | set(url "") | ||
| 43 | if(deflength GREATER 1) | ||
| 44 | list(GET def 1 url) | ||
| 45 | message(STATUS "${id} url: ${url}") | ||
| 46 | endif() | ||
| 47 | |||
| 48 | # check if there are any library specific flags that need to be passed on | ||
| 49 | if(EXISTS ${dir}/flags.txt) | ||
| 50 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${dir}/flags.txt) | ||
| 51 | file(STRINGS ${dir}/flags.txt extraflags) | ||
| 52 | string(REPLACE " " ";" extraflags ${extraflags}) | ||
| 53 | message(STATUS "${id} extraflags: ${extraflags}") | ||
| 54 | endif() | ||
| 55 | |||
| 56 | set(BUILD_ARGS -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} | ||
| 57 | -DOUTPUT_DIR=${OUTPUT_DIR} | ||
| 58 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
| 59 | -DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_USER_MAKE_RULES_OVERRIDE} | ||
| 60 | -DCMAKE_USER_MAKE_RULES_OVERRIDE_CXX=${CMAKE_USER_MAKE_RULES_OVERRIDE_CXX} | ||
| 61 | -DCMAKE_INSTALL_PREFIX=${OUTPUT_DIR} | ||
| 62 | -DCORE_SYSTEM_NAME=${CORE_SYSTEM_NAME} | ||
| 63 | -DENABLE_STATIC=1 | ||
| 64 | -DBUILD_SHARED_LIBS=0) | ||
| 65 | # if there are no make rules override files available take care of manually passing on ARCH_DEFINES | ||
| 66 | if(NOT CMAKE_USER_MAKE_RULES_OVERRIDE AND NOT CMAKE_USER_MAKE_RULES_OVERRIDE_CXX) | ||
| 67 | # make sure we create strings, not lists | ||
| 68 | set(TMP_C_FLAGS "${CMAKE_C_FLAGS} ${ARCH_DEFINES}") | ||
| 69 | set(TMP_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_DEFINES}") | ||
| 70 | list(APPEND BUILD_ARGS -DCMAKE_C_FLAGS=${TMP_C_FLAGS} | ||
| 71 | -DCMAKE_CXX_FLAGS=${TMP_CXX_FLAGS}) | ||
| 72 | endif() | ||
| 73 | |||
| 74 | if(CMAKE_TOOLCHAIN_FILE) | ||
| 75 | list(APPEND BUILD_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) | ||
| 76 | message("toolchain specified") | ||
| 77 | message(${BUILD_ARGS}) | ||
| 78 | endif() | ||
| 79 | |||
| 80 | # prepare patchfile. ensure we have a clean file after reconfiguring | ||
| 81 | set(PATCH_FILE ${BUILD_DIR}/${id}/tmp/patch.cmake) | ||
| 82 | file(REMOVE ${PATCH_FILE}) | ||
| 83 | |||
| 84 | # if there's a CMakeLists.txt use it to prepare the build | ||
| 85 | if(EXISTS ${dir}/CMakeLists.txt) | ||
| 86 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${dir}/CMakeLists.txt) | ||
| 87 | file(APPEND ${PATCH_FILE} | ||
| 88 | "file(COPY ${dir}/CMakeLists.txt | ||
| 89 | DESTINATION ${BUILD_DIR}/${id}/src/${id})\n") | ||
| 90 | endif() | ||
| 91 | |||
| 92 | # check if we have patches to apply | ||
| 93 | file(GLOB patches ${dir}/*.patch) | ||
| 94 | list(SORT patches) | ||
| 95 | foreach(patch ${patches}) | ||
| 96 | if(NOT PATCH_PROGRAM OR "${PATCH_PROGRAM}" STREQUAL "") | ||
| 97 | if(NOT PATCH_EXECUTABLE) | ||
| 98 | # find the path to the patch executable | ||
| 99 | find_program(PATCH_EXECUTABLE NAMES patch) | ||
| 100 | |||
| 101 | if(NOT PATCH_EXECUTABLE) | ||
| 102 | message(FATAL_ERROR "Missing patch command (we looked in ${CMAKE_PREFIX_PATH})") | ||
| 103 | endif() | ||
| 104 | endif() | ||
| 105 | |||
| 106 | # on windows "patch.exe" can only handle CR-LF line-endings so we | ||
| 107 | # need to force it to also handle LF-only line endings | ||
| 108 | set(PATCH_PROGRAM ${PATCH_EXECUTABLE}) | ||
| 109 | if(WIN32) | ||
| 110 | set(PATCH_PROGRAM "\"${PATCH_PROGRAM}\" --binary") | ||
| 111 | endif() | ||
| 112 | endif() | ||
| 113 | |||
| 114 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${patch}) | ||
| 115 | file(APPEND ${PATCH_FILE} | ||
| 116 | "execute_process(COMMAND ${PATCH_PROGRAM} -p1 -i \"${patch}\")\n") | ||
| 117 | endforeach() | ||
| 118 | |||
| 119 | |||
| 120 | # if there's an install.txt use it to properly install the built files | ||
| 121 | set(INSTALL_COMMAND "") | ||
| 122 | if(EXISTS ${dir}/install.txt) | ||
| 123 | set(INSTALL_COMMAND INSTALL_COMMAND ${CMAKE_COMMAND} | ||
| 124 | -DINPUTDIR=${BUILD_DIR}/${id}/src/${id}-build/ | ||
| 125 | -DINPUTFILE=${dir}/install.txt | ||
| 126 | -DDESTDIR=${OUTPUT_DIR} | ||
| 127 | -DENABLE_STATIC=1 | ||
| 128 | "${extraflags}" | ||
| 129 | -P ${PROJECT_SOURCE_DIR}/install.cmake) | ||
| 130 | elseif(EXISTS ${dir}/noinstall.txt) | ||
| 131 | set(INSTALL_COMMAND INSTALL_COMMAND "") | ||
| 132 | endif() | ||
| 133 | |||
| 134 | # check if there's a deps.txt containing dependencies on other libraries | ||
| 135 | if(EXISTS ${dir}/deps.txt) | ||
| 136 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${dir}/deps.txt) | ||
| 137 | file(STRINGS ${dir}/deps.txt deps) | ||
| 138 | message(STATUS "${id} depends: ${deps}") | ||
| 139 | else() | ||
| 140 | set(deps) | ||
| 141 | endif() | ||
| 142 | |||
| 143 | if(CROSS_AUTOCONF AND AUTOCONF_FILES) | ||
| 144 | foreach(afile ${AUTOCONF_FILES}) | ||
| 145 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${afile}) | ||
| 146 | file(APPEND ${PATCH_FILE} | ||
| 147 | "message(STATUS \"AUTOCONF: copying ${afile} to ${BUILD_DIR}/${id}/src/${id}\")\n | ||
| 148 | file(COPY ${afile} DESTINATION ${BUILD_DIR}/${id}/src/${id})\n") | ||
| 149 | endforeach() | ||
| 150 | endif() | ||
| 151 | |||
| 152 | # if the patch file exists we need to set the PATCH_COMMAND | ||
| 153 | set(PATCH_COMMAND "") | ||
| 154 | if(EXISTS ${PATCH_FILE}) | ||
| 155 | set(PATCH_COMMAND ${CMAKE_COMMAND} -P ${PATCH_FILE}) | ||
| 156 | endif() | ||
| 157 | |||
| 158 | # prepare the setup of the call to externalproject_add() | ||
| 159 | set(EXTERNALPROJECT_SETUP PREFIX ${BUILD_DIR}/${id} | ||
| 160 | CMAKE_ARGS ${extraflags} ${BUILD_ARGS} | ||
| 161 | PATCH_COMMAND ${PATCH_COMMAND} | ||
| 162 | "${INSTALL_COMMAND}") | ||
| 163 | |||
| 164 | # if there's an url defined we need to pass that to externalproject_add() | ||
| 165 | if(DEFINED url AND NOT "${url}" STREQUAL "") | ||
| 166 | # check if there's a third parameter in the file | ||
| 167 | if(deflength GREATER 2) | ||
| 168 | # the third parameter is considered as a revision of a git repository | ||
| 169 | list(GET def 2 revision) | ||
| 170 | |||
| 171 | externalproject_add(${id} | ||
| 172 | GIT_REPOSITORY ${url} | ||
| 173 | GIT_TAG ${revision} | ||
| 174 | "${EXTERNALPROJECT_SETUP}") | ||
| 175 | else() | ||
| 176 | set(CONFIGURE_COMMAND "") | ||
| 177 | if(NOT WIN32) | ||
| 178 | # manually specify the configure command to be able to pass in the custom PKG_CONFIG_PATH | ||
| 179 | set(CONFIGURE_COMMAND PKG_CONFIG_PATH=${OUTPUT_DIR}/lib/pkgconfig | ||
| 180 | ${CMAKE_COMMAND} -DCMAKE_LIBRARY_PATH=${OUTPUT_DIR}/lib ${extraflags} ${BUILD_ARGS} | ||
| 181 | ${BUILD_DIR}/${id}/src/${id} | ||
| 182 | -DPACKAGE_CONFIG_PATH=${OUTPUT_DIR}/lib/pkgconfig | ||
| 183 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
| 184 | -DOUTPUT_DIR=${OUTPUT_DIR} | ||
| 185 | -DCMAKE_PREFIX_PATH=${OUTPUT_DIR} | ||
| 186 | -DCMAKE_INSTALL_PREFIX=${OUTPUT_DIR} | ||
| 187 | -DCMAKE_EXE_LINKER_FLAGS=-L${OUTPUT_DIR}/lib | ||
| 188 | -DCMAKE_INCLUDE_PATH=${OUTPUT_DIR}/include) | ||
| 189 | endif() | ||
| 190 | |||
| 191 | externalproject_add(${id} | ||
| 192 | URL ${url} | ||
| 193 | DOWNLOAD_DIR ${BUILD_DIR}/download | ||
| 194 | CONFIGURE_COMMAND ${CONFIGURE_COMMAND} | ||
| 195 | "${EXTERNALPROJECT_SETUP}") | ||
| 196 | endif() | ||
| 197 | else() | ||
| 198 | externalproject_add(${id} | ||
| 199 | SOURCE_DIR ${dir} | ||
| 200 | "${EXTERNALPROJECT_SETUP}") | ||
| 201 | endif() | ||
| 202 | |||
| 203 | if(deps) | ||
| 204 | add_dependencies(${id} ${deps}) | ||
| 205 | endif() | ||
| 206 | endif() | ||
| 207 | |||
| 208 | # if the dependency is available for the target platform add it to the list of the addon's dependencies | ||
| 209 | # (even if the target already exists as it still has to be built before the addon) | ||
| 210 | if(${platform_found}) | ||
| 211 | list(APPEND ${addon}_DEPS ${id}) | ||
| 212 | endif() | ||
| 213 | endif() | ||
| 214 | endforeach() | ||
| 215 | |||
| 216 | # make the ${addon}_DEPS variable available to the calling script | ||
| 217 | set(${addon}_DEPS "${${addon}_DEPS}" PARENT_SCOPE) | ||
| 218 | endfunction() | ||
| 219 | |||
