From 9457c95aa033aa192b0fbe2796e3a660a660d0ad Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 5 Nov 2019 14:19:36 -0500 Subject: cmGlobalXCodeGenerator: Mark known source locations --- Source/cmGlobalXCodeGenerator.cxx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 67f1a46..cb3ee54 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -896,7 +896,8 @@ void cmGlobalXCodeGenerator::AddXCodeProjBuildRule( std::string listfile = cmStrCat(target->GetLocalGenerator()->GetCurrentSourceDirectory(), "/CMakeLists.txt"); - cmSourceFile* srcCMakeLists = target->Makefile->GetOrCreateSource(listfile); + cmSourceFile* srcCMakeLists = target->Makefile->GetOrCreateSource( + listfile, false, cmSourceFileLocationKind::Known); if (!cmContains(sources, srcCMakeLists)) { sources.push_back(srcCMakeLists); } @@ -1139,7 +1140,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeTarget( // Add the Info.plist we are about to generate for an App Bundle. if (gtgt->GetPropertyAsBool("MACOSX_BUNDLE")) { std::string plist = this->ComputeInfoPListLocation(gtgt); - cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource(plist, true); + cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource( + plist, true, cmSourceFileLocationKind::Known); classes.push_back(sf); } @@ -2855,14 +2857,16 @@ bool cmGlobalXCodeGenerator::CreateGroups( std::string listfile = cmStrCat(gtgt->GetLocalGenerator()->GetCurrentSourceDirectory(), "/CMakeLists.txt"); - cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource(listfile); + cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource( + listfile, false, cmSourceFileLocationKind::Known); addSourceToGroup(sf->GetFullPath()); } // Add the Info.plist we are about to generate for an App Bundle. if (gtgt->GetPropertyAsBool("MACOSX_BUNDLE")) { std::string plist = this->ComputeInfoPListLocation(gtgt); - cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource(plist, true); + cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource( + plist, true, cmSourceFileLocationKind::Known); addSourceToGroup(sf->GetFullPath()); } } -- cgit v0.12 From 0ce8a5c08de0852f22f9be595c6f08a4a6c865e9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 5 Nov 2019 14:20:21 -0500 Subject: Xcode: Fix generated references to CMakeLists.txt files Refactoring in commit 2d888e3390 (cmSourceFile: Rename mutating GetFullPath() overload, 2019-08-29, v3.16.0-rc1~160^2) accidentally left the paths to `CMakeLists.txt` files empty in generated Xcode project files. Fixes: #19927 --- Source/cmGlobalXCodeGenerator.cxx | 12 ++++++------ .../XcodeProject/ImplicitCMakeLists-check.cmake | 20 ++++++++++++++++++++ Tests/RunCMake/XcodeProject/ImplicitCMakeLists.cmake | 0 Tests/RunCMake/XcodeProject/RunCMakeTest.cmake | 1 + 4 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 Tests/RunCMake/XcodeProject/ImplicitCMakeLists-check.cmake create mode 100644 Tests/RunCMake/XcodeProject/ImplicitCMakeLists.cmake diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index cb3ee54..adeb065 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -776,7 +776,7 @@ public: "Xcode does not support per-config per-source " << property << ":\n" " " << expression << "\n" "specified for source:\n" - " " << this->SourceFile->GetFullPath() << "\n"; + " " << this->SourceFile->ResolveFullPath() << "\n"; /* clang-format on */ this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str()); } @@ -850,7 +850,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile( lg->AppendFlags(flags, lg->GetIncludeFlags(includes, gtgt, lang, true)); cmXCodeObject* buildFile = - this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), gtgt, lang, sf); + this->CreateXCodeSourceFileFromPath(sf->ResolveFullPath(), gtgt, lang, sf); cmXCodeObject* settings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); settings->AddAttributeIfNotEmpty("COMPILER_FLAGS", @@ -1030,7 +1030,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeFileReference( { std::string lang = this->CurrentLocalGenerator->GetSourceFileLanguage(*sf); - return this->CreateXCodeFileReferenceFromPath(sf->GetFullPath(), target, + return this->CreateXCodeFileReferenceFromPath(sf->ResolveFullPath(), target, lang, sf); } @@ -1065,7 +1065,7 @@ struct cmSourceFilePathCompare { bool operator()(cmSourceFile* l, cmSourceFile* r) { - return l->GetFullPath() < r->GetFullPath(); + return l->ResolveFullPath() < r->ResolveFullPath(); } }; @@ -2859,7 +2859,7 @@ bool cmGlobalXCodeGenerator::CreateGroups( "/CMakeLists.txt"); cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource( listfile, false, cmSourceFileLocationKind::Known); - addSourceToGroup(sf->GetFullPath()); + addSourceToGroup(sf->ResolveFullPath()); } // Add the Info.plist we are about to generate for an App Bundle. @@ -2867,7 +2867,7 @@ bool cmGlobalXCodeGenerator::CreateGroups( std::string plist = this->ComputeInfoPListLocation(gtgt); cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource( plist, true, cmSourceFileLocationKind::Known); - addSourceToGroup(sf->GetFullPath()); + addSourceToGroup(sf->ResolveFullPath()); } } } diff --git a/Tests/RunCMake/XcodeProject/ImplicitCMakeLists-check.cmake b/Tests/RunCMake/XcodeProject/ImplicitCMakeLists-check.cmake new file mode 100644 index 0000000..c6bbc1b --- /dev/null +++ b/Tests/RunCMake/XcodeProject/ImplicitCMakeLists-check.cmake @@ -0,0 +1,20 @@ +set(xcProjectFile "${RunCMake_TEST_BINARY_DIR}/ImplicitCMakeLists.xcodeproj/project.pbxproj") +if(NOT EXISTS "${xcProjectFile}") + set(RunCMake_TEST_FAILED "Project file ${xcProjectFile} does not exist.") + return() +endif() + +set(foundCMakeLists 0) +file(STRINGS "${xcProjectFile}" lines) +foreach(line IN LISTS lines) + if(line MATCHES "PBXFileReference.*CMakeLists.txt") + if(foundCMakeLists) + set(RunCMake_TEST_FAILED "CMakeLists.txt referenced multiple times") + return() + endif() + set(foundCMakeLists 1) + endif() +endforeach() +if(NOT foundCMakeLists) + set(RunCMake_TEST_FAILED "CMakeLists.txt not referenced") +endif() diff --git a/Tests/RunCMake/XcodeProject/ImplicitCMakeLists.cmake b/Tests/RunCMake/XcodeProject/ImplicitCMakeLists.cmake new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake index 1dfa8b2..9e82841 100644 --- a/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake +++ b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake @@ -1,6 +1,7 @@ include(RunCMake) run_cmake(ExplicitCMakeLists) +run_cmake(ImplicitCMakeLists) run_cmake(XcodeFileType) run_cmake(XcodeAttributeLocation) -- cgit v0.12