]> granicus.if.org Git - icinga2/blob - cmake/InstallConfig.cmake
Cli: Add blacklist/whitelist commands for agent commands
[icinga2] / cmake / InstallConfig.cmake
1 # Icinga 2
2 # Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)
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 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}")
22   endif()
23   get_filename_component(src_name "${src}" NAME)
24   if (NOT IS_ABSOLUTE "${dest}")
25     set(dest "${CMAKE_INSTALL_PREFIX}/${dest}")
26   endif()
27   get_filename_component(basename_dest "${src}" NAME)
28   string(REPLACE "/" "\\\\" nsis_src "${src}")
29   string(REPLACE "/" "\\\\" nsis_dest_dir "${real_dest}")
30   string(REPLACE "/" "\\\\" nsis_dest "${real_dest}/${basename_dest}")
31   set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}
32     SetOverwrite off
33     CreateDirectory '$INSTDIR\\\\${nsis_dest_dir}'
34     File '/oname=${nsis_dest}' '${nsis_src}'
35     SetOverwrite on
36   " PARENT_SCOPE)
37   install(CODE "
38     if(NOT EXISTS \"\$ENV{DESTDIR}${dest}/${src_name}\")
39       #file(INSTALL \"${src}\" DESTINATION \"${dest}\")
40       message(STATUS \"Installing: \$ENV{DESTDIR}${dest}/${src_name}\")
41       execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\"
42                       \"\$ENV{DESTDIR}${dest}/${src_name}\"
43                       RESULT_VARIABLE copy_result
44                       ERROR_VARIABLE error_output)
45       if(copy_result)
46         message(FATAL_ERROR \${error_output})
47       endif()
48     else()
49       message(STATUS \"Skipping  : \$ENV{DESTDIR}${dest}/${src_name}\")
50     endif()
51   ")
52 endfunction(install_if_not_exists)