From b4385d5ccc0241f8adcb012ad645d3696bcc544c Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 10 Apr 2019 07:59:37 -0400 Subject: Xcode: Factor out duplicate source group code into lambda --- Source/cmGlobalXCodeGenerator.cxx | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 51c001e..dd6008f 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2875,6 +2875,14 @@ bool cmGlobalXCodeGenerator::CreateGroups( continue; } + auto addSourceToGroup = [this, mf, gtgt, + &sourceGroups](std::string const& source) { + cmSourceGroup* sourceGroup = mf->FindSourceGroup(source, sourceGroups); + cmXCodeObject* pbxgroup = this->CreateOrGetPBXGroup(gtgt, sourceGroup); + std::string key = GetGroupMapKeyFromPath(gtgt, source); + this->GroupMap[key] = pbxgroup; + }; + // add the soon to be generated Info.plist file as a source for a // MACOSX_BUNDLE file if (gtgt->GetPropertyAsBool("MACOSX_BUNDLE")) { @@ -2890,12 +2898,7 @@ bool cmGlobalXCodeGenerator::CreateGroups( // Object library files go on the link line instead. continue; } - // Add the file to the list of sources. - std::string const& source = sf->GetFullPath(); - cmSourceGroup* sourceGroup = mf->FindSourceGroup(source, sourceGroups); - cmXCodeObject* pbxgroup = this->CreateOrGetPBXGroup(gtgt, sourceGroup); - std::string key = GetGroupMapKeyFromPath(gtgt, source); - this->GroupMap[key] = pbxgroup; + addSourceToGroup(sf->GetFullPath()); } // Add CMakeLists.txt file for user convenience. @@ -2904,11 +2907,7 @@ bool cmGlobalXCodeGenerator::CreateGroups( gtgt->GetLocalGenerator()->GetCurrentSourceDirectory(); listfile += "/CMakeLists.txt"; cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource(listfile); - std::string const& source = sf->GetFullPath(); - cmSourceGroup* sourceGroup = mf->FindSourceGroup(source, sourceGroups); - cmXCodeObject* pbxgroup = this->CreateOrGetPBXGroup(gtgt, sourceGroup); - std::string key = GetGroupMapKeyFromPath(gtgt, source); - this->GroupMap[key] = pbxgroup; + addSourceToGroup(sf->GetFullPath()); } } } -- cgit v0.12 From 428c1e429ffb320b64c19d3da32e0822ff1b1b8d Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 10 Apr 2019 08:04:15 -0400 Subject: Xcode: Avoid mutating App Bundle targets during generation For `MACOSX_BUNDLE` targets we generate an `Info.plist` automatically and add it to the sources presented to Xcode. Avoid mutating the original target's list of sources to achieve this. Otherwise when we generate the same target again (e.g. in a sub-project's Xcode file) it will look different than the first time and possibly break invariants. Fixes: #19114 --- Source/cmGlobalXCodeGenerator.cxx | 22 ++++++++++++++-------- Tests/BundleTest/BundleSubDir/CMakeLists.txt | 7 +++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index dd6008f..57de60e 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1142,6 +1142,13 @@ bool cmGlobalXCodeGenerator::CreateXCodeTarget( // Add CMakeLists.txt file for user convenience. this->AddXCodeProjBuildRule(gtgt, classes); + // 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); + classes.push_back(sf); + } + std::sort(classes.begin(), classes.end(), cmSourceFilePathCompare()); gtgt->ComputeObjectMapping(); @@ -2883,14 +2890,6 @@ bool cmGlobalXCodeGenerator::CreateGroups( this->GroupMap[key] = pbxgroup; }; - // add the soon to be generated Info.plist file as a source for a - // MACOSX_BUNDLE file - if (gtgt->GetPropertyAsBool("MACOSX_BUNDLE")) { - std::string plist = this->ComputeInfoPListLocation(gtgt); - mf->GetOrCreateSource(plist, true); - gtgt->AddSource(plist); - } - // Put cmSourceFile instances in proper groups: for (auto const& si : gtgt->GetAllConfigSources()) { cmSourceFile const* sf = si.Source; @@ -2909,6 +2908,13 @@ bool cmGlobalXCodeGenerator::CreateGroups( cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource(listfile); 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); + addSourceToGroup(sf->GetFullPath()); + } } } return true; diff --git a/Tests/BundleTest/BundleSubDir/CMakeLists.txt b/Tests/BundleTest/BundleSubDir/CMakeLists.txt index 43c366a..2f7f2c4 100644 --- a/Tests/BundleTest/BundleSubDir/CMakeLists.txt +++ b/Tests/BundleTest/BundleSubDir/CMakeLists.txt @@ -1,3 +1,5 @@ +project(BundleSubDir) + add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist" COMMAND /bin/cp @@ -34,3 +36,8 @@ install(TARGETS SecondBundle DESTINATION Applications) # bundle does not respect the name. Also the executable will not be found by # the test driver if this does not work. set_target_properties(SecondBundle PROPERTIES OUTPUT_NAME SecondBundleExe) + +# Express one app bundle in terms of another's SOURCES to verify that +# the generators do not expose the Info.plist of one to the other. +add_executable(SubdirBundle1 MACOSX_BUNDLE EXCLUDE_FROM_ALL ../BundleTest.cxx) +add_executable(SubdirBundle2 MACOSX_BUNDLE EXCLUDE_FROM_ALL $) -- cgit v0.12