@@ -583,6 +583,101 @@ void xcodeProject::addFramework(const string & name, const fs::path & path, cons
583583}
584584
585585
586+ void xcodeProject::addXCFramework (const string & name, const fs::path & path, const fs::path & folder) {
587+ // alert( "xcodeProject::addFramework " + name + " : " + path.string() + " : " + folder.string() , 33);
588+
589+ // cout << "xcodeProject::addFramework " << name << " : " << path << " : " << folder << endl;
590+ // name = name of the framework
591+ // path = the full path (w name) of this framework
592+ // folder = the path in the addon (in case we want to add this to the file browser -- we don't do that for system libs);
593+
594+ // -----------------------------------------------------------------
595+ // based on the extension make some choices about what to do:
596+ // -----------------------------------------------------------------
597+
598+ // -----------------------------------------------------------------
599+ // (A) make a FILE REF
600+ // -----------------------------------------------------------------
601+
602+ string UUID = generateUUID (name);
603+
604+ // encoding may be messing up for xcframeworks... so I switched to a pbx file ref without encoding fields
605+ // commands.emplace_back("Add :objects:"+UUID+":fileEncoding string 4");
606+
607+ commands.emplace_back (" # ----- addXCFramework name=" + name + " path=" + path.string () + " folder=" + folder.string ());
608+ commands.emplace_back (" Add :objects:" + UUID + " :name string " + name);
609+ commands.emplace_back (" Add :objects:" + UUID + " :path string " + path.string ());
610+ commands.emplace_back (" Add :objects:" + UUID + " :isa string PBXFileReference" );
611+ commands.emplace_back (" Add :objects:" + UUID + " :lastKnownFileType string wrapper.framework" );
612+ // commands.emplace_back("Add :objects:"+UUID+":sourceTree string <group>");
613+ commands.emplace_back (" Add :objects:" + UUID + " :sourceTree string SOURCE_ROOT" );
614+
615+ commands.emplace_back (" # ----- addXCFramework - add to build phase" );
616+ string buildUUID = generateUUID (name + " -build" );
617+ commands.emplace_back (" Add :objects:" + buildUUID + " :isa string PBXBuildFile" );
618+ commands.emplace_back (" Add :objects:" + buildUUID + " :fileRef string " + UUID);
619+
620+ // new - code sign frameworks on copy
621+ commands.emplace_back (" # ----- addXCFramework - sign on copy" );
622+
623+ commands.emplace_back (" Add :objects:" + buildUUID + " :settings:ATTRIBUTES array" );
624+ commands.emplace_back (" Add :objects:" + buildUUID + " :settings:ATTRIBUTES: string CodeSignOnCopy" );
625+
626+ // this now adds the recently created object UUID to its parent folder
627+ string folderUUID = getFolderUUID (folder, false );
628+ commands.emplace_back (" # ----- addXCFramework - add to parent folder : " + folder.string ());
629+ commands.emplace_back (" Add :objects:" + folderUUID + " :children: string " + UUID);
630+
631+ // commands.emplace_back("Add :objects:"+frameworksUUID+":children array");
632+ // commands.emplace_back("Add :objects:"+frameworksUUID+":children: string " + buildUUID);
633+
634+ // we add the second to a final build phase for copying the framework into app. we need to make sure we *don't* do this for system frameworks
635+
636+ string buildUUID2;
637+
638+ // maybe check if path exists in path
639+ if (!folder.empty ()) {
640+
641+ buildUUID2 = generateUUID (name + " -build2" );
642+ commands.emplace_back (" Add :objects:" + buildUUID2 + " :fileRef string " + UUID);
643+ commands.emplace_back (" Add :objects:" + buildUUID2 + " :isa string PBXBuildFile" );
644+
645+ // new - code sign frameworks on copy
646+ commands.emplace_back (" Add :objects:" + buildUUID2 + " :settings:ATTRIBUTES array" );
647+ commands.emplace_back (" Add :objects:" + buildUUID2 + " :settings:ATTRIBUTES: string CodeSignOnCopy" );
648+
649+ // UUID hardcoded para PBXCopyFilesBuildPhase
650+ // FIXME: hardcoded - this is the same for the next fixme. so maybe a clearer ident can make things better here.
651+ commands.emplace_back (" Add :objects:E4C2427710CC5ABF004149E2:files: string " + buildUUID2);
652+ }
653+
654+ commands.emplace_back (" # ----- XCFRAMEWORK_SEARCH_PATHS" );
655+
656+ fs::path parentFolder { path.parent_path () };
657+ // alert ("parentFolder " + parentFolder.string() );
658+
659+ for (auto & c : buildConfigs) {
660+ commands.emplace_back (" Add :objects:" + c + " :buildSettings:FRAMEWORK_SEARCH_PATHS: string " + parentFolder.string ());
661+ }
662+
663+ if (!folder.empty ()) {
664+ // add it to the linking phases...
665+ // PBXFrameworksBuildPhase
666+ // https://www.rubydoc.info/gems/xcodeproj/Xcodeproj/Project/Object/PBXFrameworksBuildPhase
667+ // The phase responsible on linking with frameworks. Known as ‘Link Binary With Libraries` in the UI.
668+
669+ // This is what was missing. a reference in root objects to the framework, so we can add the reference to PBXFrameworksBuildPhase
670+ auto tempUUID = generateUUID (name + " -InFrameworks" );
671+ commands.emplace_back (" Add :objects:" + tempUUID + " :fileRef string " + UUID);
672+ commands.emplace_back (" Add :objects:" + tempUUID + " :isa string PBXBuildFile" );
673+
674+ commands.emplace_back (" # --- PBXFrameworksBuildPhase" );
675+ commands.emplace_back (" Add :objects:E4B69B590A3A1756003C02F2:files: string " + tempUUID);
676+ }
677+
678+ }
679+
680+
586681// void xcodeProject::addDylib(string name, string path){
587682void xcodeProject::addDylib (const string & name, const fs::path & path, const fs::path & folder){
588683// alert( "xcodeProject::addDylib " + name + " : " + path.string() , 33);
@@ -802,6 +897,37 @@ void xcodeProject::addAddon(ofAddon & addon){
802897 }
803898 }
804899 }
900+
901+
902+ for (auto & f : addon.xcframeworks ) {
903+ // alert ("xcodeproj addon.xcframeworks : " + f);
904+ ofLogVerbose () << " adding addon xcframeworks: " << f;
905+
906+ size_t found = f.find (' /' );
907+ if (found == string::npos) {
908+ fs::path folder = fs::path { " addons" } / addon.name / " xcframeworks" ;
909+ // fs::path folder = addon.filesToFolders[f];
910+
911+ if (addon.isLocalAddon ) {
912+ folder = addon.addonPath / " xcframeworks" ;
913+ }
914+ addXCFramework (f + " .framework" ,
915+ " /System/Library/Frameworks/" + f + " .framework" ,
916+ folder);
917+
918+ } else {
919+ if (ofIsStringInString (f, " /System/Library" )) {
920+ vector<string> pathSplit = ofSplitString (f, " /" );
921+ addFramework (pathSplit[pathSplit.size () - 1 ],
922+ f,
923+ " addons/" + addon.name + " /frameworks" );
924+
925+ } else {
926+ vector<string> pathSplit = ofSplitString (f, " /" );
927+ addFramework (pathSplit[pathSplit.size () - 1 ], f, addon.filesToFolders [f]);
928+ }
929+ }
930+ }
805931}
806932
807933bool xcodeProject::saveProjectFile (){
0 commit comments