From ca95ad9618076fb0f054544ac5eda9abf9049d7f Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 29 Jul 2011 17:29:17 -0500 Subject: [PATCH] Install example config files dynamically. They'll only get installed when the distribution version differs from existing version on disk. --- cmake/InstallClobberImmune.cmake | 6 ++++++ cmake/InstallPackageConfigFile.cmake | 13 ++++++++----- cmake/package_postupgrade.sh.in | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmake/InstallClobberImmune.cmake b/cmake/InstallClobberImmune.cmake index 77da312ef2..f3da8b88bb 100644 --- a/cmake/InstallClobberImmune.cmake +++ b/cmake/InstallClobberImmune.cmake @@ -9,6 +9,12 @@ macro(InstallClobberImmune _srcfile _dstfile) install(CODE " if (EXISTS ${_dstfile}) message(STATUS \"Skipping: ${_dstfile} (already exists)\") + execute_process(COMMAND \"${CMAKE_COMMAND}\" -E compare_files + ${_srcfile} ${_dstfile} RESULT_VARIABLE _diff) + if (NOT \"\${_diff}\" STREQUAL \"0\") + message(STATUS \"Installing: ${_dstfile}.example\") + configure_file(${_srcfile} ${_dstfile}.example COPY_ONLY) + endif () else () message(STATUS \"Installing: ${_dstfile}\") # install() is not scriptable within install(), and diff --git a/cmake/InstallPackageConfigFile.cmake b/cmake/InstallPackageConfigFile.cmake index 65a1724ea4..5850bb3783 100644 --- a/cmake/InstallPackageConfigFile.cmake +++ b/cmake/InstallPackageConfigFile.cmake @@ -3,7 +3,6 @@ include(InstallClobberImmune) # This macro can be used to install configuration files which # users are expected to modify after installation. It will: # -# - Always install one version of the file with a .example suffix # - If binary packaging is enabled: # Install the file in the typical CMake fashion, but append to the # INSTALLED_CONFIG_FILES cache variable for use with the Mac package's @@ -19,10 +18,6 @@ include(InstallClobberImmune) macro(InstallPackageConfigFile _srcfile _dstdir _dstfilename) set(_dstfile ${_dstdir}/${_dstfilename}) - # Always install the latest version of the file renamed as an example - install(FILES ${_srcfile} DESTINATION ${_dstdir} - RENAME ${_dstfilename}.example) - if (BINARY_PACKAGING_MODE) # If packaging mode is enabled, always install the distribution's # version of the file. The Mac package's pre/post install scripts @@ -32,6 +27,14 @@ macro(InstallPackageConfigFile _srcfile _dstdir _dstfilename) # use to avoid clobbering user-modified config files set(INSTALLED_CONFIG_FILES "${INSTALLED_CONFIG_FILES} ${_dstfile}" CACHE STRING "" FORCE) + + # Additionally, the Mac PackageMaker packages don't have any automatic + # handling of configuration file conflicts so install an example file + # that the post install script will cleanup in the case it's extraneous + if (APPLE) + install(FILES ${_srcfile} DESTINATION ${_dstdir} + RENAME ${_dstfilename}.example) + endif () else () # Have `make install` check at run time whether the file does not exist InstallClobberImmune(${_srcfile} ${_dstfile}) diff --git a/cmake/package_postupgrade.sh.in b/cmake/package_postupgrade.sh.in index 4e199d005c..7d40950fc1 100755 --- a/cmake/package_postupgrade.sh.in +++ b/cmake/package_postupgrade.sh.in @@ -20,8 +20,9 @@ if [ -e ${backupNamesFile} ]; then if [ $? -eq 0 ]; then # if the installed version and the backup version don't differ - # then we can remove the backup version + # then we can remove the backup version and the example file rm ${backupFile} + rm ${origFileName}.example else # The backup file differs from the newly installed version, # since we can't tell if the backup version has been modified