2 # Copyright (C) 2012-2018 Icinga Development Team (https://www.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 function(install_if_not_exists src dest)
19 set(real_dest "${dest}")
20 if(NOT IS_ABSOLUTE "${src}")
21 set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
23 get_filename_component(src_name "${src}" NAME)
24 get_filename_component(basename_dest "${src}" NAME)
25 string(REPLACE "/" "\\\\" nsis_src "${src}")
26 string(REPLACE "/" "\\\\" nsis_dest_dir "${real_dest}")
27 string(REPLACE "/" "\\\\" nsis_dest "${real_dest}/${basename_dest}")
29 if(\"\$ENV{DESTDIR}\" STREQUAL \"\")
30 set(target_dir \${CMAKE_INSTALL_PREFIX})
32 set(target_dir \$ENV{DESTDIR})
34 if(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.* OR NOT EXISTS \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/\${skel_prefix}${dest}/${src_name}\")
35 message(STATUS \"Installing: \$ENV{DESTDIR}${dest}/${src_name}\")
36 if(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.*)
37 set(skel_prefix \"share/skel/\")
41 execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\"
42 \"\${target_dir}/\${skel_prefix}${dest}/${src_name}\"
43 RESULT_VARIABLE copy_result
44 ERROR_VARIABLE error_output)
46 message(FATAL_ERROR \${error_output})
49 message(STATUS \"Skipping : \${target_dir}/${dest}/${src_name}\")
52 endfunction(install_if_not_exists)