| 232 | } |
| 233 | |
| 234 | void cmFindCommon::RerootPaths(std::vector<std::string>& paths, |
| 235 | std::string* debugBuffer) |
| 236 | { |
| 237 | // Short-circuit if there is nothing to do. |
| 238 | if (this->FindRootPathMode == RootPathModeNever) { |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | cmValue sysroot = this->Makefile->GetDefinition("CMAKE_SYSROOT"); |
| 243 | cmValue sysrootCompile = |
| 244 | this->Makefile->GetDefinition("CMAKE_SYSROOT_COMPILE"); |
| 245 | cmValue sysrootLink = this->Makefile->GetDefinition("CMAKE_SYSROOT_LINK"); |
| 246 | cmValue rootPath = this->Makefile->GetDefinition("CMAKE_FIND_ROOT_PATH"); |
| 247 | bool const noSysroot = !cmNonempty(sysroot); |
| 248 | bool const noCompileSysroot = !cmNonempty(sysrootCompile); |
| 249 | bool const noLinkSysroot = !cmNonempty(sysrootLink); |
| 250 | bool const noRootPath = !cmNonempty(rootPath); |
| 251 | if (noSysroot && noCompileSysroot && noLinkSysroot && noRootPath) { |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | if (this->DebugModeEnabled() && debugBuffer) { |
| 256 | *debugBuffer = cmStrCat( |
| 257 | *debugBuffer, "Prepending the following roots to each prefix:\n"); |
| 258 | } |
| 259 | |
| 260 | auto debugRoot = [this, debugBuffer](std::string const& name, |
| 261 | cmValue value) { |
| 262 | if (this->DebugModeEnabled() && debugBuffer) { |
| 263 | *debugBuffer = cmStrCat(*debugBuffer, name, '\n'); |
| 264 | cmList roots{ value }; |
| 265 | if (roots.empty()) { |
| 266 | *debugBuffer = cmStrCat(*debugBuffer, " none\n"); |
| 267 | } |
| 268 | for (auto const& root : roots) { |
| 269 | *debugBuffer = cmStrCat(*debugBuffer, " ", root, '\n'); |
| 270 | } |
| 271 | } |
| 272 | }; |
| 273 | |
| 274 | // Construct the list of path roots with no trailing slashes. |
| 275 | cmList roots; |
| 276 | debugRoot("CMAKE_FIND_ROOT_PATH", rootPath); |
| 277 | if (cmNonempty(rootPath)) { |
| 278 | roots.assign(*rootPath); |
| 279 | } |
| 280 | debugRoot("CMAKE_SYSROOT_COMPILE", sysrootCompile); |
| 281 | if (cmNonempty(sysrootCompile)) { |
| 282 | roots.emplace_back(*sysrootCompile); |
| 283 | } |
| 284 | debugRoot("CMAKE_SYSROOT_LINK", sysrootLink); |
| 285 | if (cmNonempty(sysrootLink)) { |
| 286 | roots.emplace_back(*sysrootLink); |
| 287 | } |
| 288 | debugRoot("CMAKE_SYSROOT", sysroot); |
| 289 | if (cmNonempty(sysroot)) { |
| 290 | roots.emplace_back(*sysroot); |
| 291 | } |
no test coverage detected