diff options
| author | manuel <manuel@mausz.at> | 2015-03-03 16:53:59 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2015-03-03 16:53:59 +0100 |
| commit | ffca21f2743a7b367fa212799c6e2fea6190dd5d (patch) | |
| tree | 0608ea3a29cf644ec9ab204e2b4bb9bfaae1c381 /project/cmake/scripts/common/addon-helpers.cmake | |
| download | kodi-pvr-build-ffca21f2743a7b367fa212799c6e2fea6190dd5d.tar.gz kodi-pvr-build-ffca21f2743a7b367fa212799c6e2fea6190dd5d.tar.bz2 kodi-pvr-build-ffca21f2743a7b367fa212799c6e2fea6190dd5d.zip | |
initial commit for kodi master
Diffstat (limited to 'project/cmake/scripts/common/addon-helpers.cmake')
| -rw-r--r-- | project/cmake/scripts/common/addon-helpers.cmake | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/project/cmake/scripts/common/addon-helpers.cmake b/project/cmake/scripts/common/addon-helpers.cmake new file mode 100644 index 0000000..b94df2a --- /dev/null +++ b/project/cmake/scripts/common/addon-helpers.cmake | |||
| @@ -0,0 +1,113 @@ | |||
| 1 | # Workaround for the fact that cpack's filenames are not customizable. | ||
| 2 | # Each add-on is added as a separate component to facilitate zip/tgz packaging. | ||
| 3 | # The filenames are always of the form basename-component, which is | ||
| 4 | # incompatible with the addonid-version scheme we want. This hack renames | ||
| 5 | # the files from the file names generated by the 'package' target. | ||
| 6 | # Sadly we cannot extend the 'package' target, as it is a builtin target, see | ||
| 7 | # http://public.kitware.com/Bug/view.php?id=8438 | ||
| 8 | # Thus, we have to add an 'addon-package' target. | ||
| 9 | add_custom_target(addon-package | ||
| 10 | COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target package) | ||
| 11 | |||
| 12 | macro(add_cpack_workaround target version ext) | ||
| 13 | add_custom_command(TARGET addon-package PRE_BUILD | ||
| 14 | COMMAND ${CMAKE_COMMAND} -E rename addon-${target}-${version}.${ext} ${target}-${version}.${ext}) | ||
| 15 | endmacro() | ||
| 16 | |||
| 17 | # Grab the version from a given add-on's addon.xml | ||
| 18 | macro (addon_version dir prefix) | ||
| 19 | FILE(READ ${dir}/addon.xml ADDONXML) | ||
| 20 | STRING(REGEX MATCH "<addon[^>]*version.?=.?.[0-9\\.]+" VERSION_STRING ${ADDONXML}) | ||
| 21 | STRING(REGEX REPLACE ".*version=.([0-9\\.]+).*" "\\1" ${prefix}_VERSION ${VERSION_STRING}) | ||
| 22 | message(STATUS ${prefix}_VERSION=${${prefix}_VERSION}) | ||
| 23 | endmacro() | ||
| 24 | |||
| 25 | # Build, link and optionally package an add-on | ||
| 26 | macro (build_addon target prefix libs) | ||
| 27 | ADD_LIBRARY(${target} ${${prefix}_SOURCES}) | ||
| 28 | TARGET_LINK_LIBRARIES(${target} ${${libs}}) | ||
| 29 | addon_version(${target} ${prefix}) | ||
| 30 | SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${${prefix}_VERSION} | ||
| 31 | SOVERSION ${APP_VERSION_MAJOR}.${APP_VERSION_MINOR} | ||
| 32 | PREFIX "") | ||
| 33 | IF(OS STREQUAL "android") | ||
| 34 | SET_TARGET_PROPERTIES(${target} PROPERTIES PREFIX "lib") | ||
| 35 | ENDIF(OS STREQUAL "android") | ||
| 36 | |||
| 37 | # set zip as default if addon-package is called without PACKAGE_XXX | ||
| 38 | SET(CPACK_GENERATOR "ZIP") | ||
| 39 | SET(ext "zip") | ||
| 40 | IF(PACKAGE_ZIP OR PACKAGE_TGZ) | ||
| 41 | IF(PACKAGE_TGZ) | ||
| 42 | SET(CPACK_GENERATOR "TGZ") | ||
| 43 | SET(ext "tar.gz") | ||
| 44 | ENDIF(PACKAGE_TGZ) | ||
| 45 | SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF) | ||
| 46 | set(CPACK_PACKAGE_FILE_NAME addon) | ||
| 47 | IF(CMAKE_BUILD_TYPE STREQUAL "Release") | ||
| 48 | SET(CPACK_STRIP_FILES TRUE) | ||
| 49 | ENDIF(CMAKE_BUILD_TYPE STREQUAL "Release") | ||
| 50 | set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) | ||
| 51 | set(CPACK_COMPONENTS_IGNORE_GROUPS 1) | ||
| 52 | list(APPEND CPACK_COMPONENTS_ALL ${target}-${${prefix}_VERSION}) | ||
| 53 | # Pack files together to create an archive | ||
| 54 | INSTALL(DIRECTORY ${target} DESTINATION ./ COMPONENT ${target}-${${prefix}_VERSION}) | ||
| 55 | IF(WIN32) | ||
| 56 | # get the installation location for the addon's target | ||
| 57 | get_property(dll_location TARGET ${target} PROPERTY LOCATION) | ||
| 58 | # in case of a VC++ project the installation location contains a $(Configuration) VS variable | ||
| 59 | # we replace it with ${CMAKE_BUILD_TYPE} (which doesn't cover the case when the build configuration | ||
| 60 | # is changed within Visual Studio) | ||
| 61 | string(REPLACE "$(Configuration)" "${CMAKE_BUILD_TYPE}" dll_location "${dll_location}") | ||
| 62 | |||
| 63 | # install the generated DLL file | ||
| 64 | INSTALL(PROGRAMS ${dll_location} DESTINATION ${target} | ||
| 65 | COMPONENT ${target}-${${prefix}_VERSION}) | ||
| 66 | |||
| 67 | IF(CMAKE_BUILD_TYPE MATCHES Debug) | ||
| 68 | # for debug builds also install the PDB file | ||
| 69 | get_filename_component(dll_directory ${dll_location} DIRECTORY) | ||
| 70 | INSTALL(FILES ${dll_directory}/${target}.pdb DESTINATION ${target} | ||
| 71 | COMPONENT ${target}-${${prefix}_VERSION}) | ||
| 72 | ENDIF() | ||
| 73 | ELSE(WIN32) | ||
| 74 | INSTALL(TARGETS ${target} DESTINATION ${target} | ||
| 75 | COMPONENT ${target}-${${prefix}_VERSION}) | ||
| 76 | ENDIF(WIN32) | ||
| 77 | add_cpack_workaround(${target} ${${prefix}_VERSION} ${ext}) | ||
| 78 | ELSE(PACKAGE_ZIP OR PACKAGE_TGZ) | ||
| 79 | INSTALL(TARGETS ${target} DESTINATION lib/kodi/addons/${target}) | ||
| 80 | INSTALL(DIRECTORY ${target} DESTINATION share/kodi/addons) | ||
| 81 | ENDIF(PACKAGE_ZIP OR PACKAGE_TGZ) | ||
| 82 | endmacro() | ||
| 83 | |||
| 84 | # finds a path to a given file (recursive) | ||
| 85 | function (kodi_find_path var_name filename search_path strip_file) | ||
| 86 | file(GLOB_RECURSE PATH_TO_FILE ${search_path} ${filename}) | ||
| 87 | if(strip_file) | ||
| 88 | string(REPLACE ${filename} "" PATH_TO_FILE ${PATH_TO_FILE}) | ||
| 89 | endif(strip_file) | ||
| 90 | set (${var_name} ${PATH_TO_FILE} PARENT_SCOPE) | ||
| 91 | endfunction() | ||
| 92 | |||
| 93 | # Cmake build options | ||
| 94 | include(addoptions) | ||
| 95 | include(TestCXXAcceptsFlag) | ||
| 96 | OPTION(PACKAGE_ZIP "Package Zip file?" OFF) | ||
| 97 | OPTION(PACKAGE_TGZ "Package TGZ file?" OFF) | ||
| 98 | OPTION(BUILD_SHARED_LIBS "Build shared libs?" ON) | ||
| 99 | |||
| 100 | # LTO support? | ||
| 101 | CHECK_CXX_ACCEPTS_FLAG("-flto" HAVE_LTO) | ||
| 102 | IF(HAVE_LTO) | ||
| 103 | OPTION(USE_LTO "use link time optimization" OFF) | ||
| 104 | IF(USE_LTO) | ||
| 105 | add_options(ALL_LANGUAGES ALL_BUILDS "-flto") | ||
| 106 | ENDIF(USE_LTO) | ||
| 107 | ENDIF(HAVE_LTO) | ||
| 108 | |||
| 109 | # set this to try linking dependencies as static as possible | ||
| 110 | IF(ADDONS_PREFER_STATIC_LIBS) | ||
| 111 | SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) | ||
| 112 | ENDIF(ADDONS_PREFER_STATIC_LIBS) | ||
| 113 | |||
