diff options
Diffstat (limited to 'Tests/FindPackageTest')
-rw-r--r-- | Tests/FindPackageTest/CMakeLists.txt | 41 | ||||
-rw-r--r-- | Tests/FindPackageTest/SystemPackage/CMakeTestSystemPackageConfig.cmake | 1 |
2 files changed, 42 insertions, 0 deletions
diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt index d4984d7aaa..9ac9eee0d6 100644 --- a/Tests/FindPackageTest/CMakeLists.txt +++ b/Tests/FindPackageTest/CMakeLists.txt @@ -38,6 +38,38 @@ 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}) diff --git a/Tests/FindPackageTest/SystemPackage/CMakeTestSystemPackageConfig.cmake b/Tests/FindPackageTest/SystemPackage/CMakeTestSystemPackageConfig.cmake new file mode 100644 index 0000000000..deffa57294 --- /dev/null +++ b/Tests/FindPackageTest/SystemPackage/CMakeTestSystemPackageConfig.cmake @@ -0,0 +1 @@ +# Test config file. |