From a690523fcf31ca7dc062fca746c0f76e405c0e7a Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 10 Feb 2022 12:17:39 -0500 Subject: cmFindPackageCommand: Drop ComputeIfDebugModeWanted overload The overload for `--debug-find-pkg` has the same signature as the base class method for `--debug-find-var`. To avoid confusion, drop the overload and inline it its only call site. --- Source/cmFindPackageCommand.cxx | 9 ++------- Source/cmFindPackageCommand.h | 2 -- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index fac0e08..c40fea0 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -235,7 +235,8 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args) this->SearchPathSuffixes.emplace_back(); // Process debug mode - this->DebugMode = this->ComputeIfDebugModeWanted(this->Name); + this->DebugMode = this->ComputeIfDebugModeWanted() || + this->Makefile->GetCMakeInstance()->GetDebugFindPkgOutput(this->Name); this->DebugBuffer.clear(); // Parse the arguments. @@ -621,12 +622,6 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args) return loadedPackage; } -bool cmFindPackageCommand::ComputeIfDebugModeWanted(std::string const& var) -{ - return this->ComputeIfDebugModeWanted() || - this->Makefile->GetCMakeInstance()->GetDebugFindPkgOutput(var); -} - bool cmFindPackageCommand::FindPackageUsingModuleMode() { bool foundModule = false; diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 439d934..f921bb0 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -40,7 +40,6 @@ class cmSearchPath; class cmFindPackageCommand : public cmFindCommon { public: - using cmFindCommon::ComputeIfDebugModeWanted; /*! A sorting order strategy to be applied to recovered package folders (see * FIND_PACKAGE_SORT_ORDER)*/ enum /*class*/ SortOrderType @@ -121,7 +120,6 @@ private: bool ReadListFile(const std::string& f, PolicyScopeRule psr); void StoreVersionFound(); - bool ComputeIfDebugModeWanted(std::string const& var); void ComputePrefixes(); void FillPrefixesPackageRoot(); void FillPrefixesCMakeEnvironment(); -- cgit v0.12 From 2f435275743a345b8bbfe7de60796a1423ce92fc Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 10 Feb 2022 14:18:46 -0500 Subject: Tests: Improve order of RunCMake.find_package cases Sort recently added cases among similar-named cases. --- Tests/RunCMake/find_package/RunCMakeTest.cmake | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Tests/RunCMake/find_package/RunCMakeTest.cmake b/Tests/RunCMake/find_package/RunCMakeTest.cmake index 037502f..d02e937 100644 --- a/Tests/RunCMake/find_package/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_package/RunCMakeTest.cmake @@ -4,6 +4,7 @@ run_cmake(CMP0074-WARN) run_cmake(CMP0074-OLD) run_cmake(ComponentRequiredAndOptional) run_cmake(FromPATHEnv) +run_cmake_with_options(FromPATHEnvDebugPkg --debug-find-pkg=Resolved) run_cmake(FromPrefixPath) run_cmake(MissingNormal) run_cmake(MissingNormalForceRequired) @@ -15,6 +16,7 @@ run_cmake(MissingModule) run_cmake(MissingModuleRequired) run_cmake(MissingConfig) run_cmake(MissingConfigDebug) +run_cmake_with_options(MissingConfigDebugPkg --debug-find-pkg=NotHere) run_cmake(MissingConfigOneName) run_cmake(MissingConfigRequired) run_cmake(MissingConfigVersion) @@ -51,6 +53,3 @@ if(UNIX ) run_cmake(SetFoundResolved) endif() - -run_cmake_with_options(MissingConfigDebugPkg --debug-find-pkg=NotHere) -run_cmake_with_options(FromPATHEnvDebugPkg --debug-find-pkg=Resolved) -- cgit v0.12 From 596e18540988a7c6a426c5997d0008444773fc02 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 10 Feb 2022 14:42:01 -0500 Subject: find_package: Improve formatting of --debug-find output Also spell out more complete content in the test's expect output. --- Source/cmFindPackageCommand.cxx | 30 +++--- Tests/RunCMake/find_package/FromPATHEnv-stderr.txt | 103 ++++++++++++++++---- Tests/RunCMake/find_package/FromPATHEnv.cmake | 5 + .../find_package/FromPATHEnvDebugPkg-stderr.txt | 104 ++++++++++++++++----- .../find_package/FromPATHEnvDebugPkg.cmake | 5 + 5 files changed, 191 insertions(+), 56 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index c40fea0..d29201b 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -799,12 +799,12 @@ bool cmFindPackageCommand::FindModule(bool& found) module, system, this->DebugMode, debugBuffer); if (this->DebugMode) { if (mfile.empty()) { - debugBuffer = cmStrCat(debugBuffer, "The file was not found."); + debugBuffer = cmStrCat(debugBuffer, "The file was not found.\n"); } else { debugBuffer = cmStrCat(debugBuffer, "The file was found at\n ", mfile, "\n"); } - this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer); } if (!mfile.empty()) { @@ -1310,7 +1310,7 @@ inline std::size_t collectPathsForDebug(std::string& buffer, { const auto& paths = searchPath.GetPaths(); if (paths.empty()) { - buffer += " none"; + buffer += " none\n"; return 0; } for (std::size_t i = startIndex; i < paths.size(); i++) { @@ -1370,7 +1370,7 @@ void cmFindPackageCommand::FillPrefixesPackageRoot() std::string debugBuffer = "_ROOT CMake variable " "[CMAKE_FIND_USE_PACKAGE_ROOT_PATH].\n"; collectPathsForDebug(debugBuffer, paths); - this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer); } } @@ -1393,7 +1393,7 @@ void cmFindPackageCommand::FillPrefixesCMakeEnvironment() paths.AddEnvPath("CMAKE_PREFIX_PATH"); if (this->DebugMode) { debugBuffer = cmStrCat(debugBuffer, - "\nCMAKE_PREFIX_PATH env variable " + "CMAKE_PREFIX_PATH env variable " "[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n"); debugOffset = collectPathsForDebug(debugBuffer, paths, debugOffset); } @@ -1403,10 +1403,10 @@ void cmFindPackageCommand::FillPrefixesCMakeEnvironment() if (this->DebugMode) { debugBuffer = cmStrCat(debugBuffer, - "\nCMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env " + "CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env " "variables [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n"); collectPathsForDebug(debugBuffer, paths, debugOffset); - this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer); } } @@ -1427,10 +1427,10 @@ void cmFindPackageCommand::FillPrefixesCMakeVariable() if (this->DebugMode) { debugBuffer = cmStrCat(debugBuffer, - "\nCMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables " + "CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables " "[CMAKE_FIND_USE_CMAKE_PATH].\n"); collectPathsForDebug(debugBuffer, paths, debugOffset); - this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer); } } @@ -1455,7 +1455,7 @@ void cmFindPackageCommand::FillPrefixesSystemEnvironment() std::string debugBuffer = "Standard system environment variables " "[CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH].\n"; collectPathsForDebug(debugBuffer, paths); - this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer); } } @@ -1485,7 +1485,7 @@ void cmFindPackageCommand::FillPrefixesUserRegistry() "CMake User Package Registry [CMAKE_FIND_USE_PACKAGE_REGISTRY].\n"; collectPathsForDebug(debugBuffer, this->LabeledPaths[PathLabel::UserRegistry]); - this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer); } } @@ -1505,7 +1505,7 @@ void cmFindPackageCommand::FillPrefixesSystemRegistry() "[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY].\n"; collectPathsForDebug(debugBuffer, this->LabeledPaths[PathLabel::SystemRegistry]); - this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer); } } @@ -1684,7 +1684,7 @@ void cmFindPackageCommand::FillPrefixesCMakeSystemVariable() std::string debugBuffer = "CMake variables defined in the Platform file " "[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH].\n"; collectPathsForDebug(debugBuffer, paths); - this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer); } } @@ -1699,7 +1699,7 @@ void cmFindPackageCommand::FillPrefixesUserGuess() std::string debugBuffer = "Paths specified by the find_package PATHS option.\n"; collectPathsForDebug(debugBuffer, paths); - this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer); } } @@ -1714,7 +1714,7 @@ void cmFindPackageCommand::FillPrefixesUserHints() std::string debugBuffer = "Paths specified by the find_package HINTS option.\n"; collectPathsForDebug(debugBuffer, paths); - this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n"); + this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer); } } diff --git a/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt b/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt index b35f05e..55b6a7a 100644 --- a/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt +++ b/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt @@ -1,20 +1,83 @@ -CMake Debug Log at FromPATHEnv.cmake:5 \(find_package\): - find_package considered the following paths for Resolved.cmake.* -.*/Modules/FindResolved.cmake.* - The file was not found.* - _ROOT CMake variable.* - CMAKE_PREFIX_PATH variable.* - CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables.* - Env variable Resolved_DIR.* - CMAKE_PREFIX_PATH env variable.* - Paths specified by the find_package HINTS option.* - Standard system environment variables.* -.*Tests/RunCMake/find_package/PackageRoot.* - CMake User Package Registry.* - CMake variables defined in the Platform file.* - CMake System Package Registry.* - Paths specified by the find_package PATHS option.* - find_package considered the following locations for the Config module:.* -.*Tests/RunCMake/find_package/PackageRoot/ResolvedConfig\.cmake.* - The file was found at.* -.*Tests/RunCMake/find_package/PackageRoot/ResolvedConfig\.cmake +^CMake Debug Log at FromPATHEnv.cmake:[0-9]+ \(find_package\): + find_package considered the following paths for Resolved.cmake + + [^ +]*/Modules/FindResolved.cmake + + The file was not found. + + _ROOT CMake variable \[CMAKE_FIND_USE_PACKAGE_ROOT_PATH\]. + + none + + CMAKE_PREFIX_PATH variable \[CMAKE_FIND_USE_CMAKE_PATH\]. + + none + + CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables + \[CMAKE_FIND_USE_CMAKE_PATH\]. + + none + + Env variable Resolved_DIR \[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH\]. + + none + + CMAKE_PREFIX_PATH env variable \[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH\]. +( + [^ +]+)+ + + CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env variables + \[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH\]. +( + [^ +]+)+ + + Paths specified by the find_package HINTS option. + + none + + Standard system environment variables + \[CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH\]. + + [^ +]*/Tests/RunCMake/find_package/PackageRoot + + CMake User Package Registry \[CMAKE_FIND_USE_PACKAGE_REGISTRY\]. +( + [^ +]+)+ + + CMake variables defined in the Platform file + \[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH\]. +( + [^ +]+)+ + + CMake System Package Registry + \[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY\]. +( + [^ +]+)+ + + Paths specified by the find_package PATHS option. + + none + + find_package considered the following locations for the Config module: + + [^ +]*/Tests/RunCMake/find_package/PackageRoot/ResolvedConfig.cmake + + The file was found at + + [^ +]*/Tests/RunCMake/find_package/PackageRoot/ResolvedConfig.cmake + +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) ++ +CMake Debug Log at FromPATHEnv.cmake:[0-9]+ \(find_package\): +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/find_package/FromPATHEnv.cmake b/Tests/RunCMake/find_package/FromPATHEnv.cmake index ceb79b6..9158d4b 100644 --- a/Tests/RunCMake/find_package/FromPATHEnv.cmake +++ b/Tests/RunCMake/find_package/FromPATHEnv.cmake @@ -1,4 +1,7 @@ set(ENV_PATH "$ENV{PATH}") +set(ENV_CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}") + +set(ENV{CMAKE_PREFIX_PATH} "") set(CMAKE_FIND_DEBUG_MODE ON) set(ENV{PATH} "${CMAKE_CURRENT_SOURCE_DIR}/PackageRoot") @@ -30,4 +33,6 @@ foreach(path "/does_not_exist" "/PackageRoot" "") find_package(Resolved NO_SYSTEM_ENVIRONMENT_PATH QUIET) message(STATUS "Resolved_FOUND='${Resolved_FOUND}'") endforeach() + +set(ENV{CMAKE_PREFIX_PATH} "${ENV_CMAKE_PREFIX_PATH}") set(ENV{PATH} "${ENV_PATH}") diff --git a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt index 94ed178..e3685bc 100644 --- a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt +++ b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt @@ -1,21 +1,83 @@ -CMake Debug Log at FromPATHEnvDebugPkg.cmake:4 \(find_package\): - find_package considered the following paths for Resolved.cmake.* -.*/Modules/FindResolved.cmake.* - The file was not found.* - _ROOT CMake variable.* - CMAKE_PREFIX_PATH variable.* - CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables.* - Env variable Resolved_DIR.* - CMAKE_PREFIX_PATH env variable.* - CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env variables.* - Paths specified by the find_package HINTS option.* - Standard system environment variables.* -.*Tests/RunCMake/find_package/PackageRoot.* - CMake User Package Registry.* - CMake variables defined in the Platform file.* - CMake System Package Registry.* - Paths specified by the find_package PATHS option.* - find_package considered the following locations for the Config module:.* -.*Tests/RunCMake/find_package/PackageRoot/ResolvedConfig\.cmake.* - The file was found at.* -.*Tests/RunCMake/find_package/PackageRoot/ResolvedConfig\.cmake +^CMake Debug Log at FromPATHEnvDebugPkg.cmake:[0-9]+ \(find_package\): + find_package considered the following paths for Resolved.cmake + + [^ +]*/Modules/FindResolved.cmake + + The file was not found. + + _ROOT CMake variable \[CMAKE_FIND_USE_PACKAGE_ROOT_PATH\]. + + none + + CMAKE_PREFIX_PATH variable \[CMAKE_FIND_USE_CMAKE_PATH\]. + + none + + CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables + \[CMAKE_FIND_USE_CMAKE_PATH\]. + + none + + Env variable Resolved_DIR \[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH\]. + + none + + CMAKE_PREFIX_PATH env variable \[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH\]. +( + [^ +]+)+ + + CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env variables + \[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH\]. +( + [^ +]+)+ + + Paths specified by the find_package HINTS option. + + none + + Standard system environment variables + \[CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH\]. + + [^ +]*/Tests/RunCMake/find_package/PackageRoot + + CMake User Package Registry \[CMAKE_FIND_USE_PACKAGE_REGISTRY\]. +( + [^ +]+)+ + + CMake variables defined in the Platform file + \[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH\]. +( + [^ +]+)+ + + CMake System Package Registry + \[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY\]. +( + [^ +]+)+ + + Paths specified by the find_package PATHS option. + + none + + find_package considered the following locations for the Config module: + + [^ +]*/Tests/RunCMake/find_package/PackageRoot/ResolvedConfig.cmake + + The file was found at + + [^ +]*/Tests/RunCMake/find_package/PackageRoot/ResolvedConfig.cmake + +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) ++ +CMake Debug Log at FromPATHEnvDebugPkg.cmake:[0-9]+ \(find_package\): +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg.cmake b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg.cmake index 0ed8a12..72b03e6 100644 --- a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg.cmake +++ b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg.cmake @@ -1,4 +1,7 @@ set(ENV_PATH "$ENV{PATH}") +set(ENV_CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}") + +set(ENV{CMAKE_PREFIX_PATH} "") set(ENV{PATH} "${CMAKE_CURRENT_SOURCE_DIR}/PackageRoot") find_package(Resolved QUIET) @@ -28,4 +31,6 @@ foreach(path "/does_not_exist" "/PackageRoot" "") find_package(ResolvedC NO_SYSTEM_ENVIRONMENT_PATH QUIET) message(STATUS "Resolved_FOUND='${ResolvedC_FOUND}'") endforeach() + +set(ENV{CMAKE_PREFIX_PATH} "${ENV_CMAKE_PREFIX_PATH}") set(ENV{PATH} "${ENV_PATH}") -- cgit v0.12 From 636ca7f25c3016805bf0214bc563f30728d9de0b Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 10 Feb 2022 13:41:23 -0500 Subject: find_package: Fix find module name in --debug-find output --- Source/cmFindPackageCommand.cxx | 9 ++++----- Tests/RunCMake/find_package/FromPATHEnv-stderr.txt | 2 +- Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index d29201b..5f1544d 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -789,14 +789,13 @@ void cmFindPackageCommand::RestoreFindDefinitions() bool cmFindPackageCommand::FindModule(bool& found) { - std::string module = cmStrCat("Find", this->Name, ".cmake"); + std::string moduleFileName = cmStrCat("Find", this->Name, ".cmake"); bool system = false; - std::string debugBuffer = - cmStrCat("find_package considered the following paths for ", this->Name, - ".cmake\n"); + std::string debugBuffer = cmStrCat( + "find_package considered the following paths for ", moduleFileName, ":\n"); std::string mfile = this->Makefile->GetModulesFile( - module, system, this->DebugMode, debugBuffer); + moduleFileName, system, this->DebugMode, debugBuffer); if (this->DebugMode) { if (mfile.empty()) { debugBuffer = cmStrCat(debugBuffer, "The file was not found.\n"); diff --git a/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt b/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt index 55b6a7a..5fe89fd 100644 --- a/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt +++ b/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt @@ -1,5 +1,5 @@ ^CMake Debug Log at FromPATHEnv.cmake:[0-9]+ \(find_package\): - find_package considered the following paths for Resolved.cmake + find_package considered the following paths for FindResolved.cmake: [^ ]*/Modules/FindResolved.cmake diff --git a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt index e3685bc..f921804 100644 --- a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt +++ b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt @@ -1,5 +1,5 @@ ^CMake Debug Log at FromPATHEnvDebugPkg.cmake:[0-9]+ \(find_package\): - find_package considered the following paths for Resolved.cmake + find_package considered the following paths for FindResolved.cmake: [^ ]*/Modules/FindResolved.cmake -- cgit v0.12 From df3e29450a1d9d5bd18423831fdab13ba94fe876 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 10 Feb 2022 14:07:41 -0500 Subject: find_package: Mention package name in Config mode debug output Otherwise, if there are no paths considered then the output does not specify the name of the package. --- Source/cmFindPackageCommand.cxx | 3 ++- Tests/RunCMake/CMakePresets/Debug-stderr.txt | 3 ++- Tests/RunCMake/find_package/FromPATHEnv-stderr.txt | 3 ++- Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 5f1544d..7bcb719 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -1117,7 +1117,8 @@ bool cmFindPackageCommand::FindConfig() if (this->DebugMode) { this->DebugBuffer = cmStrCat(this->DebugBuffer, "find_package considered the following " - "locations for the Config module:\n"); + "locations for ", + this->Name, "'s Config module:\n"); } // Search for frameworks. diff --git a/Tests/RunCMake/CMakePresets/Debug-stderr.txt b/Tests/RunCMake/CMakePresets/Debug-stderr.txt index 7fdb8b3..d30dc58 100644 --- a/Tests/RunCMake/CMakePresets/Debug-stderr.txt +++ b/Tests/RunCMake/CMakePresets/Debug-stderr.txt @@ -1 +1,2 @@ - find_package considered the following locations for the Config module: + find_package considered the following locations for + ThisPackageHopefullyDoesNotExist's Config module: diff --git a/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt b/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt index 5fe89fd..19108f4 100644 --- a/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt +++ b/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt @@ -65,7 +65,8 @@ none - find_package considered the following locations for the Config module: + find_package considered the following locations for Resolved's Config + module: [^ ]*/Tests/RunCMake/find_package/PackageRoot/ResolvedConfig.cmake diff --git a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt index f921804..a708282 100644 --- a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt +++ b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt @@ -65,7 +65,8 @@ none - find_package considered the following locations for the Config module: + find_package considered the following locations for Resolved's Config + module: [^ ]*/Tests/RunCMake/find_package/PackageRoot/ResolvedConfig.cmake -- cgit v0.12 From d634d203973086f32f6d26e636eb1c9cc1acc545 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 10 Feb 2022 12:08:13 -0500 Subject: find_package: Avoid printing debug output header multiple times --- Source/cmFindPackageCommand.cxx | 15 ++++----------- Tests/RunCMake/find_package/FromPATHEnv-stderr.txt | 4 ---- .../RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt | 4 ---- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 7bcb719..a8dff95 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -237,7 +237,6 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args) // Process debug mode this->DebugMode = this->ComputeIfDebugModeWanted() || this->Makefile->GetCMakeInstance()->GetDebugFindPkgOutput(this->Name); - this->DebugBuffer.clear(); // Parse the arguments. enum Doing @@ -610,15 +609,14 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args) loadedPackage = true; } } - - if (this->DebugMode) { - this->DebugMessage(this->DebugBuffer); - this->DebugBuffer.clear(); - } } this->AppendSuccessInformation(); + if (!this->DebugBuffer.empty()) { + this->DebugMessage(this->DebugBuffer); + } + return loadedPackage; } @@ -947,11 +945,6 @@ bool cmFindPackageCommand::HandlePackageMode( result = false; } - if (this->DebugMode) { - this->DebugMessage(this->DebugBuffer); - this->DebugBuffer.clear(); - } - // package not found if (result && !found) { // warn if package required or neither quiet nor in config mode diff --git a/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt b/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt index 19108f4..691d7f0 100644 --- a/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt +++ b/Tests/RunCMake/find_package/FromPATHEnv-stderr.txt @@ -77,8 +77,4 @@ ]*/Tests/RunCMake/find_package/PackageRoot/ResolvedConfig.cmake Call Stack \(most recent call first\): - CMakeLists.txt:[0-9]+ \(include\) -+ -CMake Debug Log at FromPATHEnv.cmake:[0-9]+ \(find_package\): -Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt index a708282..ef5ec33 100644 --- a/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt +++ b/Tests/RunCMake/find_package/FromPATHEnvDebugPkg-stderr.txt @@ -77,8 +77,4 @@ ]*/Tests/RunCMake/find_package/PackageRoot/ResolvedConfig.cmake Call Stack \(most recent call first\): - CMakeLists.txt:[0-9]+ \(include\) -+ -CMake Debug Log at FromPATHEnvDebugPkg.cmake:[0-9]+ \(find_package\): -Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\)$ -- cgit v0.12 From 38de1bef2d10270d5f1be1fef2760310571c4026 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 10 Feb 2022 15:23:07 -0500 Subject: find_package: Improve --debug-find-pkg= when using a find module Extend the feature added by commit d7b18895bc (cmake: Add filtered debug-find options, 2021-12-07, v3.23.0-rc1~217^2) to enable debug output for `find_*` calls within a find module or cmake package configuration file. Fixes: #23211 --- Source/cmFindCommon.cxx | 3 +- Source/cmFindPackageCommand.cxx | 5 +- Source/cmMakefile.cxx | 19 +++ Source/cmMakefile.h | 14 +++ .../find_package/ModuleModeDebugPkg-stderr.txt | 128 +++++++++++++++++++++ .../RunCMake/find_package/ModuleModeDebugPkg.cmake | 2 + .../find_package/ModuleModeDebugPkg/FindBar.cmake | 2 + .../find_package/ModuleModeDebugPkg/FindFoo.cmake | 6 + Tests/RunCMake/find_package/RunCMakeTest.cmake | 1 + 9 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 Tests/RunCMake/find_package/ModuleModeDebugPkg-stderr.txt create mode 100644 Tests/RunCMake/find_package/ModuleModeDebugPkg.cmake create mode 100644 Tests/RunCMake/find_package/ModuleModeDebugPkg/FindBar.cmake create mode 100644 Tests/RunCMake/find_package/ModuleModeDebugPkg/FindFoo.cmake diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx index 1bb98ea..7106e4b 100644 --- a/Source/cmFindCommon.cxx +++ b/Source/cmFindCommon.cxx @@ -73,7 +73,8 @@ void cmFindCommon::DebugMessage(std::string const& msg) const bool cmFindCommon::ComputeIfDebugModeWanted() { - return this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE") || + return this->Makefile->GetDebugFindPkgMode() || + this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE") || this->Makefile->GetCMakeInstance()->GetDebugFindOutput(); } diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index a8dff95..f55d838 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -33,7 +33,6 @@ #include "cmSystemTools.h" #include "cmValue.h" #include "cmVersion.h" -#include "cmake.h" #if defined(__HAIKU__) # include @@ -235,8 +234,8 @@ bool cmFindPackageCommand::InitialPass(std::vector const& args) this->SearchPathSuffixes.emplace_back(); // Process debug mode - this->DebugMode = this->ComputeIfDebugModeWanted() || - this->Makefile->GetCMakeInstance()->GetDebugFindPkgOutput(this->Name); + cmMakefile::DebugFindPkgRAII debugFindPkgRAII(this->Makefile, this->Name); + this->DebugMode = this->ComputeIfDebugModeWanted(); // Parse the arguments. enum Doing diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 68e61bb..94d3be6 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4519,3 +4519,22 @@ cmMakefile::MacroPushPop::~MacroPushPop() { this->Makefile->PopMacroScope(this->ReportError); } + +cmMakefile::DebugFindPkgRAII::DebugFindPkgRAII(cmMakefile* mf, + std::string const& pkg) + : Makefile(mf) + , OldValue(this->Makefile->DebugFindPkg) +{ + this->Makefile->DebugFindPkg = + this->Makefile->GetCMakeInstance()->GetDebugFindPkgOutput(pkg); +} + +cmMakefile::DebugFindPkgRAII::~DebugFindPkgRAII() +{ + this->Makefile->DebugFindPkg = this->OldValue; +} + +bool cmMakefile::GetDebugFindPkgMode() const +{ + return this->DebugFindPkg; +} diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 85988b8..f425697 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -931,6 +931,18 @@ public: // searches std::deque> FindPackageRootPathStack; + class DebugFindPkgRAII + { + cmMakefile* Makefile; + bool OldValue; + + public: + DebugFindPkgRAII(cmMakefile* mf, std::string const& pkg); + ~DebugFindPkgRAII(); + }; + + bool GetDebugFindPkgMode() const; + void MaybeWarnCMP0074(std::string const& pkg); void MaybeWarnUninitialized(std::string const& variable, const char* sourceFilename) const; @@ -1104,6 +1116,8 @@ private: std::vector> GeneratorActions; bool GeneratorActionsInvoked = false; + bool DebugFindPkg = false; + bool CheckSystemVars; bool CheckCMP0000; std::set WarnedCMP0074; diff --git a/Tests/RunCMake/find_package/ModuleModeDebugPkg-stderr.txt b/Tests/RunCMake/find_package/ModuleModeDebugPkg-stderr.txt new file mode 100644 index 0000000..e4fd7c5 --- /dev/null +++ b/Tests/RunCMake/find_package/ModuleModeDebugPkg-stderr.txt @@ -0,0 +1,128 @@ +^CMake Debug Log at ModuleModeDebugPkg/FindFoo.cmake:[0-9]+ \(find_program\): + find_program called with the following settings: + + VAR: FOO_EXE + NAMES: "ModuleModeDebugPkgFooExe" + Documentation: Path to a program. + Framework + Only Search Frameworks: 0 + Search Frameworks Last: 0 + Search Frameworks First: [01] + AppBundle + Only Search AppBundle: 0 + Search AppBundle Last: 0 + Search AppBundle First: [01] + NO_DEFAULT_PATH Enabled + + find_program considered the following locations: + + The item was not found. + +Call Stack \(most recent call first\): + ModuleModeDebugPkg.cmake:[0-9]+ \(find_package\) + CMakeLists.txt:[0-9]+ \(include\) ++ +CMake Debug Log at ModuleModeDebugPkg/FindFoo.cmake:[0-9]+ \(find_library\): + find_library called with the following settings: + + VAR: FOO_LIB + NAMES: "ModuleModeDebugPkgFooLib" + Documentation: Path to a library. + Framework + Only Search Frameworks: 0 + Search Frameworks Last: 0 + Search Frameworks First: [01] + AppBundle + Only Search AppBundle: 0 + Search AppBundle Last: 0 + Search AppBundle First: [01] + NO_DEFAULT_PATH Enabled + + find_library considered the following locations: + + The item was not found. + +Call Stack \(most recent call first\): + ModuleModeDebugPkg.cmake:[0-9]+ \(find_package\) + CMakeLists.txt:[0-9]+ \(include\) ++ +CMake Debug Log at ModuleModeDebugPkg/FindFoo.cmake:[0-9]+ \(find_path\): + find_path called with the following settings: + + VAR: FOO_PATH + NAMES: "ModuleModeDebugPkgFoo.h" + Documentation: Path to a file. + Framework + Only Search Frameworks: 0 + Search Frameworks Last: 0 + Search Frameworks First: [01] + AppBundle + Only Search AppBundle: 0 + Search AppBundle Last: 0 + Search AppBundle First: [01] + NO_DEFAULT_PATH Enabled + + find_path considered the following locations: + + The item was not found. + +Call Stack \(most recent call first\): + ModuleModeDebugPkg.cmake:[0-9]+ \(find_package\) + CMakeLists.txt:[0-9]+ \(include\) ++ +CMake Debug Log at ModuleModeDebugPkg/FindFoo.cmake:[0-9]+ \(find_file\): + find_file called with the following settings: + + VAR: FOO_FILE + NAMES: "ModuleModeDebugPkgFoo.h" + Documentation: Path to a file. + Framework + Only Search Frameworks: 0 + Search Frameworks Last: 0 + Search Frameworks First: [01] + AppBundle + Only Search AppBundle: 0 + Search AppBundle Last: 0 + Search AppBundle First: [01] + NO_DEFAULT_PATH Enabled + + find_file considered the following locations: + + The item was not found. + +Call Stack \(most recent call first\): + ModuleModeDebugPkg.cmake:[0-9]+ \(find_package\) + CMakeLists.txt:[0-9]+ \(include\) ++ +FindBar processed here. ++ +CMake Debug Log at ModuleModeDebugPkg/FindFoo.cmake:[0-9]+ \(find_package\): + Paths specified by the find_package HINTS option. + + none + + Paths specified by the find_package PATHS option. + + none + + find_package considered the following locations for Zot's Config module: + + The file was not found. + +Call Stack \(most recent call first\): + ModuleModeDebugPkg.cmake:[0-9]+ \(find_package\) + CMakeLists.txt:[0-9]+ \(include\) ++ +CMake Debug Log at ModuleModeDebugPkg.cmake:[0-9]+ \(find_package\): + find_package considered the following paths for FindFoo.cmake: + + [^ +]*/Modules/FindFoo.cmake + + The file was found at + + [^ +]*/Tests/RunCMake/find_package/ModuleModeDebugPkg/FindFoo.cmake + +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\)$ diff --git a/Tests/RunCMake/find_package/ModuleModeDebugPkg.cmake b/Tests/RunCMake/find_package/ModuleModeDebugPkg.cmake new file mode 100644 index 0000000..d9cac09 --- /dev/null +++ b/Tests/RunCMake/find_package/ModuleModeDebugPkg.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ModuleModeDebugPkg) +find_package(Foo) diff --git a/Tests/RunCMake/find_package/ModuleModeDebugPkg/FindBar.cmake b/Tests/RunCMake/find_package/ModuleModeDebugPkg/FindBar.cmake new file mode 100644 index 0000000..0711118 --- /dev/null +++ b/Tests/RunCMake/find_package/ModuleModeDebugPkg/FindBar.cmake @@ -0,0 +1,2 @@ +message("FindBar processed here.\n") +find_program(BAR_EXE NAMES ModuleModeDebugPkgBarExe NO_DEFAULT_PATH) diff --git a/Tests/RunCMake/find_package/ModuleModeDebugPkg/FindFoo.cmake b/Tests/RunCMake/find_package/ModuleModeDebugPkg/FindFoo.cmake new file mode 100644 index 0000000..23a15b4 --- /dev/null +++ b/Tests/RunCMake/find_package/ModuleModeDebugPkg/FindFoo.cmake @@ -0,0 +1,6 @@ +find_program(FOO_EXE NAMES ModuleModeDebugPkgFooExe NO_DEFAULT_PATH) +find_library(FOO_LIB NAMES ModuleModeDebugPkgFooLib NO_DEFAULT_PATH) +find_path(FOO_PATH NAMES ModuleModeDebugPkgFoo.h NO_DEFAULT_PATH) +find_file(FOO_FILE NAMES ModuleModeDebugPkgFoo.h NO_DEFAULT_PATH) +find_package(Bar) # not included +find_package(Zot NO_MODULE NO_DEFAULT_PATH) # is included diff --git a/Tests/RunCMake/find_package/RunCMakeTest.cmake b/Tests/RunCMake/find_package/RunCMakeTest.cmake index d02e937..5f4c6cb 100644 --- a/Tests/RunCMake/find_package/RunCMakeTest.cmake +++ b/Tests/RunCMake/find_package/RunCMakeTest.cmake @@ -21,6 +21,7 @@ run_cmake(MissingConfigOneName) run_cmake(MissingConfigRequired) run_cmake(MissingConfigVersion) run_cmake(MixedModeOptions) +run_cmake_with_options(ModuleModeDebugPkg --debug-find-pkg=Foo,Zot) run_cmake(PackageRoot) run_cmake(PackageRootNestedConfig) run_cmake(PackageRootNestedModule) -- cgit v0.12