* Find the file the given name. Searches the given path and then * the system search path. Returns the full path to the file if it is * found. Otherwise, the empty string is returned. */
| 2880 | * found. Otherwise, the empty string is returned. |
| 2881 | */ |
| 2882 | std::string SystemToolsStatic::FindName( |
| 2883 | std::string const& name, std::vector<std::string> const& userPaths, |
| 2884 | bool no_system_path) |
| 2885 | { |
| 2886 | // Add the system search path to our path first |
| 2887 | std::vector<std::string> path; |
| 2888 | if (!no_system_path) { |
| 2889 | SystemTools::GetPath(path, "CMAKE_FILE_PATH"); |
| 2890 | SystemTools::GetPath(path); |
| 2891 | } |
| 2892 | // now add the additional paths |
| 2893 | path.reserve(path.size() + userPaths.size()); |
| 2894 | path.insert(path.end(), userPaths.begin(), userPaths.end()); |
| 2895 | // now look for the file |
| 2896 | for (std::string const& p : path) { |
| 2897 | std::string tryPath = p; |
| 2898 | if (tryPath.empty() || tryPath.back() != '/') { |
| 2899 | tryPath += '/'; |
| 2900 | } |
| 2901 | tryPath += name; |
| 2902 | if (SystemTools::FileExists(tryPath)) { |
| 2903 | return tryPath; |
| 2904 | } |
| 2905 | } |
| 2906 | // Couldn't find the file. |
| 2907 | return ""; |
| 2908 | } |
| 2909 | |
| 2910 | /** |
| 2911 | * Find the file the given name. Searches the given path and then |