diff options
author | Andreas Schuh <andreas.schuh.84@gmail.com> | 2016-11-24 22:36:48 +0000 |
---|---|---|
committer | Andreas Schuh <andreas.schuh.84@gmail.com> | 2016-11-24 23:30:55 +0000 |
commit | 3886da50e12408d0770fb689c32164ef70f200d6 (patch) | |
tree | 437d0b704a0609e7f21f8797b857840af091ebbb /cmake/utils.cmake | |
parent | 6c0ee003e84fcf7d5c4cb8171b92b0fb9dcc5bf9 (diff) | |
download | gflags-3886da50e12408d0770fb689c32164ef70f200d6.tar.gz gflags-3886da50e12408d0770fb689c32164ef70f200d6.tar.bz2 gflags-3886da50e12408d0770fb689c32164ef70f200d6.zip |
enh: Add option to add installation to CMake’s package registry
Diffstat (limited to 'cmake/utils.cmake')
-rw-r--r-- | cmake/utils.cmake | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 038baf3..c1e3ab9 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -161,3 +161,41 @@ macro (add_gflags_test name expected_rc expected_output unexpected_output cmd) WORKING_DIRECTORY "${GFLAGS_FLAGFILES_DIR}" ) endmacro () + +# ------------------------------------------------------------------------------ +## Register installed package with CMake +# +# This function adds an entry to the CMake registry for packages with the +# path of the directory where the package configuration file of the installed +# package is located in order to help CMake find the package in a custom +# installation prefix. This differs from CMake's export(PACKAGE) command +# which registers the build directory instead. +function (register_gflags_package CONFIG_DIR) + if (NOT IS_ABSOLUTE "${CONFIG_DIR}") + set (CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_DIR}") + endif () + string (MD5 REGISTRY_ENTRY "${CONFIG_DIR}") + if (WIN32) + install (CODE + "execute_process ( + COMMAND reg add \"HKCU\\\\Software\\\\Kitware\\\\CMake\\\\Packages\\\\${PACKAGE_NAME}\" /v \"${REGISTRY_ENTRY}\" /d \"${CONFIG_DIR}\" /t REG_SZ /f + RESULT_VARIABLE RT + ERROR_VARIABLE ERR + OUTPUT_QUIET + ) + if (RT EQUAL 0) + message (STATUS \"Register: Added HKEY_CURRENT_USER\\\\Software\\\\Kitware\\\\CMake\\\\Packages\\\\${PACKAGE_NAME}\\\\${REGISTRY_ENTRY}\") + else () + string (STRIP \"\${ERR}\" ERR) + message (STATUS \"Register: Failed to add registry entry: \${ERR}\") + endif ()" + ) + elseif (IS_DIRECTORY "$ENV{HOME}") + file (WRITE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-registry-entry" "${CONFIG_DIR}") + install ( + FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-registry-entry" + DESTINATION "$ENV{HOME}/.cmake/packages/${PACKAGE_NAME}" + RENAME "${REGISTRY_ENTRY}" + ) + endif () +endfunction () |