diff --git a/Help/manual/cmake-configure-log.7.rst b/Help/manual/cmake-configure-log.7.rst index f87940693a..c2b997d96a 100644 --- a/Help/manual/cmake-configure-log.7.rst +++ b/Help/manual/cmake-configure-log.7.rst @@ -442,6 +442,20 @@ The keys specific to ``find-v1`` mappings are: Either a string representing the found value or ``false`` if it was not found. +``search_context`` + A mapping of variable names to search paths specified by them (either a + string or an array of strings depending on the variable). Environment + variables are wrapped with ``ENV{`` and ``}``, otherwise CMake variables are + used. Only variables with any paths specified are used. + + ``package_stack`` + An array of objects with paths which come from the stack of paths made + available by :command:`find_package` calls. + + ``package_paths`` + The paths made available by :command:`find_package` commands in the call + stack. + .. _`find_package configure-log event`: Event Kind ``find_package`` @@ -681,3 +695,17 @@ The keys specific to ``find_package-v1`` mappings are: ``version`` The reported version of the package. + +``search_context`` + A mapping of variable names to search paths specified by them (either a + string or an array of strings depending on the variable). Environment + variables are wrapped with ``ENV{`` and ``}``, otherwise CMake variables are + used. Only variables with any paths specified are used. + + ``package_stack`` + An array of objects with paths which come from the stack of paths made + available by :command:`find_package` calls. + + ``package_paths`` + The paths made available by :command:`find_package` commands in the call + stack. diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index 949d2aab91..66c0c41b41 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -778,6 +778,21 @@ void cmFindBaseDebugState::WriteEvent(cmConfigureLog& log, } else { log.WriteValue("found"_s, false); } + + this->WriteSearchVariables(log, mf); + log.EndEvent(); } + +std::vector> +cmFindBaseDebugState::ExtraSearchVariables() const +{ + std::vector> + extraSearches; + if (!this->FindBaseCommand->EnvironmentPath.empty()) { + extraSearches.emplace_back(VariableSource::EnvironmentList, + this->FindBaseCommand->EnvironmentPath); + } + return extraSearches; +} #endif diff --git a/Source/cmFindBase.h b/Source/cmFindBase.h index 73f4a84a64..0be2d73dd0 100644 --- a/Source/cmFindBase.h +++ b/Source/cmFindBase.h @@ -117,6 +117,8 @@ private: void WriteDebug() const override; #ifndef CMAKE_BOOTSTRAP void WriteEvent(cmConfigureLog& log, cmMakefile const& mf) const override; + std::vector> ExtraSearchVariables() + const override; #endif cmFindBase const* const FindBaseCommand; diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index 337fb19711..1b70bb8611 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -18,6 +18,18 @@ #include "cmValue.h" #include "cmake.h" +#ifndef CMAKE_BOOTSTRAP +# include +# include + +# include +# include +# include + +# include "cmConfigureLog.h" +# include "cmRange.h" +#endif + cmFindCommon::PathGroup cmFindCommon::PathGroup::All("ALL"); cmFindCommon::PathLabel cmFindCommon::PathLabel::PackageRoot( "PackageName_ROOT"); @@ -514,6 +526,114 @@ void cmFindCommonDebugState::Write() this->WriteDebug(); } +#ifndef CMAKE_BOOTSTRAP +void cmFindCommonDebugState::WriteSearchVariables(cmConfigureLog& log, + cmMakefile const& mf) const +{ + auto WriteString = [&log, &mf](std::string const& name) { + if (cmValue value = mf.GetDefinition(name)) { + log.WriteValue(name, *value); + } + }; + auto WriteCMakeList = [&log, &mf](std::string const& name) { + if (cmValue value = mf.GetDefinition(name)) { + cmList values{ *value }; + if (!values.empty()) { + log.WriteValue(name, values); + } + } + }; + auto WriteEnvList = [&log](std::string const& name) { + if (auto value = cmSystemTools::GetEnvVar(name)) { + auto values = cmSystemTools::SplitEnvPath(*value); + if (!values.empty()) { + log.WriteValue(cmStrCat("ENV{", name, '}'), values); + } + } + }; + + auto const* fc = this->FindCommand; + log.BeginObject("search_context"_s); + auto const& packageRootStack = mf.FindPackageRootPathStack; + if (!packageRootStack.empty()) { + bool havePaths = + std::any_of(packageRootStack.begin(), packageRootStack.end(), + [](std::vector const& entry) -> bool { + return !entry.empty(); + }); + if (havePaths) { + log.BeginObject("package_stack"); + log.BeginArray(); + for (auto const& pkgPaths : cmReverseRange(packageRootStack)) { + if (!pkgPaths.empty()) { + log.NextArrayElement(); + log.WriteValue("package_paths", pkgPaths); + } + } + log.EndArray(); + log.EndObject(); + } + } + auto cmakePathVar = cmStrCat("CMAKE_", fc->CMakePathName, "_PATH"); + WriteCMakeList(cmakePathVar); + WriteCMakeList("CMAKE_PREFIX_PATH"); + if (fc->CMakePathName == "PROGRAM"_s) { + WriteCMakeList("CMAKE_APPBUNDLE_PATH"); + } else { + WriteCMakeList("CMAKE_FRAMEWORK_PATH"); + } + // Same as above, but ask the environment instead. + WriteEnvList(cmakePathVar); + WriteEnvList("CMAKE_PREFIX_PATH"); + if (fc->CMakePathName == "PROGRAM"_s) { + WriteEnvList("CMAKE_APPBUNDLE_PATH"); + } else { + WriteEnvList("CMAKE_FRAMEWORK_PATH"); + } + WriteEnvList("PATH"); + WriteString("CMAKE_INSTALL_PREFIX"); + WriteString("CMAKE_STAGING_PREFIX"); + WriteCMakeList("CMAKE_SYSTEM_PREFIX_PATH"); + auto systemPathVar = cmStrCat("CMAKE_SYSTEM_", fc->CMakePathName, "_PATH"); + WriteCMakeList(systemPathVar); + // Sysroot paths. + WriteString("CMAKE_SYSROOT"); + WriteString("CMAKE_SYSROOT_COMPILE"); + WriteString("CMAKE_SYSROOT_LINK"); + WriteString("CMAKE_FIND_ROOT_PATH"); + // Write out paths which are ignored. + WriteCMakeList("CMAKE_IGNORE_PATH"); + WriteCMakeList("CMAKE_IGNORE_PREFIX_PATH"); + WriteCMakeList("CMAKE_SYSTEM_IGNORE_PATH"); + WriteCMakeList("CMAKE_SYSTEM_IGNORE_PREFIX_PATH"); + if (fc->CMakePathName == "PROGRAM"_s) { + WriteCMakeList("CMAKE_SYSTEM_APPBUNDLE_PATH"); + } else { + WriteCMakeList("CMAKE_SYSTEM_FRAMEWORK_PATH"); + } + for (auto const& extraVar : this->ExtraSearchVariables()) { + switch (extraVar.first) { + case VariableSource::String: + WriteString(extraVar.second); + break; + case VariableSource::PathList: + WriteCMakeList(extraVar.second); + break; + case VariableSource::EnvironmentList: + WriteEnvList(extraVar.second); + break; + } + } + log.EndObject(); +} + +std::vector> +cmFindCommonDebugState::ExtraSearchVariables() const +{ + return {}; +} +#endif + bool cmFindCommonDebugState::TrackSearchProgress() const { // Track search progress if debugging or logging the configure. diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h index 22bc40742e..35467726e0 100644 --- a/Source/cmFindCommon.h +++ b/Source/cmFindCommon.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "cmPathLabel.h" @@ -187,6 +188,15 @@ protected: virtual void WriteDebug() const = 0; #ifndef CMAKE_BOOTSTRAP virtual void WriteEvent(cmConfigureLog& log, cmMakefile const& mf) const = 0; + void WriteSearchVariables(cmConfigureLog& log, cmMakefile const& mf) const; + enum class VariableSource + { + String, + PathList, + EnvironmentList, + }; + virtual std::vector> + ExtraSearchVariables() const; #endif cmFindCommon const* const FindCommand; diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index a2a71bd9e2..7f1bc814ce 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -3668,6 +3668,19 @@ void cmFindPackageDebugState::WriteEvent(cmConfigureLog& log, log.WriteValue("found"_s, nullptr); } + this->WriteSearchVariables(log, mf); + log.EndEvent(); } + +std::vector> +cmFindPackageDebugState::ExtraSearchVariables() const +{ + std::vector> + extraSearches; + if (this->FindPackageCommand->UseFindModules) { + extraSearches.emplace_back(VariableSource::PathList, "CMAKE_MODULE_PATH"); + } + return extraSearches; +} #endif diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index bbbcdd41f8..a8eb5a2639 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -399,6 +399,8 @@ private: void WriteDebug() const override; #ifndef CMAKE_BOOTSTRAP void WriteEvent(cmConfigureLog& log, cmMakefile const& mf) const override; + std::vector> ExtraSearchVariables() + const override; #endif cmFindPackageCommand const* const FindPackageCommand; diff --git a/Tests/RunCMake/find_package/ConfigureLog-config.txt b/Tests/RunCMake/find_package/ConfigureLog-config.txt index 59c50ba762..93181c3817 100644 --- a/Tests/RunCMake/find_package/ConfigureLog-config.txt +++ b/Tests/RunCMake/find_package/ConfigureLog-config.txt @@ -71,6 +71,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/lib/cmake/ViaConfig/ViaConfigConfig.cmake" mode: "config" version: "1\.0" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -100,6 +103,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/cmake/FindViaModule.cmake" mode: "module" version: "1.0" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -163,6 +169,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/lib/cmake/Inner/InnerConfig.cmake" mode: "config" version: "1.1" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -192,6 +201,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/cmake/FindWithInner.cmake" mode: "module" version: "1.1" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -265,4 +277,7 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/lib/cmake/VersionCheck-2.5/VersionCheckConfig.cmake" mode: "config" version: "2.5" + search_context:( + [^ +]*)+ \.\.\.$ diff --git a/Tests/RunCMake/find_package/ConfigureLogParameters1-config.txt b/Tests/RunCMake/find_package/ConfigureLogParameters1-config.txt index 44a285f837..0970fa1c5b 100644 --- a/Tests/RunCMake/find_package/ConfigureLogParameters1-config.txt +++ b/Tests/RunCMake/find_package/ConfigureLogParameters1-config.txt @@ -42,6 +42,9 @@ events: reason: "not_found" message: "Not an EXACT version match" found: null + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -75,6 +78,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/cmake/FindParameterCheck.cmake" mode: "module" version: "1.2" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -106,6 +112,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/cmake/FindParameterCheck.cmake" mode: "module" version: "1.2" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -135,6 +144,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/cmake/FindParameterCheck.cmake" mode: "module" version: "1.2" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -164,6 +176,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/cmake/FindParameterCheck.cmake" mode: "module" version: "1.2" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -202,6 +217,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/cmake/FindParameterCheck.cmake" mode: "module" version: "1.2" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -232,6 +250,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/cmake/FindParameterCheck.cmake" mode: "module" version: "1.2" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -261,6 +282,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/cmake/FindParameterCheck.cmake" mode: "module" version: "1.2" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -290,6 +314,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/cmake/FindParameterCheck.cmake" mode: "module" version: "1.2" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -319,4 +346,7 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/cmake/FindParameterCheck.cmake" mode: "module" version: "1.2" + search_context:( + [^ +]*)+ \.\.\.$ diff --git a/Tests/RunCMake/find_package/ConfigureLogParameters2-config.txt b/Tests/RunCMake/find_package/ConfigureLogParameters2-config.txt index 989d83a22b..c371ad417a 100644 --- a/Tests/RunCMake/find_package/ConfigureLogParameters2-config.txt +++ b/Tests/RunCMake/find_package/ConfigureLogParameters2-config.txt @@ -73,6 +73,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/lib/cmake/ParameterCheckConfig/ParameterCheckConfigConfig.cmake" mode: "config" version: "1.6" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -186,6 +189,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/lib/cmake/ParameterCheckConfig/ParameterCheckConfigConfig.cmake" mode: "config" version: "1.6" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -230,6 +236,9 @@ events: mode: "config" reason: "no_exist" found: null + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -293,6 +302,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/lib/cmake/ParameterCheckConfig/ParameterCheckConfigConfig.cmake" mode: "config" version: "1.6" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -356,6 +368,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/lib/cmake/ParameterCheckConfig/ParameterCheckConfigConfig.cmake" mode: "config" version: "1.6" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -419,6 +434,9 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/lib/cmake/ParameterCheckConfig/ParameterCheckConfigConfig.cmake" mode: "config" version: "1.6" + search_context:( + [^ +]*)+ - kind: "find_package-v1" backtrace:( @@ -521,4 +539,7 @@ events: path: ".*/Tests/RunCMake/find_package/ConfigureLog/lib/cmake/ParameterCheckConfig/ParameterCheckConfigConfig.cmake" mode: "config" version: "1.6" + search_context:( + [^ +]*)+ \.\.\.$