find_package: Test system package registry when possible
Teach the FindPackagTest to try creating the appropriate HKLM system package registry value. If it works then add a test to verify that find_package() reads it as expected. Then delete the value to cleanup.
This commit is contained in:
parent
b95f3cac91
commit
93021adb73
|
@ -37,6 +37,38 @@ FIND_PACKAGE(VersionTestB 1.2)
|
|||
FIND_PACKAGE(VersionTestC 1.2.3)
|
||||
FIND_PACKAGE(VersionTestD 1.2.3.4)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Test system package registry if possible.
|
||||
SET(CMakeTestSystemPackage "")
|
||||
IF(WIN32 AND NOT CYGWIN)
|
||||
# Try writing a value to the system package registry.
|
||||
FILE(TO_NATIVE_PATH "${FindPackageTest_SOURCE_DIR}/SystemPackage" _data)
|
||||
SET(_key "HKLM\\Software\\Kitware\\CMake\\Packages\\CMakeTestSystemPackage")
|
||||
SET(_file "${FindPackageTest_BINARY_DIR}/CMakeTestSystemPackage.data")
|
||||
FILE(WRITE ${_file} "${_data}\n")
|
||||
EXECUTE_PROCESS(
|
||||
COMMAND ${CMAKE_COMMAND} -E md5sum ${_file}
|
||||
OUTPUT_VARIABLE _output ERROR_VARIABLE _error RESULT_VARIABLE _failed
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
STRING(REGEX REPLACE " .*" "" _value "${_output}")
|
||||
IF(NOT _failed AND _value)
|
||||
EXECUTE_PROCESS(
|
||||
COMMAND reg add "${_key}" /v "${_value}" /t REG_SZ /d "${_data}" /f
|
||||
OUTPUT_VARIABLE _output ERROR_VARIABLE _output RESULT_VARIABLE _failed
|
||||
)
|
||||
ENDIF()
|
||||
# If the above worked, add the rest of the test and a rule to
|
||||
# cleanup the value.
|
||||
IF(NOT _failed)
|
||||
MESSAGE(STATUS "HKLM is writable: enabling CMakeTestSystemPackage")
|
||||
SET(CMakeTestSystemPackage_CLEANUP reg delete "${_key}" /v "${_value}" /f)
|
||||
SET(CMakeTestSystemPackage CMakeTestSystemPackage)
|
||||
ELSE()
|
||||
MESSAGE(STATUS "HKLM is readonly: disabling CMakeTestSystemPackage")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
#SET(CMAKE_FIND_DEBUG_MODE 1)
|
||||
|
@ -49,6 +81,7 @@ SET(PACKAGES
|
|||
wibbleA wibbleB
|
||||
RecursiveA RecursiveB RecursiveC
|
||||
EnvA EnvB
|
||||
${CMakeTestSystemPackage}
|
||||
)
|
||||
FOREACH(p ${PACKAGES})
|
||||
SET(${p}_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
|
||||
|
@ -116,6 +149,13 @@ SET(ENV{EnvA_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/lib/zot-3.1")
|
|||
FIND_PACKAGE(EnvA 3.1 EXACT QUIET NAMES zot) # Should Work
|
||||
FIND_PACKAGE(EnvB 3.1 EXACT QUIET NAMES zot) # Should Fail
|
||||
|
||||
# Test system package registry if available.
|
||||
IF(CMakeTestSystemPackage)
|
||||
FIND_PACKAGE(CMakeTestSystemPackage)
|
||||
EXECUTE_PROCESS(COMMAND ${CMakeTestSystemPackage_CLEANUP}
|
||||
OUTPUT_VARIABLE _output ERROR_VARIABLE _error)
|
||||
ENDIF()
|
||||
|
||||
# Expected locations at which packages should be found.
|
||||
SET(foo_EXPECTED "lib/foo-1.2/foo-config.cmake")
|
||||
SET(Foo_EXPECTED "lib/foo-1.2/CMake/FooConfig.cmake")
|
||||
|
@ -145,6 +185,7 @@ SET(RecursiveB_EXPECTED "lib/zot-2.0/zot-config.cmake")
|
|||
SET(RecursiveC_EXPECTED "lib/zot-3.1/zot-config.cmake")
|
||||
SET(EnvA_EXPECTED "lib/zot-3.1/zot-config.cmake")
|
||||
SET(EnvB_MISSING "EnvB_DIR-NOTFOUND")
|
||||
SET(CMakeTestSystemPackage_EXPECTED "SystemPackage/CMakeTestSystemPackageConfig.cmake")
|
||||
|
||||
# Check the results.
|
||||
FOREACH(p ${PACKAGES})
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
# Test config file.
|
Loading…
Reference in New Issue