diff --git a/Source/CPack/cmCPackBundleGenerator.cxx b/Source/CPack/cmCPackBundleGenerator.cxx index 3a6f7f41e3..82a4935ec9 100644 --- a/Source/CPack/cmCPackBundleGenerator.cxx +++ b/Source/CPack/cmCPackBundleGenerator.cxx @@ -27,8 +27,7 @@ int cmCPackBundleGenerator::InitializeInternal() } if (this->GetOption("CPACK_BUNDLE_APPLE_CERT_APP")) { - std::string const codesign_path = cmSystemTools::FindProgram( - "codesign", std::vector(), false); + std::string const codesign_path = cmSystemTools::FindProgram("codesign"); if (codesign_path.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx index 8d2f516e1c..4b26a631bd 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.cxx +++ b/Source/CPack/cmCPackDragNDropGenerator.cxx @@ -75,8 +75,7 @@ int cmCPackDragNDropGenerator::InitializeInternal() paths.emplace_back("/Applications/Xcode.app/Contents/Developer/Tools"); paths.emplace_back("/Developer/Tools"); - std::string const hdiutil_path = - cmSystemTools::FindProgram("hdiutil", std::vector(), false); + std::string const hdiutil_path = cmSystemTools::FindProgram("hdiutil"); if (hdiutil_path.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot locate hdiutil command" << std::endl); @@ -85,7 +84,7 @@ int cmCPackDragNDropGenerator::InitializeInternal() this->SetOptionIfNotSet("CPACK_COMMAND_HDIUTIL", hdiutil_path); std::string const setfile_path = - cmSystemTools::FindProgram("SetFile", paths, false); + cmSystemTools::FindProgram("SetFile", paths); if (setfile_path.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot locate SetFile command" << std::endl); @@ -93,7 +92,7 @@ int cmCPackDragNDropGenerator::InitializeInternal() } this->SetOptionIfNotSet("CPACK_COMMAND_SETFILE", setfile_path); - std::string const rez_path = cmSystemTools::FindProgram("Rez", paths, false); + std::string const rez_path = cmSystemTools::FindProgram("Rez", paths); if (rez_path.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot locate Rez command" << std::endl); diff --git a/Source/CPack/cmCPackInnoSetupGenerator.cxx b/Source/CPack/cmCPackInnoSetupGenerator.cxx index f76deb2b48..ed0b2c4e6b 100644 --- a/Source/CPack/cmCPackInnoSetupGenerator.cxx +++ b/Source/CPack/cmCPackInnoSetupGenerator.cxx @@ -46,8 +46,8 @@ int cmCPackInnoSetupGenerator::InitializeInternal() #endif SetOptionIfNotSet("CPACK_INNOSETUP_EXECUTABLE", "ISCC"); - std::string const& isccPath = cmSystemTools::FindProgram( - GetOption("CPACK_INNOSETUP_EXECUTABLE"), path, false); + std::string const& isccPath = + cmSystemTools::FindProgram(GetOption("CPACK_INNOSETUP_EXECUTABLE"), path); if (isccPath.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index bc18e824bd..fb8e81ba8c 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -466,7 +466,7 @@ int cmCPackNSISGenerator::InitializeInternal() this->SetOptionIfNotSet("CPACK_NSIS_EXECUTABLE", "makensis"); nsisPath = cmSystemTools::FindProgram( - *this->GetOption("CPACK_NSIS_EXECUTABLE"), path, false); + *this->GetOption("CPACK_NSIS_EXECUTABLE"), path); if (nsisPath.empty()) { cmCPackLogger( diff --git a/Source/CPack/cmCPackProductBuildGenerator.cxx b/Source/CPack/cmCPackProductBuildGenerator.cxx index 32f9a7cef3..4193f8c45f 100644 --- a/Source/CPack/cmCPackProductBuildGenerator.cxx +++ b/Source/CPack/cmCPackProductBuildGenerator.cxx @@ -127,9 +127,7 @@ int cmCPackProductBuildGenerator::InitializeInternal() { this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/Applications"); - std::vector no_paths; - std::string program = - cmSystemTools::FindProgram("pkgbuild", no_paths, false); + std::string program = cmSystemTools::FindProgram("pkgbuild"); if (program.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find pkgbuild executable" << std::endl); @@ -137,7 +135,7 @@ int cmCPackProductBuildGenerator::InitializeInternal() } this->SetOptionIfNotSet("CPACK_COMMAND_PKGBUILD", program); - program = cmSystemTools::FindProgram("productbuild", no_paths, false); + program = cmSystemTools::FindProgram("productbuild"); if (program.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find productbuild executable" << std::endl); diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 69ab748ca3..ef2359f455 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1708,7 +1708,7 @@ std::string cmCTestTestHandler::FindExecutable( // if everything else failed, check the users path, but only if a full path // wasn't specified if (fullPath.empty() && filepath.empty()) { - std::string path = cmSystemTools::FindProgram(filename.c_str()); + std::string path = cmSystemTools::FindProgram(filename); if (!path.empty()) { resultingConfig.clear(); return path; diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 1968f3b75b..a8691f3125 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -2992,6 +2992,16 @@ unsigned int cmSystemTools::RandomNumber() return static_cast(gen()); } +std::string cmSystemTools::FindProgram(std::string const& name, + std::vector const& path) +{ + std::string exe = cmsys::SystemTools::FindProgram(name, path); + if (!exe.empty()) { + exe = cmSystemTools::ToNormalizedPathOnDisk(std::move(exe)); + } + return exe; +} + namespace { std::string InitLogicalWorkingDirectory() { @@ -3065,11 +3075,7 @@ std::string FindOwnExecutable(char const* argv0) } } #else - std::string errorMsg; - std::string exe; - if (!cmSystemTools::FindProgramPath(argv0, exe, errorMsg)) { - // ??? - } + std::string exe = cmsys::SystemTools::FindProgram(argv0); #endif exe = cmSystemTools::ToNormalizedPathOnDisk(std::move(exe)); return exe; diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 16c5caa321..892da76c1b 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -560,6 +560,14 @@ public: static unsigned int RandomSeed(); static unsigned int RandomNumber(); + /** + * Find an executable in the system PATH, with optional extra paths. + * This wraps KWSys's FindProgram to add ToNormalizedPathOnDisk. + */ + static std::string FindProgram( + std::string const& name, + std::vector const& path = std::vector()); + /** Find the directory containing CMake executables. */ static void FindCMakeResources(char const* argv0);