diff options
Diffstat (limited to 'project/cmake/addons/CMakeLists.txt')
| -rw-r--r-- | project/cmake/addons/CMakeLists.txt | 156 |
1 files changed, 135 insertions, 21 deletions
diff --git a/project/cmake/addons/CMakeLists.txt b/project/cmake/addons/CMakeLists.txt index 0773713..8fc1a23 100644 --- a/project/cmake/addons/CMakeLists.txt +++ b/project/cmake/addons/CMakeLists.txt | |||
| @@ -1,15 +1,31 @@ | |||
| 1 | project(kodi-addons) | 1 | project(kodi-addons) |
| 2 | 2 | ||
| 3 | cmake_minimum_required(VERSION 2.8) | 3 | if(WIN32) |
| 4 | # there seems to be a bug in the CMake generator implementation in CMake 2.8.x releases for WIN32 | ||
| 5 | cmake_minimum_required(VERSION 3.0) | ||
| 6 | else() | ||
| 7 | cmake_minimum_required(VERSION 2.8) | ||
| 8 | endif() | ||
| 4 | 9 | ||
| 5 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}) | 10 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}) |
| 6 | 11 | ||
| 12 | option(ADDON_TARBALL_CACHING "Cache downloaded addon source tarballs?" ON) | ||
| 13 | if(ADDON_TARBALL_CACHING) | ||
| 14 | message(STATUS "Addon source tarball caching is enabled") | ||
| 15 | else() | ||
| 16 | message(STATUS "Addon source tarball caching is disabled") | ||
| 17 | endif() | ||
| 18 | |||
| 7 | if(NOT CMAKE_BUILD_TYPE) | 19 | if(NOT CMAKE_BUILD_TYPE) |
| 8 | set(CMAKE_BUILD_TYPE Release) | 20 | set(CMAKE_BUILD_TYPE Release) |
| 9 | endif() | 21 | endif() |
| 10 | 22 | ||
| 11 | if(NOT CORE_SYSTEM_NAME) | 23 | if(NOT CORE_SYSTEM_NAME) |
| 12 | string(TOLOWER ${CMAKE_SYSTEM_NAME} CORE_SYSTEM_NAME) | 24 | if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") |
| 25 | set(CORE_SYSTEM_NAME "osx") | ||
| 26 | else() | ||
| 27 | string(TOLOWER ${CMAKE_SYSTEM_NAME} CORE_SYSTEM_NAME) | ||
| 28 | endif() | ||
| 13 | endif() | 29 | endif() |
| 14 | 30 | ||
| 15 | include(ExternalProject) | 31 | include(ExternalProject) |
| @@ -65,6 +81,7 @@ list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}) | |||
| 65 | set(BUILD_ARGS -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} | 81 | set(BUILD_ARGS -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} |
| 66 | -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> | 82 | -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> |
| 67 | -DPACKAGE_CONFIG_PATH=${DEPENDS_PATH}/lib/pkgconfig | 83 | -DPACKAGE_CONFIG_PATH=${DEPENDS_PATH}/lib/pkgconfig |
| 84 | -DDEPENDS_PATH=${DEPENDS_PATH} | ||
| 68 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | 85 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} |
| 69 | -DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_USER_MAKE_RULES_OVERRIDE} | 86 | -DCMAKE_USER_MAKE_RULES_OVERRIDE=${CMAKE_USER_MAKE_RULES_OVERRIDE} |
| 70 | -DCMAKE_USER_MAKE_RULES_OVERRIDE_CXX=${CMAKE_USER_MAKE_RULES_OVERRIDE_CXX} | 87 | -DCMAKE_USER_MAKE_RULES_OVERRIDE_CXX=${CMAKE_USER_MAKE_RULES_OVERRIDE_CXX} |
| @@ -78,16 +95,26 @@ if(MSVC) | |||
| 78 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) | 95 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 79 | endif() | 96 | endif() |
| 80 | 97 | ||
| 98 | option(PACKAGE_ZIP "Prepare built addons for packaging" OFF) | ||
| 81 | if(PACKAGE_ZIP) | 99 | if(PACKAGE_ZIP) |
| 82 | # needed for project installing | 100 | # needed for project installing |
| 83 | list(APPEND BUILD_ARGS -DPACKAGE_ZIP=1) | 101 | list(APPEND BUILD_ARGS -DPACKAGE_ZIP=ON) |
| 84 | MESSAGE("package zip specified") | 102 | |
| 103 | # figure out where to store the packaged ZIP archives | ||
| 104 | if(NOT PACKAGE_DIR) | ||
| 105 | set(PACKAGE_DIR "${BUILD_DIR}/zips") | ||
| 106 | else() | ||
| 107 | file(TO_CMAKE_PATH "${PACKAGE_DIR}" PACKAGE_DIR) | ||
| 108 | endif() | ||
| 109 | list(APPEND BUILD_ARGS -DPACKAGE_DIR=${PACKAGE_DIR}) | ||
| 110 | |||
| 111 | MESSAGE(STATUS "ZIP packaging enabled (destination: ${PACKAGE_DIR})") | ||
| 85 | endif() | 112 | endif() |
| 86 | 113 | ||
| 87 | if(CMAKE_TOOLCHAIN_FILE) | 114 | if(CMAKE_TOOLCHAIN_FILE) |
| 88 | list(APPEND BUILD_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) | 115 | list(APPEND BUILD_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) |
| 89 | MESSAGE("toolchain specified") | 116 | MESSAGE(STATUS "Toolchain specified") |
| 90 | MESSAGE(${BUILD_ARGS}) | 117 | MESSAGE(STATUS ${BUILD_ARGS}) |
| 91 | endif() | 118 | endif() |
| 92 | 119 | ||
| 93 | if(NOT ADDONS_TO_BUILD) | 120 | if(NOT ADDONS_TO_BUILD) |
| @@ -97,16 +124,25 @@ else() | |||
| 97 | separate_arguments(ADDONS_TO_BUILD) | 124 | separate_arguments(ADDONS_TO_BUILD) |
| 98 | endif() | 125 | endif() |
| 99 | 126 | ||
| 127 | if(NOT ADDONS_DEFINITION_DIR) | ||
| 128 | set(ADDONS_DEFINITION_DIR ${PROJECT_SOURCE_DIR}/addons) | ||
| 129 | else() | ||
| 130 | file(TO_CMAKE_PATH "${ADDONS_DEFINITION_DIR}" ADDONS_DEFINITION_DIR) | ||
| 131 | endif() | ||
| 132 | get_filename_component(ADDONS_DEFINITION_DIR "${ADDONS_DEFINITION_DIR}" ABSOLUTE) | ||
| 133 | |||
| 100 | if(ADDON_SRC_PREFIX) | 134 | if(ADDON_SRC_PREFIX) |
| 101 | message(STATUS "Overriding addon source directory prefix: ${ADDON_SRC_PREFIX}") | 135 | message(STATUS "Overriding addon source directory prefix: ${ADDON_SRC_PREFIX}") |
| 102 | endif() | 136 | endif() |
| 103 | 137 | ||
| 104 | if(NOT KODI_LIB_DIR) | 138 | if(NOT APP_LIB_DIR) |
| 105 | set(KODI_LIB_DIR "${DEPENDS_PATH}/lib/kodi") | 139 | set(APP_LIB_DIR "${DEPENDS_PATH}/lib/kodi") |
| 106 | else() | 140 | else() |
| 107 | file(TO_CMAKE_PATH "${KODI_LIB_DIR}" KODI_LIB_DIR) | 141 | file(TO_CMAKE_PATH "${APP_LIB_DIR}" APP_LIB_DIR) |
| 108 | endif() | 142 | endif() |
| 109 | 143 | ||
| 144 | set(APP_PREFIX "${CMAKE_INSTALL_PREFIX}") | ||
| 145 | |||
| 110 | # check for platform specific stuff | 146 | # check for platform specific stuff |
| 111 | if(EXISTS ${PLATFORM_DIR}/defines.txt) | 147 | if(EXISTS ${PLATFORM_DIR}/defines.txt) |
| 112 | file(STRINGS ${PLATFORM_DIR}/defines.txt platformdefines) | 148 | file(STRINGS ${PLATFORM_DIR}/defines.txt platformdefines) |
| @@ -119,21 +155,23 @@ endif() | |||
| 119 | # include check_target_platform() function | 155 | # include check_target_platform() function |
| 120 | include(${APP_ROOT}/project/cmake/scripts/common/check_target_platform.cmake) | 156 | include(${APP_ROOT}/project/cmake/scripts/common/check_target_platform.cmake) |
| 121 | 157 | ||
| 122 | # check install permissions | ||
| 123 | set(ADDON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}) | 158 | set(ADDON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}) |
| 124 | check_install_permissions(${CMAKE_INSTALL_PREFIX} can_write) | 159 | if(NOT WIN32) |
| 125 | if(NOT ${can_write} AND NOT WIN32) | 160 | # check install permissions |
| 126 | set(NEED_SUDO TRUE) | 161 | check_install_permissions(${CMAKE_INSTALL_PREFIX} can_write) |
| 127 | set(ADDON_INSTALL_DIR ${CMAKE_BINARY_DIR}/.install) | 162 | if(NOT ${can_write} AND CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 128 | message(STATUS "NEED_SUDO: ${NEED_SUDO}") | 163 | set(NEED_SUDO TRUE) |
| 164 | set(ADDON_INSTALL_DIR ${CMAKE_BINARY_DIR}/.install) | ||
| 165 | message(STATUS "NEED_SUDO: ${NEED_SUDO}") | ||
| 166 | endif() | ||
| 129 | endif() | 167 | endif() |
| 130 | 168 | ||
| 131 | ### prepare the build environment for the binary addons | 169 | ### prepare the build environment for the binary addons |
| 132 | # copy the prepare-env.cmake script to the depends path so that we can include it | 170 | # copy the prepare-env.cmake script to the depends path so that we can include it |
| 133 | file(COPY ${APP_ROOT}/project/cmake/scripts/common/prepare-env.cmake DESTINATION ${KODI_LIB_DIR}) | 171 | file(COPY ${APP_ROOT}/project/cmake/scripts/common/prepare-env.cmake DESTINATION ${APP_LIB_DIR}) |
| 134 | 172 | ||
| 135 | # add the location of prepare-env.cmake to CMAKE_MODULE_PATH so that it is found | 173 | # add the location of prepare-env.cmake to CMAKE_MODULE_PATH so that it is found |
| 136 | list(APPEND CMAKE_MODULE_PATH ${KODI_LIB_DIR}) | 174 | list(APPEND CMAKE_MODULE_PATH ${APP_LIB_DIR}) |
| 137 | 175 | ||
| 138 | # include prepare-env.cmake which contains the logic to install the addon header bindings etc | 176 | # include prepare-env.cmake which contains the logic to install the addon header bindings etc |
| 139 | include(prepare-env) | 177 | include(prepare-env) |
| @@ -141,17 +179,61 @@ include(prepare-env) | |||
| 141 | ### add the depends subdirectory for any general dependencies | 179 | ### add the depends subdirectory for any general dependencies |
| 142 | add_subdirectory(depends) | 180 | add_subdirectory(depends) |
| 143 | 181 | ||
| 182 | # add a custom target "package-addons" which will package and install all addons | ||
| 183 | add_custom_target(package-addons) | ||
| 184 | |||
| 144 | ### get and build all the binary addons | 185 | ### get and build all the binary addons |
| 145 | # look for all the addons to be built | 186 | # look for all the addons to be built |
| 146 | file(GLOB_RECURSE addons ${PROJECT_SOURCE_DIR}/addons/*.txt) | 187 | file(GLOB_RECURSE addons ${ADDONS_DEFINITION_DIR}/*.txt) |
| 188 | |||
| 189 | #if there are no addons assume that bootstrapping hasn't happened yet | ||
| 190 | if(NOT addons) | ||
| 191 | message(STATUS "Bootstrapping all default repositories as no addons were found...") | ||
| 192 | set(BOOTSTRAP_BUILD_DIR "${BUILD_DIR}/bootstrap") | ||
| 193 | |||
| 194 | # make sure that the bootstraps build addon exists | ||
| 195 | if(NOT EXISTS ${BOOTSTRAP_BUILD_DIR}) | ||
| 196 | file(MAKE_DIRECTORY ${BOOTSTRAP_BUILD_DIR}) | ||
| 197 | endif() | ||
| 198 | |||
| 199 | # generate the bootstrap buildsystem | ||
| 200 | execute_process(COMMAND ${CMAKE_COMMAND} ${PROJECT_SOURCE_DIR}/bootstrap | ||
| 201 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} | ||
| 202 | -DCMAKE_INSTALL_PREFIX:PATH=${ADDONS_DEFINITION_DIR} | ||
| 203 | -DBUILD_DIR:PATH=${BOOTSTRAP_BUILD_DIR} | ||
| 204 | -DADDONS_TO_BUILD=${ADDONS_TO_BUILD} | ||
| 205 | WORKING_DIRECTORY ${BOOTSTRAP_BUILD_DIR}) | ||
| 206 | |||
| 207 | # execute the generated bootstrap buildsystem | ||
| 208 | execute_process(COMMAND ${CMAKE_COMMAND} --build ${BOOTSTRAP_BUILD_DIR} | ||
| 209 | WORKING_DIRECTORY ${BOOTSTRAP_BUILD_DIR}) | ||
| 210 | |||
| 211 | # now look for all the addons to be built again | ||
| 212 | file(GLOB_RECURSE addons ${ADDONS_DEFINITION_DIR}/*.txt) | ||
| 213 | |||
| 214 | if(NOT addons) | ||
| 215 | message(FATAL_ERROR "No addons available to be built") | ||
| 216 | endif() | ||
| 217 | endif() | ||
| 218 | |||
| 147 | foreach(addon ${addons}) | 219 | foreach(addon ${addons}) |
| 148 | if(NOT (addon MATCHES platforms.txt)) | 220 | if(NOT (addon MATCHES platforms.txt)) |
| 149 | file(STRINGS ${addon} def) | 221 | file(STRINGS ${addon} def) |
| 150 | separate_arguments(def) | 222 | separate_arguments(def) |
| 151 | list(GET def 0 id) | 223 | list(GET def 0 id) |
| 152 | 224 | ||
| 225 | set(ADDON_FOUND FALSE) | ||
| 226 | # try to find a perfect match | ||
| 153 | list(FIND ADDONS_TO_BUILD ${id} idx) | 227 | list(FIND ADDONS_TO_BUILD ${id} idx) |
| 154 | if(idx GREATER -1 OR ADDONS_TO_BUILD STREQUAL "all") | 228 | if(idx GREATER -1 OR "${ADDONS_TO_BUILD}" STREQUAL "all") |
| 229 | set(ADDON_FOUND TRUE) | ||
| 230 | # Maybe we have a regex | ||
| 231 | elseif(id MATCHES "${ADDONS_TO_BUILD}") | ||
| 232 | message(STATUS "Pattern ${ADDONS_TO_BUILD} matches ${id}, building addon") | ||
| 233 | set(ADDON_FOUND TRUE) | ||
| 234 | endif() | ||
| 235 | |||
| 236 | if(ADDON_FOUND) | ||
| 155 | get_filename_component(dir ${addon} PATH) | 237 | get_filename_component(dir ${addon} PATH) |
| 156 | 238 | ||
| 157 | # check if the addon has a platforms.txt | 239 | # check if the addon has a platforms.txt |
| @@ -180,6 +262,19 @@ foreach(addon ${addons}) | |||
| 180 | if(deflength GREATER 2 AND "${SOURCE_DIR}" STREQUAL "") | 262 | if(deflength GREATER 2 AND "${SOURCE_DIR}" STREQUAL "") |
| 181 | list(GET def 2 revision) | 263 | list(GET def 2 revision) |
| 182 | 264 | ||
| 265 | # we need access to a git executable | ||
| 266 | find_package(Git REQUIRED) | ||
| 267 | |||
| 268 | # resolve revision to git hash | ||
| 269 | execute_process(COMMAND ${GIT_EXECUTABLE} ls-remote ${url} ${revision} OUTPUT_VARIABLE revision_hash) | ||
| 270 | # git ls-remote only works on branches and tag names but not on revisions | ||
| 271 | if(NOT "${revision_hash}" STREQUAL "") | ||
| 272 | string(REPLACE "\t" ";" revision_list ${revision_hash}) | ||
| 273 | list(GET revision_list 0 revision_hash) | ||
| 274 | message(STATUS "${id}: git branch/tag ${revision} resolved to hash: ${revision_hash}") | ||
| 275 | set(revision ${revision_hash}) | ||
| 276 | endif() | ||
| 277 | |||
| 183 | # Note: downloading specific revisions via http in the format below is probably github specific | 278 | # Note: downloading specific revisions via http in the format below is probably github specific |
| 184 | # if we ever use other repositories, this might need adapting | 279 | # if we ever use other repositories, this might need adapting |
| 185 | set(url ${url}/archive/${revision}.tar.gz) | 280 | set(url ${url}/archive/${revision}.tar.gz) |
| @@ -210,7 +305,7 @@ foreach(addon ${addons}) | |||
| 210 | # download the addon if necessary | 305 | # download the addon if necessary |
| 211 | if(NOT "${archive_name}" STREQUAL "") | 306 | if(NOT "${archive_name}" STREQUAL "") |
| 212 | # download and extract the addon | 307 | # download and extract the addon |
| 213 | if(NOT EXISTS ${BUILD_DIR}/download/${archive_name}.tar.gz) | 308 | if(NOT ADDON_TARBALL_CACHING OR NOT EXISTS ${BUILD_DIR}/download/${archive_name}.tar.gz) |
| 214 | # cleanup any of the previously downloaded archives of this addon | 309 | # cleanup any of the previously downloaded archives of this addon |
| 215 | file(GLOB archives "${BUILD_DIR}/download/${id}*.tar.gz") | 310 | file(GLOB archives "${BUILD_DIR}/download/${id}*.tar.gz") |
| 216 | if(archives) | 311 | if(archives) |
| @@ -275,6 +370,25 @@ foreach(addon ${addons}) | |||
| 275 | add_dependencies(${id} ${${id}_DEPS}) | 370 | add_dependencies(${id} ${${id}_DEPS}) |
| 276 | endif() | 371 | endif() |
| 277 | endif() | 372 | endif() |
| 373 | |||
| 374 | if(CROSS_AUTOCONF AND AUTOCONF_FILES) | ||
| 375 | if(EXISTS ${SOURCE_DIR}/bootstrap/autoreconf.txt) | ||
| 376 | file(STRINGS ${SOURCE_DIR}/bootstrap/autoreconf.txt conf_dirs) | ||
| 377 | foreach(conf_dir ${conf_dirs}) | ||
| 378 | foreach(afile ${AUTOCONF_FILES}) | ||
| 379 | message(STATUS "copying ${afile} to ${SOURCE_DIR}/${conf_dir}") | ||
| 380 | file(COPY ${afile} DESTINATION ${SOURCE_DIR}/${conf_dir}) | ||
| 381 | endforeach() | ||
| 382 | endforeach() | ||
| 383 | endif() | ||
| 384 | endif() | ||
| 385 | |||
| 386 | # create a forwarding target to the addon-package target | ||
| 387 | add_custom_target(package-${id} | ||
| 388 | COMMAND ${CMAKE_COMMAND} --build ${id}-prefix/src/${id}-build --target addon-package | ||
| 389 | DEPENDS ${id}) | ||
| 390 | add_dependencies(package-addons package-${id}) | ||
| 391 | |||
| 278 | else() | 392 | else() |
| 279 | message(FATAL_ERROR "${id}: invalid or missing addon source directory at ${SOURCE_DIR}") | 393 | message(FATAL_ERROR "${id}: invalid or missing addon source directory at ${SOURCE_DIR}") |
| 280 | endif() | 394 | endif() |
| @@ -297,4 +411,4 @@ endif() | |||
| 297 | 411 | ||
| 298 | # add custom target "supported_addons" that returns all addons that are supported on this platform | 412 | # add custom target "supported_addons" that returns all addons that are supported on this platform |
| 299 | string(REPLACE ";" " " ALL_ADDONS_BUILDING "${ALL_ADDONS_BUILDING}") | 413 | string(REPLACE ";" " " ALL_ADDONS_BUILDING "${ALL_ADDONS_BUILDING}") |
| 300 | add_custom_target(supported_addons COMMAND ${CMAKE_COMMAND} -E echo "ALL_ADDONS_BUILDING: ${ALL_ADDONS_BUILDING}" VERBATIM) | 414 | add_custom_target(supported_addons COMMAND ${CMAKE_COMMAND} -E echo "ALL_ADDONS_BUILDING: ${ALL_ADDONS_BUILDING}" VERBATIM) \ No newline at end of file |
