1 # Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
3 # Install $src into directory $dest - usually only used for config files
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
9 # also see https://cmake.org/cmake/help/latest/command/install.html
11 function(install_if_not_exists src dest)
12 if(NOT IS_ABSOLUTE "${src}")
13 set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
16 get_filename_component(src_name "${src}" NAME)
21 if (\"\${CMAKE_INSTALL_PREFIX}\" MATCHES .*/_CPack_Packages/.*)
22 set(dest \"share/skel/\${dest}\")
23 set(force_overwrite TRUE)
25 set(force_overwrite FALSE)
28 if(NOT IS_ABSOLUTE \"\${dest}\")
29 set(dest \"\${CMAKE_INSTALL_PREFIX}/\${dest}\")
32 set(full_dest \"\$ENV{DESTDIR}\${dest}/${src_name}\")
34 if(force_overwrite OR NOT EXISTS \"\${full_dest}\")
35 message(STATUS \"Installing: ${src} into \${full_dest}\")
37 execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\" \"\${full_dest}\"
38 RESULT_VARIABLE copy_result
39 ERROR_VARIABLE error_output)
41 message(FATAL_ERROR \${error_output})
44 message(STATUS \"Skipping : \${full_dest}\")
47 endfunction(install_if_not_exists)