| 4574 | } |
| 4575 | |
| 4576 | std::string cmLocalGenerator::GetObjectFileNameWithoutTarget( |
| 4577 | cmSourceFile const& source, std::string const& dir_max, |
| 4578 | bool* hasSourceExtension, char const* customOutputExtension, |
| 4579 | bool const* forceShortObjectName) |
| 4580 | { |
| 4581 | bool useShortObjectNames = this->UseShortObjectNames(); |
| 4582 | if (forceShortObjectName) { |
| 4583 | useShortObjectNames = *forceShortObjectName; |
| 4584 | } |
| 4585 | |
| 4586 | if (!useShortObjectNames && |
| 4587 | this->GetGlobalGenerator()->SupportsCustomObjectNames()) { |
| 4588 | auto customName = this->GetCustomObjectFileName(source); |
| 4589 | if (!customName.empty()) { |
| 4590 | auto ext = this->GlobalGenerator->GetLanguageOutputExtension(source); |
| 4591 | if (customOutputExtension) { |
| 4592 | ext = *customOutputExtension; |
| 4593 | } |
| 4594 | return cmStrCat(customName, ext); |
| 4595 | } |
| 4596 | } |
| 4597 | |
| 4598 | // This can return an absolute path in the case where source is |
| 4599 | // not relative to the current source or binary directories |
| 4600 | std::string objectName = this->GetRelativeSourceFileName(source); |
| 4601 | // if it is still a full path check for the try compile case |
| 4602 | // try compile never have in source sources, and should not |
| 4603 | // have conflicting source file names in the same target |
| 4604 | if (cmSystemTools::FileIsFullPath(objectName)) { |
| 4605 | if (this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile()) { |
| 4606 | objectName = cmSystemTools::GetFilenameName(source.GetFullPath()); |
| 4607 | } |
| 4608 | } |
| 4609 | bool const isPchObject = source.IsPchHeader() || source.IsPchSource(); |
| 4610 | |
| 4611 | // Short object path policy selected, use as little info as necessary to |
| 4612 | // select an object name |
| 4613 | bool keptSourceExtension = true; |
| 4614 | if (useShortObjectNames) { |
| 4615 | objectName = this->GetShortObjectFileName(source); |
| 4616 | keptSourceExtension = false; |
| 4617 | } |
| 4618 | |
| 4619 | // Ensure that for the CMakeFiles/<target>.dir/generated_source_file |
| 4620 | // we don't end up having: |
| 4621 | // CMakeFiles/<target>.dir/CMakeFiles/<target>.dir/generated_source_file.obj |
| 4622 | cmValue unitySourceFile = source.GetProperty("UNITY_SOURCE_FILE"); |
| 4623 | cmValue pchExtension = source.GetProperty("PCH_EXTENSION"); |
| 4624 | if (unitySourceFile || pchExtension || isPchObject) { |
| 4625 | if (pchExtension) { |
| 4626 | customOutputExtension = pchExtension->c_str(); |
| 4627 | } |
| 4628 | |
| 4629 | cmsys::RegularExpression var("(CMakeFiles/[^/]+.dir/)"); |
| 4630 | if (var.find(objectName)) { |
| 4631 | objectName.erase(var.start(), var.end() - var.start()); |
| 4632 | } |
| 4633 | } |
no test coverage detected