diff options
author | Brad King <brad.king@kitware.com> | 2011-04-13 17:17:42 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2011-04-13 17:17:42 (GMT) |
commit | b95f3cac91488f754bfef183e391c1dae03ba406 (patch) | |
tree | f21e5390763220386de0493f3157cb9221296be9 /Source | |
parent | a0d76c10a72fb1cdb551f729bd8c74493543a6c7 (diff) | |
download | CMake-b95f3cac91488f754bfef183e391c1dae03ba406.zip CMake-b95f3cac91488f754bfef183e391c1dae03ba406.tar.gz CMake-b95f3cac91488f754bfef183e391c1dae03ba406.tar.bz2 |
find_package: Check both 32-bit and 64-bit registry views
The system package registry is under HKEY_LOCAL_MACHINE\SOFTWARE which
has separate views for 32-bit and 64-bit applications. Look in both
views, but prefer the architecture matching the build target platform.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 42 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.h | 4 |
2 files changed, 40 insertions, 6 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index daf71d4..b77273c 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -1282,7 +1282,7 @@ void cmFindPackageCommand::AddPrefixesUserRegistry() } #if defined(_WIN32) && !defined(__CYGWIN__) - this->LoadPackageRegistryWin(true); + this->LoadPackageRegistryWinUser(); #elif defined(__HAIKU__) BPath dir; if (find_directory(B_USER_SETTINGS_DIRECTORY, &dir) == B_OK) @@ -1311,22 +1311,54 @@ void cmFindPackageCommand::AddPrefixesSystemRegistry() } #if defined(_WIN32) && !defined(__CYGWIN__) - this->LoadPackageRegistryWin(false); + this->LoadPackageRegistryWinSystem(); #endif } #if defined(_WIN32) && !defined(__CYGWIN__) # include <windows.h> # undef GetCurrentDirectory + // http://msdn.microsoft.com/en-us/library/aa384253%28v=vs.85%29.aspx +# if !defined(KEY_WOW64_32KEY) +# define KEY_WOW64_32KEY 0x0200 +# endif +# if !defined(KEY_WOW64_64KEY) +# define KEY_WOW64_64KEY 0x0100 +# endif //---------------------------------------------------------------------------- -void cmFindPackageCommand::LoadPackageRegistryWin(bool user) +void cmFindPackageCommand::LoadPackageRegistryWinUser() +{ + // HKEY_CURRENT_USER\\Software shares 32-bit and 64-bit views. + this->LoadPackageRegistryWin(true, 0); +} + +//---------------------------------------------------------------------------- +void cmFindPackageCommand::LoadPackageRegistryWinSystem() +{ + // HKEY_LOCAL_MACHINE\\SOFTWARE has separate 32-bit and 64-bit views. + // Prefer the target platform view first. + if(this->Makefile->PlatformIs64Bit()) + { + this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY); + this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY); + } + else + { + this->LoadPackageRegistryWin(false, KEY_WOW64_32KEY); + this->LoadPackageRegistryWin(false, KEY_WOW64_64KEY); + } +} + +//---------------------------------------------------------------------------- +void cmFindPackageCommand::LoadPackageRegistryWin(bool user, + unsigned int view) { std::string key = "Software\\Kitware\\CMake\\Packages\\"; key += this->Name; std::set<cmStdString> bad; HKEY hKey; if(RegOpenKeyEx(user? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, key.c_str(), - 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) + 0, KEY_QUERY_VALUE|view, &hKey) == ERROR_SUCCESS) { DWORD valueType = REG_NONE; char name[16384]; @@ -1365,7 +1397,7 @@ void cmFindPackageCommand::LoadPackageRegistryWin(bool user) // Remove bad values if possible. if(user && !bad.empty() && RegOpenKeyEx(HKEY_CURRENT_USER, key.c_str(), - 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) + 0, KEY_SET_VALUE|view, &hKey) == ERROR_SUCCESS) { for(std::set<cmStdString>::const_iterator vi = bad.begin(); vi != bad.end(); ++vi) diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index fa3fd4f..4229d37 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -95,7 +95,9 @@ private: void AddPrefixesUserHints(); void ComputeFinalPrefixes(); void LoadPackageRegistryDir(std::string const& dir); - void LoadPackageRegistryWin(bool user); + void LoadPackageRegistryWinUser(); + void LoadPackageRegistryWinSystem(); + void LoadPackageRegistryWin(bool user, unsigned int view); bool CheckPackageRegistryEntry(std::istream& is); bool SearchDirectory(std::string const& dir); bool CheckDirectory(std::string const& dir); |