Skip to content

Commit

Permalink
Merge pull request xbmc#6592 from Montellese/binary_addons_pvr_local
Browse files Browse the repository at this point in the history
cmake: support file:// based URLs for addon definitions
  • Loading branch information
Montellese committed Mar 3, 2015
2 parents b107c44 + 55ffd2e commit ec963fa
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 59 deletions.
155 changes: 98 additions & 57 deletions project/cmake/addons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ set(BUILD_ARGS -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS})

if(MSVC)
# move cmake specific targets to a CMakePredefinedTargets folder in Visual Studio
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()

if(PACKAGE_ZIP)
# needed for project installing
list(APPEND BUILD_ARGS -DPACKAGE_ZIP=1)
Expand All @@ -92,6 +97,10 @@ else()
separate_arguments(ADDONS_TO_BUILD)
endif()

if(ADDON_SRC_PREFIX)
message(STATUS "Overriding addon source directory prefix: ${ADDON_SRC_PREFIX}")
endif()

if(NOT KODI_LIB_DIR)
set(KODI_LIB_DIR "${DEPENDS_PATH}/lib/kodi")
else()
Expand Down Expand Up @@ -160,85 +169,117 @@ foreach(addon ${addons})
list(GET def 1 url)

set(archive_name ${id})
if(ADDON_SRC_PREFIX)
set(SOURCE_DIR ${ADDON_SRC_PREFIX}/${id})
set(archive_name "")
else()
set(SOURCE_DIR "")
endif()

# if there is a 3rd parameter in the file, we consider it a git revision
if(deflength GREATER 2)
# if there is a 3rd parameter in the file, we consider it a git revision
if(deflength GREATER 2 AND "${SOURCE_DIR}" STREQUAL "")
list(GET def 2 revision)

# Note: downloading specific revisions via http in the format below is probably github specific
# if we ever use other repositories, this might need adapting
set(url ${url}/archive/${revision}.tar.gz)
set(archive_name ${archive_name}-${revision})
elseif("${SOURCE_DIR}" STREQUAL "")
# check if the URL starts with file://
string(REGEX MATCH "^file://.*$" local_url "${url}")

#if not we assume this to be a local directory
if(local_url)
# this is not an archive
set(archive_name "")

# remove the file:// protocol from the URL
string(REPLACE "file://" "" SOURCE_DIR "${url}")

# on win32 we may have to remove another leading /
if(WIN32)
# check if the path is a local path
string(REGEX MATCH "^/.*$" local_path "${SOURCE_DIR}")
if(local_path)
string(SUBSTRING "${SOURCE_DIR}" 1 -1 SOURCE_DIR)
endif()
endif()
endif()
endif()

# download and extract the addon
if(NOT EXISTS ${BUILD_DIR}/download/${archive_name}.tar.gz)
# cleanup any of the previously downloaded archives of this addon
file(GLOB archives "${BUILD_DIR}/download/${id}*.tar.gz")
if(archives)
message(STATUS "Removing old archives of ${id}: ${archives}")
file(REMOVE ${archives})
# download the addon if necessary
if(NOT "${archive_name}" STREQUAL "")
# download and extract the addon
if(NOT EXISTS ${BUILD_DIR}/download/${archive_name}.tar.gz)
# cleanup any of the previously downloaded archives of this addon
file(GLOB archives "${BUILD_DIR}/download/${id}*.tar.gz")
if(archives)
message(STATUS "Removing old archives of ${id}: ${archives}")
file(REMOVE ${archives})
endif()

# download the addon
file(DOWNLOAD "${url}" "${BUILD_DIR}/download/${archive_name}.tar.gz" STATUS dlstatus LOG dllog SHOW_PROGRESS)
list(GET dlstatus 0 retcode)
if(NOT ${retcode} EQUAL 0)
message(FATAL_ERROR "ERROR downloading ${url} - status: ${dlstatus} log: ${dllog}")
endif()
endif()

# download the addon
file(DOWNLOAD "${url}" "${BUILD_DIR}/download/${archive_name}.tar.gz" STATUS dlstatus LOG dllog SHOW_PROGRESS)
list(GET dlstatus 0 retcode)
if(NOT ${retcode} EQUAL 0)
message(FATAL_ERROR "ERROR downloading ${url} - status: ${dlstatus} log: ${dllog}")
# remove any previously extracted version of the addon
if(EXISTS "${BUILD_DIR}/${id}")
file(REMOVE_RECURSE "${BUILD_DIR}/${id}")
endif()
endif()

# remove any previously extracted version of the addon
if(EXISTS "${BUILD_DIR}/${id}")
file(REMOVE_RECURSE "${BUILD_DIR}/${id}")
# extract the addon from the archive
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzvf ${BUILD_DIR}/download/${archive_name}.tar.gz
WORKING_DIRECTORY ${BUILD_DIR})
file(GLOB extract_dir "${BUILD_DIR}/${archive_name}*")
if(extract_dir STREQUAL "")
message(FATAL_ERROR "${id}: error extracting ${BUILD_DIR}/download/${archive_name}.tar.gz")
else()
file(RENAME "${extract_dir}" "${BUILD_DIR}/${id}")
endif()

