# Workaround for the fact that cpack's filenames are not customizable. # Each add-on is added as a separate component to facilitate zip/tgz packaging. # The filenames are always of the form basename-component, which is # incompatible with the addonid-version scheme we want. This hack renames # the files from the file names generated by the 'package' target. # Sadly we cannot extend the 'package' target, as it is a builtin target, see # http://public.kitware.com/Bug/view.php?id=8438 # Thus, we have to add an 'addon-package' target. add_custom_target(addon-package COMMAND cmake --build ${CMAKE_BINARY_DIR} --target package) macro(add_cpack_workaround target version) add_custom_command(TARGET addon-package PRE_BUILD COMMAND cmake -E rename addon-${target}-${version}.zip ${target}-${version}.zip) endmacro() # Grab the version from a given add-on's addon.xml macro (addon_version dir prefix) FILE(READ ${dir}/addon.xml ADDONXML) STRING(REGEX MATCH "]*version.?=.?.[0-9\\.]+" VERSION_STRING ${ADDONXML}) STRING(REGEX REPLACE ".*version=.([0-9\\.]+).*" "\\1" ${prefix}_VERSION ${VERSION_STRING}) message(STATUS ${prefix}_VERSION=${${prefix}_VERSION}) endmacro() # Prepare the add-on build environment macro (prepare_addon_environment) IF(WIN32) SET(BINDING_FILE ${XBMC_BINDINGS}.zip) message (STATUS "downloading XBMC bindings: " ${BINDING_FILE}) file(DOWNLOAD http://mirrors.xbmc.org/build-deps/win32/${BINDING_FILE} ${CMAKE_BINARY_DIR}/downloads/${BINDING_FILE} STATUS STATUSLIST SHOW_PROGRESS) LIST(GET STATUSLIST 0 VALUE) IF(${VALUE} STRGREATER "0") LIST(GET STATUSLIST 1 VALUE) message (STATUS "failed to download XBMC bindings: " ${VALUE}) ENDIF(${VALUE} STRGREATER "0") execute_process( COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_BINARY_DIR}/downloads/${BINDING_FILE} ) ENDIF(WIN32) endmacro() # Build, link and optionally package an add-on macro (build_addon target prefix libs) ADD_LIBRARY(${target} ${${prefix}_SOURCES}) TARGET_LINK_LIBRARIES(${target} ${${libs}}) addon_version(${target} ${prefix}) SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${${prefix}_VERSION} SOVERSION 13.0 PREFIX "") IF(OS STREQUAL "android") SET_TARGET_PROPERTIES(${target} PROPERTIES PREFIX "lib") ENDIF(OS STREQUAL "android") IF(PACKAGE_ZIP OR PACKAGE_TGZ) IF(PACKAGE_ZIP) SET(CPACK_GENERATOR "ZIP") ENDIF(PACKAGE_ZIP) IF(PACKAGE_TGZ) SET(CPACK_GENERATOR "TGZ") ENDIF(PACKAGE_TGZ) SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF) set(CPACK_PACKAGE_FILE_NAME addon) IF(CMAKE_BUILD_TYPE STREQUAL "Release") SET(CPACK_STRIP_FILES TRUE) ENDIF(CMAKE_BUILD_TYPE STREQUAL "Release") set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) set(CPACK_COMPONENTS_IGNORE_GROUPS 1) list(APPEND CPACK_COMPONENTS_ALL ${target}-${${prefix}_VERSION}) # Pack files together to create an archive INSTALL(DIRECTORY ${target} DESTINATION ./ COMPONENT ${target}-${${prefix}_VERSION}) IF(WIN32) INSTALL(PROGRAMS ${CMAKE_BINARY_DIR}/${target}.dll DESTINATION ${target} COMPONENT ${target}-${${prefix}_VERSION}) ELSE(WIN32) INSTALL(TARGETS ${target} DESTINATION ${target} COMPONENT ${target}-${${prefix}_VERSION}) ENDIF(WIN32) add_cpack_workaround(${target} ${${prefix}_VERSION}) ELSE(PACKAGE_ZIP OR PACKAGE_TGZ) INSTALL(TARGETS ${target} DESTINATION lib/xbmc/addons/${target}) INSTALL(DIRECTORY ${target} DESTINATION share/xbmc/addons) ENDIF(PACKAGE_ZIP OR PACKAGE_TGZ) endmacro() # finds a path to a given file (recursive) function (xbmc_find_path var_name filename search_path strip_file) file(GLOB_RECURSE PATH_TO_FILE ${search_path} ${filename}) if(strip_file) string(REPLACE ${filename} "" PATH_TO_FILE ${PATH_TO_FILE}) endif(strip_file) set (${var_name} ${PATH_TO_FILE} PARENT_SCOPE) endfunction()