Tarod
Tarod

Reputation: 7170

Check permissions of the destination directory before installing

I've been searching in the documentation and SO but I haven't found an answer for this issue.

Using , I'm trying to check the permission of the DESTINATION directory before installing some libraries.

Is there some command in cmake to do this? Do I need to make the checks with custom commands?

As an example, this is my code in my CMakeLists.txt:

INSTALL( TARGETS ${LIBRARY_NAME}
 DESTINATION lib/plugins/
 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE )

The idea is to check if the user has the required permissions to write in lib/plugins/ before installing the plugins.

Upvotes: 1

Views: 1010

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 66061

You can use install(SCRIPT ...) command flow for execute some CMake script at install stage. For example:

check_script.cmake.in:

EXECUTE_PROCESS(COMMAND test -w @CMAKE_INSTALL_PREFIX@/lib/plugins
    RESULT_VARIABLE res)
IF(res)
    MESSAGE(FATAL_ERROR "No write permissions on plugins directory")
ENDIF()

CMakeLists.txt:

CONFIGURE_FILE(check_script.cmake.in check_script.cmake @ONLY)
INSTALL(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/check_script.cmake)
INSTALL( TARGETS ${LIBRARY_NAME} DESTINATION lib/plugins/ ...)

As you can see, it is too many work to check file permissions on install stage. Actually, you rarely need such checks: if installing of file fails, whole installation process stops immediately, and appropriate message is shown to the user.

Upvotes: 2

Related Questions