Commit 6780a94c authored by Robert Maynard's avatar Robert Maynard

Updated to support find_program

parent 1baed285
Pipeline #154632 failed with stage
......@@ -3,6 +3,7 @@
#include "cmFindProgramCommand.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
......@@ -15,7 +16,9 @@ class cmExecutionStatus;
struct cmFindProgramHelper
{
cmFindProgramHelper()
cmFindProgramHelper(cmMakefile* makefile, bool debugMode)
: DebugSearches("find_program", debugMode)
, Makefile(makefile)
{
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
// Consider platform-specific extensions.
......@@ -26,6 +29,14 @@ struct cmFindProgramHelper
this->Extensions.emplace_back();
}
~cmFindProgramHelper()
{
std::string buffer = this->DebugSearches.GenerateSearchLocations();
if (!buffer.empty()) {
this->Makefile->IssueMessage(MessageType::LOG, buffer);
}
}
// List of valid extensions.
std::vector<std::string> Extensions;
......@@ -41,6 +52,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 +93,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(name, this->TestPath)
: this->DebugSearches.FailedAt(name, this->TestPath);
if (exists) {
this->BestPath = this->TestPath;
return true;
}
......@@ -159,7 +176,7 @@ std::string cmFindProgramCommand::FindNormalProgram()
std::string cmFindProgramCommand::FindNormalProgramNamesPerDir()
{
// Search for all names in each directory.
cmFindProgramHelper helper;
cmFindProgramHelper helper(this->Makefile, this->DebugMode);
for (std::string const& n : this->Names) {
helper.AddName(n);
}
......@@ -182,7 +199,7 @@ std::string cmFindProgramCommand::FindNormalProgramNamesPerDir()
std::string cmFindProgramCommand::FindNormalProgramDirsPerName()
{
// Search the entire path for each name.
cmFindProgramHelper helper;
cmFindProgramHelper helper(this->Makefile, this->DebugMode);
for (std::string const& n : this->Names) {
// Switch to searching for this name.
helper.SetName(n);
......
\[Find Query\].*
VAR: PROG
NAMES: \[testAandB\]
Query Type: PROGRAM.*
Framework PROGRAM.*
AppBundle PROGRAM.*
CMAKE_FIND_USE_CMAKE_PATH: 1
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
.*
CMake Debug Log at EnvAndHints.cmake:[0-9]+ \(find_program\):
find_program considered the following locations for.*testAandB.*
The item was found at.*
.*testAandB
.*
\[Find Query\].*
VAR: PROG
NAMES: \[testAandB\]
Query Type: PROGRAM.*
Framework PROGRAM.*
AppBundle PROGRAM.*
CMAKE_FIND_USE_CMAKE_PATH: 1
CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 0
CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
.*
CMake Debug Log at EnvAndHints.cmake:[0-9]+ \(find_program\):
find_program considered the following locations for.*testAandB.*
The item was not found.*
set(CMAKE_FIND_DEBUG_MODE 1)
set(ENV_PATH "$ENV{PATH}")
set(ENV{PATH} ${CMAKE_CURRENT_SOURCE_DIR}/A)
find_program(PROG
......@@ -13,6 +14,7 @@ find_program(PROG
)
message(STATUS "PROG='${PROG}'")
unset(PROG CACHE)
set(CMAKE_FIND_DEBUG_MODE 0)
find_program(PROG
NAMES testAandB
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment