]> granicus.if.org Git - icinga2/blob - cmake/InstallConfig.cmake
Merge pull request #7403 from Icinga/feature/docs-agents
[icinga2] / cmake / InstallConfig.cmake
1 # Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
2 #
3 # Install $src into directory $dest - usually only used for config files
4 #
5 # * similar to install() a non absolute path is prefixed with CMAKE_INSTALL_PREFIX on runtime
6 # * in case of CPack path with be prefixed with share/skel/
7 # * DESTDIR is prefixed as well
8 #
9 # also see https://cmake.org/cmake/help/latest/command/install.html
10
11 function(install_if_not_exists src dest)
12   if(NOT IS_ABSOLUTE "${src}")
13     set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
14   endif()
15
16   get_filename_component(src_name "${src}" NAME)
17
18   install(CODE "
19     set(dest \"${dest}\")
20
21     if (\"\${CMAKE_INSTALL_PREFIX}\" MATCHES .*/_CPack_Packages/.*)
22       set(dest \"share/skel/\${dest}\")
23       set(force_overwrite TRUE)
24     else()
25       set(force_overwrite FALSE)
26     endif()
27
28     if(NOT IS_ABSOLUTE \"\${dest}\")
29       set(dest \"\${CMAKE_INSTALL_PREFIX}/\${dest}\")
30     endif()
31
32     set(full_dest \"\$ENV{DESTDIR}\${dest}/${src_name}\")
33
34     if(force_overwrite OR NOT EXISTS \"\${full_dest}\")
35       message(STATUS \"Installing: ${src} into \${full_dest}\")
36
37       execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\" \"\${full_dest}\"
38                       RESULT_VARIABLE copy_result
39                       ERROR_VARIABLE error_output)
40       if(copy_result)
41         message(FATAL_ERROR \${error_output})
42       endif()
43     else()
44       message(STATUS \"Skipping  : \${full_dest}\")
45     endif()
46   ")
47 endfunction(install_if_not_exists)