Skip to content

Commit

Permalink
cmake: ask for sudo rights on addon install to system dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
wsnipex authored and Montellese committed Mar 1, 2015
1 parent efaf6f1 commit 98bf72d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
20 changes: 19 additions & 1 deletion project/cmake/addons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ endif()
# include check_target_platform() function
include(${APP_ROOT}/project/cmake/scripts/common/check_target_platform.cmake)

# check install permissions
set(ADDON_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
check_install_permissions(${CMAKE_INSTALL_PREFIX} can_write)
if(NOT ${can_write} AND NOT WIN32)
set(NEED_SUDO TRUE)
set(ADDON_INSTALL_DIR ${CMAKE_BINARY_DIR}/.install)
message(STATUS "NEED_SUDO: ${NEED_SUDO}")
endif()

### prepare the build environment for the binary addons
# copy the prepare-env.cmake script to the depends path so that we can include it
file(COPY ${APP_ROOT}/project/cmake/scripts/common/prepare-env.cmake DESTINATION ${KODI_LIB_DIR})
Expand Down Expand Up @@ -204,7 +213,7 @@ endforeach()
foreach(id ${downloaded_addons})
externalproject_add(${id}
SOURCE_DIR ${BUILD_DIR}/${id}
INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
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
Expand All @@ -229,3 +238,12 @@ foreach(id ${downloaded_addons})
endif()
endif()
endforeach()

if(NEED_SUDO)
add_custom_target(install
COMMAND ${CMAKE_COMMAND} -E echo "\n\n"
COMMAND ${CMAKE_COMMAND} -E echo "WARNING: sudo rights needed to install to ${CMAKE_INSTALL_PREFIX}\n"
COMMAND sudo ${CMAKE_COMMAND} -E copy_directory ${ADDON_INSTALL_DIR}/ ${CMAKE_INSTALL_PREFIX}/
COMMAND sudo ${CMAKE_COMMAND} -E remove_directory ${ADDON_INSTALL_DIR}/
COMMAND sudo -k)
endif()
21 changes: 21 additions & 0 deletions project/cmake/scripts/common/check_target_platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,24 @@ function(check_target_platform dir target_platform build)
# make the ${build} variable available to the calling script
set(${build} "${${build}}" PARENT_SCOPE)
endfunction()

function(check_install_permissions install_dir have_perms)
# param[in] install_dir directory to check for write permissions
# param[out] have_perms wether we have permissions to install to install_dir

set(${have_perms} TRUE)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir}/lib/kodi
COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir}/share/kodi
COMMAND ${CMAKE_COMMAND} -E touch ${install_dir}/lib/kodi/.cmake-inst-test ${install_dir}/share/kodi/.cmake-inst-test
RESULT_VARIABLE permtest)

if(${permtest} GREATER 0)
message(STATUS "check_install_permissions: ${permtest}")
set(${have_perms} FALSE)
endif()
set(${have_perms} "${${have_perms}}" PARENT_SCOPE)

if(EXISTS ${install_dir}/lib/kodi/.cmake-inst-test OR EXISTS ${install_dir}/share/kodi/.cmake-inst-test)
file(REMOVE ${install_dir}/lib/kodi/.cmake-inst-test ${install_dir}/share/kodi/.cmake-inst-test)
endif()
endfunction()
3 changes: 3 additions & 0 deletions tools/depends/xbmc-addons.include
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ endif
$(TOOLCHAIN) \
-DADDONS_TO_BUILD=$(ADDONS) ../../../../../project/cmake/addons/ -DBUILD_DIR=$(BUILDDIR)/$(PLATFORM)/build ;\
$(MAKE);
ifneq ($(CROSS_COMPILING),yes)
@[ -w $(INSTALL_PREFIX) ] || $(MAKE) -C $(PLATFORM) install
endif
touch $@

$(TOOLCHAIN_FILE): $(abs_top_srcdir)/target/Toolchain_binaddons.cmake
Expand Down

0 comments on commit 98bf72d

Please sign in to comment.