forked from zeek/cmake
-
Notifications
You must be signed in to change notification settings - Fork 13
/
InstallClobberImmune.cmake
31 lines (30 loc) · 1.36 KB
/
InstallClobberImmune.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Determines at `make install` time if a file, typically a configuration
# file placed in $PREFIX/etc, shouldn't be installed to prevent overwrite
# of an existing file.
#
# _srcfile: the file to install
# _dstfile: the absolute file name after installation
macro(InstallClobberImmune _srcfile _dstfile)
install(CODE "
set(_destfile \"${_dstfile}\")
if (NOT \"\$ENV{DESTDIR}\" STREQUAL \"\")
# prepend install root prefix with install-time DESTDIR
set(_destfile \"\$ENV{DESTDIR}/${_dstfile}\")
endif ()
if (EXISTS \${_destfile})
message(STATUS \"Skipping: \${_destfile} (already exists)\")
execute_process(COMMAND \"${CMAKE_COMMAND}\" -E compare_files
${_srcfile} \${_destfile} RESULT_VARIABLE _diff)
if (NOT \"\${_diff}\" STREQUAL \"0\")
message(STATUS \"Installing: \${_destfile}.example\")
configure_file(${_srcfile} \${_destfile}.example COPYONLY)
endif ()
else ()
message(STATUS \"Installing: \${_destfile}\")
# install() is not scriptable within install(), and
# configure_file() is the next best thing
configure_file(${_srcfile} \${_destfile} COPYONLY)
# TODO: create additional install_manifest files?
endif ()
")
endmacro(InstallClobberImmune)