[CMake] Ignore installation failure

David Adam zanchey at ucc.gu.uwa.edu.au
Tue Feb 20 08:10:18 EST 2018


On Sun, 18 Feb 2018, David Adam wrote:
> Our project installs an empty directory for other programs to drop files 
> in, the location of which is overrideable with a cache variable. Some 
> environments set the location of this directory outside the writeable 
> area and create it themselves, so I'd like to set up CMake so that it 
> tries to create the directory but skips over it if there is a failure.
> 
> At the moment we use:
> 
> SET(extra_completionsdir
>     ${rel_datadir}/fish/vendor_completions.d
>     CACHE STRING "Path for extra completions")
> INSTALL(DIRECTORY DESTINATION ${extra_completionsdir})
> 
> but that fails if the destination is not writeable.
> 
> Is there an idiomatic way of ignoring a failed installation step? At the 
> moment, I'm trying various install(script code execute_process(... 
> incantations, but I'm aware there's lots of corner cases with DESTDIR and 
> so on.

For the record, I ended up implementing just enough to make our use case 
work:

FUNCTION(FISH_TRY_CREATE_DIRS)
  FOREACH(dir ${ARGV})
    IF(NOT IS_ABSOLUTE ${dir})
      SET(abs_dir "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${dir}")
    ELSE()
      SET(abs_dir "\$ENV{DESTDIR}${dir}")
    ENDIF()
    INSTALL(SCRIPT CODE "EXECUTE_PROCESS(COMMAND mkdir -p ${abs_dir} OUTPUT_QUIET ERROR_QUIET)
                         EXECUTE_PROCESS(COMMAND chmod 755 ${abs_dir} OUTPUT_QUIET ERROR_QUIET)
                        ")
  ENDFOREACH()
ENDFUNCTION(FISH_TRY_CREATE_DIRS)

Perhaps that will help someone in a similar situation in the future.

David Adam
zanchey at ucc.gu.uwa.edu.au



More information about the CMake mailing list