diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFindLibraryCommand.cxx | 68 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 133 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.h | 1 | ||||
-rw-r--r-- | Source/cmFindPathCommand.cxx | 17 | ||||
-rw-r--r-- | Source/cmFindPathCommand.h | 4 | ||||
-rw-r--r-- | Source/cmFindProgramCommand.cxx | 19 |
6 files changed, 211 insertions, 31 deletions
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 20221b1..d5a4bde 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -29,6 +29,7 @@ cmFindLibraryCommand::cmFindLibraryCommand(cmExecutionStatus& status) // cmFindLibraryCommand bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn) { + this->DebugMode = ComputeIfDebugModeWanted(); this->VariableDocumentation = "Path to a library."; this->CMakePathName = "LIBRARY"; if (!this->ParseArguments(argsIn)) { @@ -92,6 +93,13 @@ void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix) original.swap(this->SearchPaths); for (std::string const& o : original) { this->AddArchitecturePath(o, 0, suffix); + if (this->DebugMode) { + std::string msg = cmStrCat( + "find_library(", this->VariableName, ") removed original suffix ", o, + " from PATH_SUFFIXES while adding architecture paths for suffix '", + suffix, "'"); + this->DebugMessage(msg); + } } } @@ -153,11 +161,23 @@ void cmFindLibraryCommand::AddArchitecturePath( if (use_dirX) { dirX += "/"; + if (this->DebugMode) { + std::string msg = cmStrCat( + "find_library(", this->VariableName, ") added replacement path ", + dirX, " to PATH_SUFFIXES for architecture suffix '", suffix, "'"); + this->DebugMessage(msg); + } this->SearchPaths.push_back(std::move(dirX)); } if (use_dir) { this->SearchPaths.push_back(dir); + if (this->DebugMode) { + std::string msg = cmStrCat( + "find_library(", this->VariableName, ") added replacement path ", + dir, " to PATH_SUFFIXES for architecture suffix '", suffix, "'"); + this->DebugMessage(msg); + } } } } @@ -179,7 +199,7 @@ std::string cmFindLibraryCommand::FindLibrary() struct cmFindLibraryHelper { - cmFindLibraryHelper(cmMakefile* mf); + cmFindLibraryHelper(cmMakefile* mf, cmFindBase const* findBase); // Context information. cmMakefile* Makefile; @@ -198,6 +218,8 @@ struct cmFindLibraryHelper // Support for OpenBSD shared library naming: lib<name>.so.<major>.<minor> bool OpenBSD; + bool DebugMode; + // Current names under consideration. struct Name { @@ -227,10 +249,33 @@ struct cmFindLibraryHelper void SetName(std::string const& name); bool CheckDirectory(std::string const& path); bool CheckDirectoryForName(std::string const& path, Name& name); + + cmFindBaseDebugState DebugSearches; + + void DebugLibraryFailed(std::string const& name, std::string const& path) + { + if (this->DebugMode) { + auto regexName = + cmStrCat(this->PrefixRegexStr, name, this->SuffixRegexStr); + this->DebugSearches.FailedAt(path, regexName); + } + }; + + void DebugLibraryFound(std::string const& name, std::string const& path) + { + if (this->DebugMode) { + auto regexName = + cmStrCat(this->PrefixRegexStr, name, this->SuffixRegexStr); + this->DebugSearches.FoundAt(path, regexName); + } + }; }; -cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf) +cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf, + cmFindBase const* base) : Makefile(mf) + , DebugMode(base->DebugModeEnabled()) + , DebugSearches("find_library", base) { this->GG = this->Makefile->GetGlobalGenerator(); @@ -350,7 +395,12 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, // library or an import library). if (name.TryRaw) { this->TestPath = cmStrCat(path, name.Raw); - if (cmSystemTools::FileExists(this->TestPath, true)) { + + const bool exists = cmSystemTools::FileExists(this->TestPath, true); + if (!exists) { + this->DebugLibraryFailed(name.Raw, path); + } else { + this->DebugLibraryFound(name.Raw, path); this->BestPath = cmSystemTools::CollapseFullPath(this->TestPath); cmSystemTools::ConvertToUnixSlashes(this->BestPath); return true; @@ -376,6 +426,8 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, if (name.Regex.find(testName)) { this->TestPath = cmStrCat(path, origName); if (!cmSystemTools::FileIsDirectory(this->TestPath)) { + this->DebugLibraryFound(name.Raw, dir); + // This is a matching file. Check if it is better than the // best name found so far. Earlier prefixes are preferred, // followed by earlier suffixes. For OpenBSD, shared library @@ -402,6 +454,12 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path, } } + if (this->BestPath.empty()) { + this->DebugLibraryFailed(name.Raw, dir); + } else { + this->DebugLibraryFound(name.Raw, this->BestPath); + } + // Use the best candidate found in this directory, if any. return !this->BestPath.empty(); } @@ -417,7 +475,7 @@ std::string cmFindLibraryCommand::FindNormalLibrary() std::string cmFindLibraryCommand::FindNormalLibraryNamesPerDir() { // Search for all names in each directory. - cmFindLibraryHelper helper(this->Makefile); + cmFindLibraryHelper helper(this->Makefile, this); for (std::string const& n : this->Names) { helper.AddName(n); } @@ -434,7 +492,7 @@ std::string cmFindLibraryCommand::FindNormalLibraryNamesPerDir() std::string cmFindLibraryCommand::FindNormalLibraryDirsPerName() { // Search the entire path for each name. - cmFindLibraryHelper helper(this->Makefile); + cmFindLibraryHelper helper(this->Makefile, this); for (std::string const& n : this->Names) { // Switch to searching for this name. helper.SetName(n); diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 2b11b62..9eb256b 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -160,8 +160,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args) this->RequiredCMakeVersion = CMake_VERSION_ENCODE(v[0], v[1], v[2]); } - // Check for debug mode. - this->DebugMode = this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE"); + this->DebugMode = ComputeIfDebugModeWanted(); // Lookup target architecture, if any. if (const char* arch = @@ -695,8 +694,23 @@ void cmFindPackageCommand::RestoreFindDefinitions() bool cmFindPackageCommand::FindModule(bool& found) { std::string module = cmStrCat("Find", this->Name, ".cmake"); + bool system = false; - std::string mfile = this->Makefile->GetModulesFile(module, system); + std::string debugBuffer = + cmStrCat("find_package considered the following paths for ", this->Name, + ".cmake\n"); + std::string mfile = this->Makefile->GetModulesFile( + module, system, this->DebugMode, debugBuffer); + if (this->DebugMode) { + if (mfile.empty()) { + debugBuffer = cmStrCat(debugBuffer, "The file was not found."); + } else { + debugBuffer = + cmStrCat(debugBuffer, "The file was found at\n ", mfile, "\n"); + } + this->DebugMessage(debugBuffer); + } + if (!mfile.empty()) { if (system) { auto it = this->DeprecatedFindModules.find(this->Name); @@ -1164,6 +1178,21 @@ void cmFindPackageCommand::AppendSuccessInformation() this->Makefile->FindPackageRootPathStack.pop_back(); } +inline std::size_t collectPathsForDebug(std::string& buffer, + cmSearchPath const& searchPath, + std::size_t startIndex = 0) +{ + const auto& paths = searchPath.GetPaths(); + if (paths.empty()) { + buffer += " none"; + return 0; + } + for (std::size_t i = startIndex; i < paths.size(); i++) { + buffer += " " + paths[i] + "\n"; + } + return paths.size(); +} + void cmFindPackageCommand::ComputePrefixes() { if (!this->NoDefaultPath) { @@ -1177,7 +1206,9 @@ void cmFindPackageCommand::ComputePrefixes() this->FillPrefixesCMakeEnvironment(); } } + this->FillPrefixesUserHints(); + if (!this->NoDefaultPath) { if (!this->NoSystemEnvironmentPath) { this->FillPrefixesSystemEnvironment(); @@ -1209,29 +1240,72 @@ void cmFindPackageCommand::FillPrefixesPackageRoot() paths.AddPath(path); } } + if (this->DebugMode) { + std::string debugBuffer = "<PackageName>_ROOT CMake variable " + "[CMAKE_FIND_USE_PACKAGE_ROOT_PATH].\n"; + collectPathsForDebug(debugBuffer, paths); + this->DebugMessage(debugBuffer); + } } void cmFindPackageCommand::FillPrefixesCMakeEnvironment() { cmSearchPath& paths = this->LabeledPaths[PathLabel::CMakeEnvironment]; + std::string debugBuffer; + std::size_t debugOffset = 0; // Check the environment variable with the same name as the cache // entry. paths.AddEnvPath(this->Variable); + if (this->DebugMode) { + debugBuffer = cmStrCat("Env variable ", this->Variable, + " [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n"); + debugOffset = collectPathsForDebug(debugBuffer, paths); + } // And now the general CMake environment variables paths.AddEnvPath("CMAKE_PREFIX_PATH"); + if (this->DebugMode) { + debugBuffer = cmStrCat(debugBuffer, + "\nCMAKE_PREFIX_PATH env variable " + "[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n"); + debugOffset = collectPathsForDebug(debugBuffer, paths, debugOffset); + } + paths.AddEnvPath("CMAKE_FRAMEWORK_PATH"); paths.AddEnvPath("CMAKE_APPBUNDLE_PATH"); + if (this->DebugMode) { + debugBuffer = + cmStrCat(debugBuffer, + "\nCMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env " + "variables [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n"); + collectPathsForDebug(debugBuffer, paths, debugOffset); + this->DebugMessage(debugBuffer); + } } void cmFindPackageCommand::FillPrefixesCMakeVariable() { cmSearchPath& paths = this->LabeledPaths[PathLabel::CMake]; + std::string debugBuffer; + std::size_t debugOffset = 0; paths.AddCMakePath("CMAKE_PREFIX_PATH"); + if (this->DebugMode) { + debugBuffer = "CMAKE_PREFIX_PATH variable [CMAKE_FIND_USE_CMAKE_PATH].\n"; + debugOffset = collectPathsForDebug(debugBuffer, paths); + } + paths.AddCMakePath("CMAKE_FRAMEWORK_PATH"); paths.AddCMakePath("CMAKE_APPBUNDLE_PATH"); + if (this->DebugMode) { + debugBuffer = + cmStrCat(debugBuffer, + "\nCMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables " + "[CMAKE_FIND_USE_CMAKE_PATH].\n"); + collectPathsForDebug(debugBuffer, paths, debugOffset); + this->DebugMessage(debugBuffer); + } } void cmFindPackageCommand::FillPrefixesSystemEnvironment() @@ -1251,6 +1325,12 @@ void cmFindPackageCommand::FillPrefixesSystemEnvironment() paths.AddPath(i); } } + if (this->DebugMode) { + std::string debugBuffer = "Standard system environment variables " + "[CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH].\n"; + collectPathsForDebug(debugBuffer, paths); + this->DebugMessage(debugBuffer); + } } void cmFindPackageCommand::FillPrefixesUserRegistry() @@ -1274,6 +1354,13 @@ void cmFindPackageCommand::FillPrefixesUserRegistry() this->LabeledPaths[PathLabel::UserRegistry]); } #endif + if (this->DebugMode) { + std::string debugBuffer = + "CMake User Package Registry [CMAKE_FIND_USE_PACKAGE_REGISTRY].\n"; + collectPathsForDebug(debugBuffer, + this->LabeledPaths[PathLabel::UserRegistry]); + this->DebugMessage(debugBuffer); + } } void cmFindPackageCommand::FillPrefixesSystemRegistry() @@ -1285,6 +1372,15 @@ void cmFindPackageCommand::FillPrefixesSystemRegistry() #if defined(_WIN32) && !defined(__CYGWIN__) this->LoadPackageRegistryWinSystem(); #endif + + if (this->DebugMode) { + std::string debugBuffer = + "CMake System Package Registry " + "[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY].\n"; + collectPathsForDebug(debugBuffer, + this->LabeledPaths[PathLabel::SystemRegistry]); + this->DebugMessage(debugBuffer); + } } #if defined(_WIN32) && !defined(__CYGWIN__) @@ -1457,6 +1553,13 @@ void cmFindPackageCommand::FillPrefixesCMakeSystemVariable() paths.AddCMakePath("CMAKE_SYSTEM_PREFIX_PATH"); paths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH"); paths.AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH"); + + if (this->DebugMode) { + std::string debugBuffer = "CMake variables defined in the Platform file " + "[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH].\n"; + collectPathsForDebug(debugBuffer, paths); + this->DebugMessage(debugBuffer); + } } void cmFindPackageCommand::FillPrefixesUserGuess() @@ -1466,6 +1569,12 @@ void cmFindPackageCommand::FillPrefixesUserGuess() for (std::string const& p : this->UserGuessArgs) { paths.AddUserPath(p); } + if (this->DebugMode) { + std::string debugBuffer = + "Paths specified by the find_package PATHS option.\n"; + collectPathsForDebug(debugBuffer, paths); + this->DebugMessage(debugBuffer); + } } void cmFindPackageCommand::FillPrefixesUserHints() @@ -1475,6 +1584,12 @@ void cmFindPackageCommand::FillPrefixesUserHints() for (std::string const& p : this->UserHintsArgs) { paths.AddUserPath(p); } + if (this->DebugMode) { + std::string debugBuffer = + "Paths specified by the find_package HINTS option.\n"; + collectPathsForDebug(debugBuffer, paths); + this->DebugMessage(debugBuffer); + } } bool cmFindPackageCommand::SearchDirectory(std::string const& dir) @@ -1519,7 +1634,8 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir, for (std::string const& c : this->Configs) { file = cmStrCat(dir, '/', c); if (this->DebugMode) { - fprintf(stderr, "Checking file [%s]\n", file.c_str()); + std::string msg = "Checking file [" + file + "]\n"; + this->DebugMessage(msg); } if (cmSystemTools::FileExists(file, true) && this->CheckVersion(file)) { // Allow resolving symlinks when the config file is found through a link @@ -2032,9 +2148,6 @@ private: bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) { assert(!prefix_in.empty() && prefix_in.back() == '/'); - if (this->DebugMode) { - fprintf(stderr, "Checking prefix [%s]\n", prefix_in.c_str()); - } // Skip this if the prefix does not exist. if (!cmSystemTools::FileIsDirectory(prefix_in)) { @@ -2188,9 +2301,6 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in) bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in) { assert(!prefix_in.empty() && prefix_in.back() == '/'); - if (this->DebugMode) { - fprintf(stderr, "Checking framework prefix [%s]\n", prefix_in.c_str()); - } // Strip the trailing slash because the path generator is about to // add one. @@ -2249,9 +2359,6 @@ bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in) bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in) { assert(!prefix_in.empty() && prefix_in.back() == '/'); - if (this->DebugMode) { - fprintf(stderr, "Checking bundle prefix [%s]\n", prefix_in.c_str()); - } // Strip the trailing slash because the path generator is about to // add one. diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 85fe7b6..a65a292 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -174,7 +174,6 @@ private: bool UseFindModules; bool NoUserRegistry; bool NoSystemRegistry; - bool DebugMode; bool UseLib32Paths; bool UseLib64Paths; bool UseLibx32Paths; diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx index f5e2631..908f0c1 100644 --- a/Source/cmFindPathCommand.cxx +++ b/Source/cmFindPathCommand.cxx @@ -21,6 +21,7 @@ cmFindPathCommand::cmFindPathCommand(cmExecutionStatus& status) // cmFindPathCommand bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn) { + this->DebugMode = ComputeIfDebugModeWanted(); this->VariableDocumentation = "Path to a file."; this->CMakePathName = "INCLUDE"; if (!this->ParseArguments(argsIn)) { @@ -55,16 +56,19 @@ bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn) std::string cmFindPathCommand::FindHeader() { + std::string debug_name = this->IncludeFileInPath ? "find_file" : "find_path"; + cmFindBaseDebugState debug(debug_name, this); std::string header; if (this->SearchFrameworkFirst || this->SearchFrameworkOnly) { - header = this->FindFrameworkHeader(); + header = this->FindFrameworkHeader(debug); } if (header.empty() && !this->SearchFrameworkOnly) { - header = this->FindNormalHeader(); + header = this->FindNormalHeader(debug); } if (header.empty() && this->SearchFrameworkLast) { - header = this->FindFrameworkHeader(); + header = this->FindFrameworkHeader(debug); } + return header; } @@ -116,28 +120,31 @@ std::string cmFindPathCommand::FindHeaderInFramework(std::string const& file, return ""; } -std::string cmFindPathCommand::FindNormalHeader() +std::string cmFindPathCommand::FindNormalHeader(cmFindBaseDebugState& debug) { std::string tryPath; for (std::string const& n : this->Names) { for (std::string const& sp : this->SearchPaths) { tryPath = cmStrCat(sp, n); if (cmSystemTools::FileExists(tryPath)) { + debug.FoundAt(tryPath); if (this->IncludeFileInPath) { return tryPath; } return sp; } + debug.FailedAt(tryPath); } } return ""; } -std::string cmFindPathCommand::FindFrameworkHeader() +std::string cmFindPathCommand::FindFrameworkHeader(cmFindBaseDebugState& debug) { for (std::string const& n : this->Names) { for (std::string const& sp : this->SearchPaths) { std::string fwPath = this->FindHeaderInFramework(n, sp); + fwPath.empty() ? debug.FailedAt(fwPath) : debug.FoundAt(fwPath); if (!fwPath.empty()) { return fwPath; } diff --git a/Source/cmFindPathCommand.h b/Source/cmFindPathCommand.h index 8d1ea8b..18bfb7d 100644 --- a/Source/cmFindPathCommand.h +++ b/Source/cmFindPathCommand.h @@ -32,8 +32,8 @@ private: std::string FindHeaderInFramework(std::string const& file, std::string const& dir); std::string FindHeader(); - std::string FindNormalHeader(); - std::string FindFrameworkHeader(); + std::string FindNormalHeader(cmFindBaseDebugState& debug); + std::string FindFrameworkHeader(cmFindBaseDebugState& debug); }; bool cmFindPath(std::vector<std::string> const& args, diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index e0a3fbf..3e49172 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -15,7 +15,9 @@ class cmExecutionStatus; struct cmFindProgramHelper { - cmFindProgramHelper() + cmFindProgramHelper(cmMakefile* makefile, cmFindBase const* base) + : DebugSearches("find_program", base) + , Makefile(makefile) { #if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) // Consider platform-specific extensions. @@ -41,6 +43,10 @@ struct cmFindProgramHelper // Current full path under consideration. std::string TestPath; + // Debug state + cmFindBaseDebugState DebugSearches; + cmMakefile* Makefile; + void AddName(std::string const& name) { this->Names.push_back(name); } void SetName(std::string const& name) { @@ -78,8 +84,10 @@ struct cmFindProgramHelper this->TestNameExt = cmStrCat(name, ext); this->TestPath = cmSystemTools::CollapseFullPath(this->TestNameExt, path); - - if (cmSystemTools::FileExists(this->TestPath, true)) { + bool exists = cmSystemTools::FileExists(this->TestPath, true); + exists ? this->DebugSearches.FoundAt(this->TestPath) + : this->DebugSearches.FailedAt(this->TestPath); + if (exists) { this->BestPath = this->TestPath; return true; } @@ -97,6 +105,7 @@ cmFindProgramCommand::cmFindProgramCommand(cmExecutionStatus& status) // cmFindProgramCommand bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn) { + this->DebugMode = ComputeIfDebugModeWanted(); this->VariableDocumentation = "Path to a program."; this->CMakePathName = "PROGRAM"; // call cmFindBase::ParseArguments @@ -158,7 +167,7 @@ std::string cmFindProgramCommand::FindNormalProgram() std::string cmFindProgramCommand::FindNormalProgramNamesPerDir() { // Search for all names in each directory. - cmFindProgramHelper helper; + cmFindProgramHelper helper(this->Makefile, this); for (std::string const& n : this->Names) { helper.AddName(n); } @@ -181,7 +190,7 @@ std::string cmFindProgramCommand::FindNormalProgramNamesPerDir() std::string cmFindProgramCommand::FindNormalProgramDirsPerName() { // Search the entire path for each name. - cmFindProgramHelper helper; + cmFindProgramHelper helper(this->Makefile, this); for (std::string const& n : this->Names) { // Switch to searching for this name. helper.SetName(n); |