]> granicus.if.org Git - icinga2/blob - cmake/InstallConfig.cmake
Merge pull request #6718 from Icinga/bugfix/ssl-shutdown
[icinga2] / cmake / InstallConfig.cmake
1 # Icinga 2
2 # Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com)
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation
16 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 # Install $src into directory $dest - usually only used for config files
19 #
20 # * similar to install() a non absolute path is prefixed with CMAKE_INSTALL_PREFIX on runtime
21 # * in case of CPack path with be prefixed with share/skel/
22 # * DESTDIR is prefixed as well
23 #
24 # also see https://cmake.org/cmake/help/latest/command/install.html
25 function(install_if_not_exists src dest)
26   if(NOT IS_ABSOLUTE "${src}")
27     set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
28   endif()
29
30   get_filename_component(src_name "${src}" NAME)
31
32   install(CODE "
33     set(dest \"${dest}\")
34
35     if (\"\${CMAKE_INSTALL_PREFIX}\" MATCHES .*/_CPack_Packages/.*)
36       set(dest \"share/skel/\${dest}\")
37       set(force_overwrite TRUE)
38     else()
39       set(force_overwrite FALSE)
40     endif()
41
42     if(NOT IS_ABSOLUTE \"\${dest}\")
43       set(dest \"\${CMAKE_INSTALL_PREFIX}/\${dest}\")
44     endif()
45
46     set(full_dest \"\$ENV{DESTDIR}\${dest}/${src_name}\")
47
48     if(force_overwrite OR NOT EXISTS \"\${full_dest}\")
49       message(STATUS \"Installing: ${src} into \${full_dest}\")
50
51       execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\" \"\${full_dest}\"
52                       RESULT_VARIABLE copy_result
53                       ERROR_VARIABLE error_output)
54       if(copy_result)
55         message(FATAL_ERROR \${error_output})
56       endif()
57     else()
58       message(STATUS \"Skipping  : \${full_dest}\")
59     endif()
60   ")
61 endfunction(install_if_not_exists)