mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-28 16:14:09 +02:00
cmake: Improve InstallConfig for stable path handling
* similar to install() a non absolute path is prefixed with CMAKE_INSTALL_PREFIX on runtime * in case of CPack path with be prefixed with share/skel/ * DESTDIR is prefixed as well Also see https://cmake.org/cmake/help/latest/command/install.html
This commit is contained in:
parent
8bac1dc99e
commit
1e4ee94f07
@ -15,38 +15,47 @@
|
|||||||
# along with this program; if not, write to the Free Software Foundation
|
# along with this program; if not, write to the Free Software Foundation
|
||||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
# Install $src into directory $dest - usually only used for config files
|
||||||
|
#
|
||||||
|
# * similar to install() a non absolute path is prefixed with CMAKE_INSTALL_PREFIX on runtime
|
||||||
|
# * in case of CPack path with be prefixed with share/skel/
|
||||||
|
# * DESTDIR is prefixed as well
|
||||||
|
#
|
||||||
|
# also see https://cmake.org/cmake/help/latest/command/install.html
|
||||||
function(install_if_not_exists src dest)
|
function(install_if_not_exists src dest)
|
||||||
set(real_dest "${dest}")
|
|
||||||
if(NOT IS_ABSOLUTE "${src}")
|
if(NOT IS_ABSOLUTE "${src}")
|
||||||
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
|
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
get_filename_component(src_name "${src}" NAME)
|
get_filename_component(src_name "${src}" NAME)
|
||||||
get_filename_component(basename_dest "${src}" NAME)
|
|
||||||
string(REPLACE "/" "\\\\" nsis_src "${src}")
|
|
||||||
string(REPLACE "/" "\\\\" nsis_dest_dir "${real_dest}")
|
|
||||||
string(REPLACE "/" "\\\\" nsis_dest "${real_dest}/${basename_dest}")
|
|
||||||
install(CODE "
|
install(CODE "
|
||||||
if(\"\$ENV{DESTDIR}\" STREQUAL \"\")
|
set(dest \"${dest}\")
|
||||||
set(target_dir \${CMAKE_INSTALL_PREFIX})
|
|
||||||
|
if (\"\${CMAKE_INSTALL_PREFIX}\" MATCHES .*/_CPack_Packages/.*)
|
||||||
|
set(dest \"share/skel/\${dest}\")
|
||||||
|
set(force_overwrite TRUE)
|
||||||
else()
|
else()
|
||||||
set(target_dir \$ENV{DESTDIR})
|
set(force_overwrite FALSE)
|
||||||
endif()
|
endif()
|
||||||
if(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.* OR NOT EXISTS \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/\${skel_prefix}${dest}/${src_name}\")
|
|
||||||
message(STATUS \"Installing: \$ENV{DESTDIR}${dest}/${src_name}\")
|
if(NOT IS_ABSOLUTE \"\${dest}\")
|
||||||
if(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.*)
|
set(dest \"\${CMAKE_INSTALL_PREFIX}/\${dest}\")
|
||||||
set(skel_prefix \"share/skel/\")
|
endif()
|
||||||
else()
|
|
||||||
set(skel_prefix \"\")
|
set(full_dest \"\$ENV{DESTDIR}\${dest}/${src_name}\")
|
||||||
endif()
|
|
||||||
execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\"
|
if(force_overwrite OR NOT EXISTS \"\${full_dest}\")
|
||||||
\"\${target_dir}/\${skel_prefix}${dest}/${src_name}\"
|
message(STATUS \"Installing: ${src} into \${full_dest}\")
|
||||||
|
|
||||||
|
execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\" \"\${full_dest}\"
|
||||||
RESULT_VARIABLE copy_result
|
RESULT_VARIABLE copy_result
|
||||||
ERROR_VARIABLE error_output)
|
ERROR_VARIABLE error_output)
|
||||||
if(copy_result)
|
if(copy_result)
|
||||||
message(FATAL_ERROR \${error_output})
|
message(FATAL_ERROR \${error_output})
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
message(STATUS \"Skipping : \${target_dir}/${dest}/${src_name}\")
|
message(STATUS \"Skipping : \${full_dest}\")
|
||||||
endif()
|
endif()
|
||||||
")
|
")
|
||||||
endfunction(install_if_not_exists)
|
endfunction(install_if_not_exists)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user