diff options
author | Kyle Edwards <kyedwards@nvidia.com> | 2024-08-02 20:18:44 (GMT) |
---|---|---|
committer | Kyle Edwards <kyedwards@nvidia.com> | 2024-08-02 20:18:44 (GMT) |
commit | f8264cf2ffc3daabffe25365a5e91865d97d147b (patch) | |
tree | 96055e7632a93148205b81512f071d5fc2b1b08e | |
parent | 289c30ad3ab31dbdc5348bf5450344f6ec08ceca (diff) | |
download | CMake-f8264cf2ffc3daabffe25365a5e91865d97d147b.zip CMake-f8264cf2ffc3daabffe25365a5e91865d97d147b.tar.gz CMake-f8264cf2ffc3daabffe25365a5e91865d97d147b.tar.bz2 |
find_package(): Debug re-rooting behavior
find_package()'s debug mode provides information about which
prefixes are searched, but not which roots are prepended to each
prefix. Display this information if debugging is enabled.
-rw-r--r-- | Source/cmFindCommon.cxx | 31 | ||||
-rw-r--r-- | Source/cmFindCommon.h | 6 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 2 | ||||
-rw-r--r-- | Tests/RunCMake/find_package/DebugRoot-stderr.txt | 52 | ||||
-rw-r--r-- | Tests/RunCMake/find_package/DebugRoot.cmake | 15 | ||||
-rw-r--r-- | Tests/RunCMake/find_package/DebugRoot/Exist/DebugRoot/DebugRootConfig.cmake | 1 | ||||
-rw-r--r-- | Tests/RunCMake/find_package/DebugRoot/NoExist/DebugRoot/.empty | 0 | ||||
-rw-r--r-- | Tests/RunCMake/find_package/RunCMakeTest.cmake | 1 |
8 files changed, 102 insertions, 6 deletions
diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index 31cc14b..31243f6 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -212,7 +212,8 @@ void cmFindCommon::SelectDefaultSearchModes() } } -void cmFindCommon::RerootPaths(std::vector<std::string>& paths) +void cmFindCommon::RerootPaths(std::vector<std::string>& paths, + std::string* debugBuffer) { #if 0 for(std::string const& p : paths) @@ -238,17 +239,40 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths) return; } + if (this->DebugMode && debugBuffer) { + *debugBuffer = cmStrCat( + *debugBuffer, "Prepending the following roots to each prefix:\n"); + } + + auto debugRoot = [this, debugBuffer](const std::string& name, + cmValue value) { + if (this->DebugMode && debugBuffer) { + *debugBuffer = cmStrCat(*debugBuffer, name, "\n"); + cmList roots{ value }; + if (roots.empty()) { + *debugBuffer = cmStrCat(*debugBuffer, " none\n"); + } + for (auto const& root : roots) { + *debugBuffer = cmStrCat(*debugBuffer, " ", root, "\n"); + } + } + }; + // Construct the list of path roots with no trailing slashes. cmList roots; + debugRoot("CMAKE_FIND_ROOT_PATH", rootPath); if (rootPath) { roots.assign(*rootPath); } + debugRoot("CMAKE_SYSROOT_COMPILE", sysrootCompile); if (sysrootCompile) { roots.emplace_back(*sysrootCompile); } + debugRoot("CMAKE_SYSROOT_LINK", sysrootLink); if (sysrootLink) { roots.emplace_back(*sysrootLink); } + debugRoot("CMAKE_SYSROOT", sysroot); if (sysroot) { roots.emplace_back(*sysroot); } @@ -411,7 +435,8 @@ static void AddTrailingSlash(std::string& s) s += '/'; } } -void cmFindCommon::ComputeFinalPaths(IgnorePaths ignorePaths) +void cmFindCommon::ComputeFinalPaths(IgnorePaths ignorePaths, + std::string* debugBuffer) { // Filter out ignored paths from the prefix list std::set<std::string> ignoredPaths; @@ -430,7 +455,7 @@ void cmFindCommon::ComputeFinalPaths(IgnorePaths ignorePaths) } // Expand list of paths inside all search roots. - this->RerootPaths(this->SearchPaths); + this->RerootPaths(this->SearchPaths, debugBuffer); // Add a trailing slash to all paths to aid the search process. std::for_each(this->SearchPaths.begin(), this->SearchPaths.end(), diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h index 41de797..1abf567 100644 --- a/Source/cmFindCommon.h +++ b/Source/cmFindCommon.h @@ -81,7 +81,8 @@ protected: void InitializeSearchPathGroups(); /** Place a set of search paths under the search roots. */ - void RerootPaths(std::vector<std::string>& paths); + void RerootPaths(std::vector<std::string>& paths, + std::string* debugBuffer = nullptr); /** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_PATH variables. */ void GetIgnoredPaths(std::vector<std::string>& ignore); @@ -97,7 +98,8 @@ protected: No, Yes, }; - void ComputeFinalPaths(IgnorePaths ignorePaths); + void ComputeFinalPaths(IgnorePaths ignorePaths, + std::string* debugBuffer = nullptr); /** Compute the current default root path mode. */ void SelectDefaultRootPathMode(); diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 344c250..59f5ce2 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -2013,7 +2013,7 @@ void cmFindPackageCommand::ComputePrefixes() } this->FillPrefixesUserGuess(); - this->ComputeFinalPaths(IgnorePaths::No); + this->ComputeFinalPaths(IgnorePaths::No, &this->DebugBuffer); } void cmFindPackageCommand::FillPrefixesPackageRedirect() diff --git a/Tests/RunCMake/find_package/DebugRoot-stderr.txt b/Tests/RunCMake/find_package/DebugRoot-stderr.txt new file mode 100644 index 0000000..00a70c1 --- /dev/null +++ b/Tests/RunCMake/find_package/DebugRoot-stderr.txt @@ -0,0 +1,52 @@ +^CMake Debug Log at DebugRoot\.cmake:[0-9]+ \(find_package\): + The internally managed CMAKE_FIND_PACKAGE_REDIRECTS_DIR\. + + [^ +]*/Tests/RunCMake/find_package/DebugRoot-build/CMakeFiles/pkgRedirects + + Paths specified by the find_package HINTS option\. + + none + + Paths specified by the find_package PATHS option\. + + /DebugRoot + + Prepending the following roots to each prefix: + + CMAKE_FIND_ROOT_PATH + + [^ +]*/Tests/RunCMake/find_package/DebugRoot/NoExist + [^ +]*/Tests/RunCMake/find_package/DebugRoot/Exist + + CMAKE_SYSROOT_COMPILE + + none + + CMAKE_SYSROOT_LINK + + none + + CMAKE_SYSROOT + + none + + find_package considered the following locations for DebugRoot's Config + module: + + [^ +]*/Tests/RunCMake/find_package/DebugRoot/NoExist/DebugRoot/DebugRootConfig\.cmake + [^ +]*/Tests/RunCMake/find_package/DebugRoot/NoExist/DebugRoot/debugroot-config\.cmake + [^ +]*/Tests/RunCMake/find_package/DebugRoot/Exist/DebugRoot/DebugRootConfig\.cmake + + The file was found at + + [^ +]*/Tests/RunCMake/find_package/DebugRoot/Exist/DebugRoot/DebugRootConfig.cmake + +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/find_package/DebugRoot.cmake b/Tests/RunCMake/find_package/DebugRoot.cmake new file mode 100644 index 0000000..2fb7017 --- /dev/null +++ b/Tests/RunCMake/find_package/DebugRoot.cmake @@ -0,0 +1,15 @@ +set(CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_LIST_DIR}/DebugRoot/NoExist ${CMAKE_CURRENT_LIST_DIR}/DebugRoot/Exist) +set(CMAKE_FIND_DEBUG_MODE ON) +find_package(DebugRoot + NO_DEFAULT_PATH + NO_PACKAGE_ROOT_PATH + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_PACKAGE_REGISTRY + NO_CMAKE_SYSTEM_PATH + NO_CMAKE_INSTALL_PREFIX + NO_CMAKE_SYSTEM_PACKAGE_REGISTRY + PATHS /DebugRoot + ) +set(CMAKE_FIND_DEBUG_MODE OFF) diff --git a/Tests/RunCMake/find_package/DebugRoot/Exist/DebugRoot/DebugRootConfig.cmake b/Tests/RunCMake/find_package/DebugRoot/Exist/DebugRoot/DebugRootConfig.cmake new file mode 100644 index 0000000..683b7a6 --- /dev/null +++ b/Tests/RunCMake/find_package/DebugRoot/Exist/DebugRoot/DebugRootConfig.cmake @@ -0,0 +1 @@ +set(DebugRoot_FOUND TRUE) diff --git a/Tests/RunCMake/find_package/DebugRoot/NoExist/DebugRoot/.empty b/Tests/RunCMake/find_package/DebugRoot/NoExist/DebugRoot/.empty new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/find_package/DebugRoot/NoExist/DebugRoot/.empty diff --git a/Tests/RunCMake/find_package/RunCMakeTest.cmake b/Tests/RunCMake/find_package/RunCMakeTest.cmake index 8cda4c1..1995ac4 100644 --- a/Tests/RunCMake/find_package/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_package/RunCMakeTest.cmake @@ -74,6 +74,7 @@ run_cmake(IgnorePrefixPath) run_cmake(REGISTRY_VIEW-no-view) run_cmake(REGISTRY_VIEW-wrong-view) run_cmake(REGISTRY_VIEW-propagated) +run_cmake(DebugRoot) if(CMAKE_HOST_WIN32 AND MINGW) run_cmake(MSYSTEM_PREFIX) |