| 378 | } |
| 379 | |
| 380 | bool cmFileCopier::Run(std::vector<std::string> const& args) |
| 381 | { |
| 382 | if (!this->Parse(args)) { |
| 383 | return false; |
| 384 | } |
| 385 | |
| 386 | for (std::string const& f : this->Files) { |
| 387 | std::string file; |
| 388 | if (!f.empty() && !cmSystemTools::FileIsFullPath(f)) { |
| 389 | if (!this->FilesFromDir.empty()) { |
| 390 | file = this->FilesFromDir; |
| 391 | } else { |
| 392 | file = this->Makefile->GetCurrentSourceDirectory(); |
| 393 | } |
| 394 | file += "/"; |
| 395 | file += f; |
| 396 | } else if (!this->FilesFromDir.empty()) { |
| 397 | this->Status.SetError("option FILES_FROM_DIR requires all files " |
| 398 | "to be specified as relative paths."); |
| 399 | return false; |
| 400 | } else { |
| 401 | file = f; |
| 402 | } |
| 403 | |
| 404 | // Split the input file into its directory and name components. |
| 405 | std::vector<std::string> fromPathComponents; |
| 406 | cmSystemTools::SplitPath(file, fromPathComponents); |
| 407 | std::string fromName = *(fromPathComponents.end() - 1); |
| 408 | std::string fromDir = cmSystemTools::JoinPath( |
| 409 | fromPathComponents.begin(), fromPathComponents.end() - 1); |
| 410 | |
| 411 | // Compute the full path to the destination file. |
| 412 | std::string toFile = this->Destination; |
| 413 | if (!this->FilesFromDir.empty()) { |
| 414 | std::string dir = cmSystemTools::GetFilenamePath(f); |
| 415 | if (!dir.empty()) { |
| 416 | toFile += "/"; |
| 417 | toFile += dir; |
| 418 | } |
| 419 | } |
| 420 | std::string const& toName = this->ToName(fromName); |
| 421 | if (!toName.empty()) { |
| 422 | toFile += "/"; |
| 423 | toFile += toName; |
| 424 | } |
| 425 | |
| 426 | // Construct the full path to the source file. The file name may |
| 427 | // have been changed above. |
| 428 | std::string fromFile = fromDir; |
| 429 | if (!fromName.empty()) { |
| 430 | fromFile += "/"; |
| 431 | fromFile += fromName; |
| 432 | } |
| 433 | |
| 434 | if (!this->Install(fromFile, toFile)) { |
| 435 | return false; |
| 436 | } |
| 437 | } |