| 54 | } |
| 55 | |
| 56 | std::string find_xclbin_path() { |
| 57 | std::string xclbin_prefix = CMAKE_XCLBIN_PREFIX; |
| 58 | |
| 59 | // 1. Check FLM_CONFIG_PATH environment variable |
| 60 | const char* env_path = std::getenv("FLM_XCLBIN_PATH"); |
| 61 | if (env_path && *env_path) { |
| 62 | // Remove possible "/xclbins" or "/xclbins/" from the end of the path |
| 63 | std::string path(env_path); |
| 64 | if (path.size() > 9 && path.substr(path.size() - 9) == "/xclbins/") { |
| 65 | path = path.substr(0, path.size() - 9); |
| 66 | } else if (path.size() > 9 && path.substr(path.size() - 9) == "\\xclbins\\") { |
| 67 | path = path.substr(0, path.size() - 9); |
| 68 | } else if (path.size() > 8 && path.substr(path.size() - 8) == "/xclbins") { |
| 69 | path = path.substr(0, path.size() - 8); |
| 70 | } else if (path.size() > 8 && path.substr(path.size() - 8) == "\\xclbins") { |
| 71 | path = path.substr(0, path.size() - 8); |
| 72 | } |
| 73 | |
| 74 | if (std::filesystem::exists(path + "/xclbins")) { |
| 75 | return path; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // 2. Check for install prefix |
| 80 | std::string installed_path = xclbin_prefix; |
| 81 | if (std::filesystem::exists(installed_path)) { |
| 82 | return installed_path; |
| 83 | } |
| 84 | |
| 85 | // 3. Check relative to executable |
| 86 | std::string exe_dir = get_executable_directory(); |
| 87 | std::string exe_relative_path = exe_dir; |
| 88 | if (std::filesystem::exists(exe_relative_path)) { |
| 89 | return exe_relative_path; |
| 90 | } |
| 91 | |
| 92 | // 4. Check current working directory |
| 93 | if (std::filesystem::exists("xclbins")) { |
| 94 | return "xclbins"; |
| 95 | } |
| 96 | |
| 97 | // If not found, throw an error |
| 98 | throw std::runtime_error("xclbins not found. Please set FLM_XCLBIN_PATH or place it next to the executable."); |
| 99 | } |
| 100 | |
| 101 | std::string get_executable_directory() { |
| 102 | #ifdef _WIN32 |
no test coverage detected