Skip to content

Commit

Permalink
cmake: support file:// based paths for addon definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Mar 3, 2015
1 parent 17ce62c commit 49e9026
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 53 deletions.
133 changes: 82 additions & 51 deletions project/cmake/addons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ foreach(addon ${addons})
list(GET def 1 url)

set(archive_name ${id})
set(SOURCE_DIR "")

# if there is a 3rd parameter in the file, we consider it a git revision
if(deflength GREATER 2)
Expand All @@ -169,71 +170,101 @@ foreach(addon ${addons})
# if we ever use other repositories, this might need adapting
set(url ${url}/archive/${revision}.tar.gz)
set(archive_name ${archive_name}-${revision})
else()
# 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}")
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 "${id}: error extracting ${BUILD_DIR}/download/${archive_name}.tar.gz")
else()
file(RENAME "${extract_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")
else()
file(RENAME "${extract_dir}" "${BUILD_DIR}/${id}")
set(SOURCE_DIR ${BUILD_DIR}/${id})
endif()

# setup building the addon
externalproject_add(${id}
SOURCE_DIR ${BUILD_DIR}/${id}
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 ${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})
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()
message(FATAL_ERROR "${id}: invalid or missing addon source directory at ${SOURCE_DIR}")
endif()
endif()
endif()
endif()
endforeach(
endforeach()

if(NEED_SUDO)
add_custom_target(install
Expand Down
9 changes: 7 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 Down

0 comments on commit 49e9026

Please sign in to comment.