2 # Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com)
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.
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.
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.
18 # Install $src into directory $dest - usually only used for config files
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
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}")
30 get_filename_component(src_name "${src}" NAME)
35 if (\"\${CMAKE_INSTALL_PREFIX}\" MATCHES .*/_CPack_Packages/.*)
36 set(dest \"share/skel/\${dest}\")
37 set(force_overwrite TRUE)
39 set(force_overwrite FALSE)
42 if(NOT IS_ABSOLUTE \"\${dest}\")
43 set(dest \"\${CMAKE_INSTALL_PREFIX}/\${dest}\")
46 set(full_dest \"\$ENV{DESTDIR}\${dest}/${src_name}\")
48 if(force_overwrite OR NOT EXISTS \"\${full_dest}\")
49 message(STATUS \"Installing: ${src} into \${full_dest}\")
51 execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\" \"\${full_dest}\"
52 RESULT_VARIABLE copy_result
53 ERROR_VARIABLE error_output)
55 message(FATAL_ERROR \${error_output})
58 message(STATUS \"Skipping : \${full_dest}\")
61 endfunction(install_if_not_exists)