diff options
Diffstat (limited to 'project/cmake/addons/CMakeLists.txt')
| -rw-r--r-- | project/cmake/addons/CMakeLists.txt | 249 |
1 files changed, 249 insertions, 0 deletions
diff --git a/project/cmake/addons/CMakeLists.txt b/project/cmake/addons/CMakeLists.txt new file mode 100644 index 0000000..0afc622 --- /dev/null +++ b/project/cmake/addons/CMakeLists.txt | |||
| @@ -0,0 +1,249 @@ | |||
| 1 | project(kodi-addons) | ||
| 2 | |||
| 3 | cmake_minimum_required(VERSION 2.8) | ||
| 4 | |||
| 5 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}) | ||
| 6 | |||
| 7 | if(NOT CMAKE_BUILD_TYPE) | ||
| 8 | set(CMAKE_BUILD_TYPE Release) | ||
| 9 | endif() | ||
| 10 | |||
| 11 | if(NOT CORE_SYSTEM_NAME) | ||
| 12 | string(TOLOWER ${CMAKE_SYSTEM_NAME} CORE_SYSTEM_NAME) | ||
| 13 | endif() | ||
| 14 | |||
| 15 | include(ExternalProject) | ||
| 16 | |||
| 17 | ### setup all the necessary paths | ||
| 18 | if(NOT APP_ROOT AND NOT XBMCROOT) | ||
| 19 | set(APP_ROOT ${PROJECT_SOURCE_DIR}/../../..) | ||
| 20 | elseif(NOT APP_ROOT) | ||
| 21 | file(TO_CMAKE_PATH "${XBMCROOT}" APP_ROOT) | ||
| 22 | else() | ||
| 23 | file(TO_CMAKE_PATH "${APP_ROOT}" APP_ROOT) | ||
| 24 | endif() | ||
| 25 | get_filename_component(APP_ROOT "${APP_ROOT}" ABSOLUTE) | ||
| 26 | |||
| 27 | if(NOT BUILD_DIR) | ||
| 28 | set(BUILD_DIR "${CMAKE_BINARY_DIR}/build") | ||
| 29 | else() | ||
| 30 | file(TO_CMAKE_PATH "${BUILD_DIR}" BUILD_DIR) | ||
| 31 | endif() | ||
| 32 | get_filename_component(BUILD_DIR "${BUILD_DIR}" ABSOLUTE) | ||
| 33 | |||
| 34 | if(NOT DEPENDS_PATH) | ||
| 35 | set(DEPENDS_PATH "${BUILD_DIR}/depends") | ||
| 36 | else() | ||
| 37 | file(TO_CMAKE_PATH "${DEPENDS_PATH}" DEPENDS_PATH) | ||
| 38 | endif() | ||
| 39 | get_filename_component(DEPENDS_PATH "${DEPENDS_PATH}" ABSOLUTE) | ||
| 40 | |||
| 41 | if(NOT PLATFORM_DIR) | ||
| 42 | set(PLATFORM_DIR ${APP_ROOT}/project/cmake/platform/${CORE_SYSTEM_NAME}) | ||
| 43 | file(TO_CMAKE_PATH "${PLATFORM_DIR}" PLATFORM_DIR) | ||
| 44 | endif() | ||
| 45 | |||
| 46 | # make sure CMAKE_PREFIX_PATH is set | ||
| 47 | if(NOT CMAKE_PREFIX_PATH) | ||
| 48 | set(CMAKE_PREFIX_PATH "${DEPENDS_PATH}") | ||
| 49 | else() | ||
| 50 | file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH) | ||
| 51 | list(APPEND CMAKE_PREFIX_PATH "${DEPENDS_PATH}") | ||
| 52 | endif() | ||
| 53 | |||
| 54 | # check for autoconf stuff to pass on | ||
| 55 | if(AUTOCONF_FILES) | ||
| 56 | separate_arguments(AUTOCONF_FILES) | ||
| 57 | set(CROSS_AUTOCONF "yes") | ||
| 58 | endif() | ||
| 59 | |||
| 60 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR NOT CMAKE_INSTALL_PREFIX) | ||
| 61 | set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/output/addons") | ||
| 62 | endif() | ||
| 63 | list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}) | ||
| 64 | |||
| 65 | set(BUILD_ARGS -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} | ||
| 66 | -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> | ||
| 67 | -DPACKAGE_CONFIG_PATH=${DEPENDS_PATH}/lib/pkgconfig | ||
| 68 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
| 69 | -DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_USER_MAKE_RULES_OVERRIDE} | ||
| 70 | -DCMAKE_USER_MAKE_RULES_OVERRIDE_CXX=${CMAKE_USER_MAKE_RULES_OVERRIDE_CXX} | ||
| 71 | -DCORE_SYSTEM_NAME=${CORE_SYSTEM_NAME} | ||
| 72 | -DBUILD_SHARED_LIBS=1 | ||
| 73 | -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} | ||
| 74 | -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}) | ||
| 75 | |||
| 76 | if(PACKAGE_ZIP) | ||
| 77 | # needed for project installing | ||
| 78 | list(APPEND BUILD_ARGS -DPACKAGE_ZIP=1) | ||
| 79 | MESSAGE("package zip specified") | ||
| 80 | endif() | ||
| 81 | |||
| 82 | if(CMAKE_TOOLCHAIN_FILE) | ||
| 83 | list(APPEND BUILD_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) | ||
| 84 | MESSAGE("toolchain specified") | ||
| 85 | MESSAGE(${BUILD_ARGS}) | ||
| 86 | endif() | ||
| 87 | |||
| 88 | if(NOT ADDONS_TO_BUILD) | ||
| 89 | set(ADDONS_TO_BUILD "all") | ||
| 90 | else() | ||
| 91 | message(STATUS "Building following addons: ${ADDONS_TO_BUILD}") | ||
| 92 | separate_arguments(ADDONS_TO_BUILD) | ||
| 93 | endif() | ||
| 94 | |||
| 95 | if(NOT KODI_LIB_DIR) | ||
| 96 | set(KODI_LIB_DIR "${DEPENDS_PATH}/lib/kodi") | ||
| 97 | else() | ||
| 98 | file(TO_CMAKE_PATH "${KODI_LIB_DIR}" KODI_LIB_DIR) | ||
| 99 | endif() | ||
| 100 | |||
| 101 | # check for platform specific stuff | ||
| 102 | if(EXISTS ${PLATFORM_DIR}/defines.txt) | ||
| 103 | file(STRINGS ${PLATFORM_DIR}/defines.txt platformdefines) | ||
| 104 | |||
| 105 | if(NOT ARCH_DEFINES AND platformdefines) | ||
| 106 | set(ARCH_DEFINES ${platformdefines}) | ||
| 107 | endif() | ||
| 108 | endif() | ||
| 109 | |||
| 110 | # include check_target_platform() function | ||
| 111 | include(${APP_ROOT}/project/cmake/scripts/common/check_target_platform.cmake) | ||
| 112 | |||
| 113 | # check install permissions | ||
| 114 | set(ADDON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}) | ||
| 115 | check_install_permissions(${CMAKE_INSTALL_PREFIX} can_write) | ||
| 116 | if(NOT ${can_write} AND NOT WIN32) | ||
| 117 | set(NEED_SUDO TRUE) | ||
| 118 | set(ADDON_INSTALL_DIR ${CMAKE_BINARY_DIR}/.install) | ||
| 119 | message(STATUS "NEED_SUDO: ${NEED_SUDO}") | ||
| 120 | endif() | ||
| 121 | |||
| 122 | ### prepare the build environment for the binary addons | ||
| 123 | # copy the prepare-env.cmake script to the depends path so that we can include it | ||
| 124 | file(COPY ${APP_ROOT}/project/cmake/scripts/common/prepare-env.cmake DESTINATION ${KODI_LIB_DIR}) | ||
| 125 | |||
| 126 | # add the location of prepare-env.cmake to CMAKE_MODULE_PATH so that it is found | ||
| 127 | list(APPEND CMAKE_MODULE_PATH ${KODI_LIB_DIR}) | ||
| 128 | |||
| 129 | # include prepare-env.cmake which contains the logic to install the addon header bindings etc | ||
| 130 | include(prepare-env) | ||
| 131 | |||
| 132 | ### add the depends subdirectory for any general dependencies | ||
| 133 | add_subdirectory(depends) | ||
| 134 | |||
| 135 | ### get and build all the binary addons | ||
| 136 | # look for all the addons to be built | ||
| 137 | file(GLOB_RECURSE addons ${PROJECT_SOURCE_DIR}/addons/*.txt) | ||
| 138 | foreach(addon ${addons}) | ||
| 139 | if(NOT (addon MATCHES platforms.txt)) | ||
| 140 | file(STRINGS ${addon} def) | ||
| 141 | separate_arguments(def) | ||
| 142 | list(GET def 0 id) | ||
| 143 | |||
| 144 | list(FIND ADDONS_TO_BUILD ${id} idx) | ||
| 145 | if(idx GREATER -1 OR ADDONS_TO_BUILD STREQUAL "all") | ||
| 146 | get_filename_component(dir ${addon} PATH) | ||
| 147 | |||
| 148 | # check if the addon has a platforms.txt | ||
| 149 | set(platform_found FALSE) | ||
| 150 | check_target_platform(${dir} ${CORE_SYSTEM_NAME} platform_found) | ||
| 151 | |||
| 152 | if (${platform_found}) | ||
| 153 | # make sure the output directory is clean | ||
| 154 | if(EXISTS "${CMAKE_INSTALL_PREFIX}/${id}") | ||
| 155 | file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/${id}/") | ||
| 156 | endif() | ||
| 157 | |||
| 158 | # get the URL and revision of the addon | ||
| 159 | list(LENGTH def deflength) | ||
| 160 | list(GET def 1 url) | ||
| 161 | |||
| 162 | set(archive_name ${id}) | ||
| 163 | |||
| 164 | # if there is a 3rd parameter in the file, we consider it a git revision | ||
| 165 | if(deflength GREATER 2) | ||
| 166 | list(GET def 2 revision) | ||
| 167 | |||
| 168 | # Note: downloading specific revisions via http in the format below is probably github specific | ||
| 169 | # if we ever use other repositories, this might need adapting | ||
| 170 | set(url ${url}/archive/${revision}.tar.gz) | ||
| 171 | set(archive_name ${archive_name}-${revision}) | ||
| 172 | endif() | ||
| 173 | |||
| 174 | # download and extract the addon | ||
| 175 | if(NOT EXISTS ${BUILD_DIR}/download/${archive_name}.tar.gz) | ||
| 176 | # cleanup any of the previously downloaded archives of this addon | ||
| 177 | file(GLOB archives "${BUILD_DIR}/download/${id}*.tar.gz") | ||
| 178 | if(archives) | ||
| 179 | message(STATUS "Removing old archives of ${id}: ${archives}") | ||
| 180 | file(REMOVE ${archives}) | ||
| 181 | endif() | ||
| 182 | |||
| 183 | # download the addon | ||
| 184 | file(DOWNLOAD "${url}" "${BUILD_DIR}/download/${archive_name}.tar.gz" STATUS dlstatus LOG dllog SHOW_PROGRESS) | ||
| 185 | list(GET dlstatus 0 retcode) | ||
| 186 | if(NOT ${retcode} EQUAL 0) | ||
| 187 | message(FATAL_ERROR "ERROR downloading ${url} - status: ${dlstatus} log: ${dllog}") | ||
| 188 | endif() | ||
| 189 | endif() | ||
| 190 | |||
| 191 | # remove any previously extracted version of the addon | ||
| 192 | if(EXISTS "${BUILD_DIR}/${id}") | ||
| 193 | file(REMOVE_RECURSE "${BUILD_DIR}/${id}") | ||
| 194 | endif() | ||
| 195 | |||
| 196 | # extract the addon from the archive | ||
| 197 | execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzvf ${BUILD_DIR}/download/${archive_name}.tar.gz | ||
| 198 | WORKING_DIRECTORY ${BUILD_DIR}) | ||
| 199 | file(GLOB extract_dir "${BUILD_DIR}/${archive_name}*") | ||
| 200 | if(extract_dir STREQUAL "") | ||
| 201 | message(FATAL_ERROR "Error extracting ${BUILD_DIR}/download/${archive_name}.tar.gz") | ||
| 202 | else() | ||
| 203 | file(RENAME "${extract_dir}" "${BUILD_DIR}/${id}") | ||
| 204 | endif() | ||
| 205 | |||
| 206 | list(APPEND downloaded_addons ${id}) | ||
| 207 | |||
| 208 | endif() | ||
| 209 | endif() | ||
| 210 | endif() | ||
| 211 | endforeach() | ||
| 212 | |||
| 213 | foreach(id ${downloaded_addons}) | ||
| 214 | externalproject_add(${id} | ||
| 215 | SOURCE_DIR ${BUILD_DIR}/${id} | ||
| 216 | INSTALL_DIR ${ADDON_INSTALL_DIR} | ||
| 217 | CMAKE_ARGS ${BUILD_ARGS}) | ||
| 218 | |||
| 219 | # add a custom step to the external project between the configure and the build step which will always | ||
| 220 | # be executed and therefore forces a re-build of all changed files | ||
| 221 | externalproject_add_step(${id} forcebuild | ||
| 222 | COMMAND ${CMAKE_COMMAND} -E echo "Force build of ${id}" | ||
| 223 | DEPENDEES configure | ||
| 224 | DEPENDERS build | ||
| 225 | ALWAYS 1) | ||
| 226 | |||
| 227 | # add "kodi-platform" as a dependency to every addon | ||
| 228 | add_dependencies(${id} kodi-platform) | ||
| 229 | |||
| 230 | set(${id}_DEPENDS_DIR ${BUILD_DIR}/${id}/depends) | ||
| 231 | |||
| 232 | if(EXISTS ${${id}_DEPENDS_DIR}) | ||
| 233 | include(${APP_ROOT}/project/cmake/scripts/common/handle-depends.cmake) | ||
| 234 | add_addon_depends(${id} ${${id}_DEPENDS_DIR}) | ||
| 235 | if (${id}_DEPS AND NOT "${${id}_DEPS}" STREQUAL "") | ||
| 236 | message(STATUS "${id} DEPENDENCIES: ${${id}_DEPS}") | ||
| 237 | add_dependencies(${id} ${${id}_DEPS}) | ||
| 238 | endif() | ||
| 239 | endif() | ||
| 240 | endforeach() | ||
| 241 | |||
| 242 | if(NEED_SUDO) | ||
| 243 | add_custom_target(install | ||
| 244 | COMMAND ${CMAKE_COMMAND} -E echo "\n\n" | ||
| 245 | COMMAND ${CMAKE_COMMAND} -E echo "WARNING: sudo rights needed to install to ${CMAKE_INSTALL_PREFIX}\n" | ||
| 246 | COMMAND sudo ${CMAKE_COMMAND} -E copy_directory ${ADDON_INSTALL_DIR}/ ${CMAKE_INSTALL_PREFIX}/ | ||
| 247 | COMMAND sudo ${CMAKE_COMMAND} -E remove_directory ${ADDON_INSTALL_DIR}/ | ||
| 248 | COMMAND sudo -k) | ||
| 249 | endif() | ||