set(SOURCE_DIR ${BUILD_DIR}/${id})
endif()

# extract the addon from the archive
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzvf ${BUILD_DIR}/download/${archive_name}.tar.gz
WORKING_DIRECTORY ${BUILD_DIR})
file(GLOB extract_dir "${BUILD_DIR}/${archive_name}*")
if(extract_dir STREQUAL "")
message(FATAL_ERROR "Error extracting ${BUILD_DIR}/download/${archive_name}.tar.gz")
if(NOT "${SOURCE_DIR}" STREQUAL "" AND EXISTS ${SOURCE_DIR})
# setup the buildsystem for the addon
externalproject_add(${id}
SOURCE_DIR ${SOURCE_DIR}
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
CMAKE_ARGS ${BUILD_ARGS})

# add a custom step to the external project between the configure and the build step which will always
# be executed and therefore forces a re-build of all changed files
externalproject_add_step(${id} forcebuild
COMMAND ${CMAKE_COMMAND} -E echo "Force build of ${id}"
DEPENDEES configure
DEPENDERS build
ALWAYS 1)

# add "kodi-platform" as a dependency to every addon
add_dependencies(${id} kodi-platform)

set(${id}_DEPENDS_DIR ${SOURCE_DIR}/depends)

if(EXISTS ${${id}_DEPENDS_DIR})
include(${APP_ROOT}/project/cmake/scripts/common/handle-depends.cmake)
add_addon_depends(${id} ${${id}_DEPENDS_DIR})
if(${id}_DEPS AND NOT "${${id}_DEPS}" STREQUAL "")
message(STATUS "${id} DEPENDENCIES: ${${id}_DEPS}")
add_dependencies(${id} ${${id}_DEPS})
endif()
endif()
else()
file(RENAME "${extract_dir}" "${BUILD_DIR}/${id}")
message(FATAL_ERROR "${id}: invalid or missing addon source directory at ${SOURCE_DIR}")
endif()

list(APPEND downloaded_addons ${id})

endif()
endif()
endif()
endforeach()

foreach(id ${downloaded_addons})
externalproject_add(${id}
SOURCE_DIR ${BUILD_DIR}/${id}
INSTALL_DIR ${ADDON_INSTALL_DIR}
CMAKE_ARGS ${BUILD_ARGS})

# add a custom step to the external project between the configure and the build step which will always
# be executed and therefore forces a re-build of all changed files
externalproject_add_step(${id} forcebuild
COMMAND ${CMAKE_COMMAND} -E echo "Force build of ${id}"
DEPENDEES configure
DEPENDERS build
ALWAYS 1)

# add "kodi-platform" as a dependency to every addon
add_dependencies(${id} kodi-platform)

set(${id}_DEPENDS_DIR ${BUILD_DIR}/${id}/depends)

if(EXISTS ${${id}_DEPENDS_DIR})
include(${APP_ROOT}/project/cmake/scripts/common/handle-depends.cmake)
add_addon_depends(${id} ${${id}_DEPENDS_DIR})
if (${id}_DEPS AND NOT "${${id}_DEPS}" STREQUAL "")
message(STATUS "${id} DEPENDENCIES: ${${id}_DEPS}")
add_dependencies(${id} ${${id}_DEPS})
endif()
endif()
endforeach()

if(NEED_SUDO)
add_custom_target(install
COMMAND ${CMAKE_COMMAND} -E echo "\n\n"
Expand Down
12 changes: 10 additions & 2 deletions project/cmake/addons/README
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ KODI ADDONS
This directory contains the cmake-based buildsystem for addons. It looks into
the "addons" sub-directory and parses all *.txt files recursively. Each addon
must have its own <addon-id>.txt file in a separate sub-directory which must
follow the defined format:
follow one of the defined format:
<addon-id> <git-url> <git-revision>
<addon-id> <tarball-url>
<addon-id> <file://path>
where
* <addon-id> must be identical to the addon's ID as defined in the addon's
addon.xml
* <git-url> must be the URL of the git repository containing the addon.
* <git-url> must be the URL of the git repository containing the addon
* <git-revision> must be a valid git tag/branch/commit in the addon's git
repository which will be used for the build.
* <tarball-url> must be the URL to a .tar.gz tarball containing the addon
* <file://path> must be a file:// based path to the directory containing the
addon

Reserved filenames (for additional information on how to build an addon)
are:
Expand All @@ -24,6 +29,9 @@ executing cmake with the -D<variable-name>=<value> option) to e.g. access
specific paths:
* ADDONS_TO_BUILD is a quoted, space delimited list of <addon-id>s that
you want to build (default is "all").
* ADDON_SRC_PREFIX can be used to override the addon repository location.
It must point to the locally available parent directory of the addon(s) to build
<addon-id> will be appended to this path automatically
* CMAKE_BUILD_TYPE specifies the type of the build. This can be either "Debug"
or "Release" (default is "Release").
* CMAKE_INSTALL_PREFIX points to the directory where the built addons and their
Expand Down

0 comments on commit ec963fa

Please sign in to comment.