Skip to content

Commit 44fc978

Browse files
authored
Project Generator - xcframeworks, fixed up extra platforms (#471)
1 parent 5984f15 commit 44fc978

8 files changed

Lines changed: 174 additions & 11 deletions

File tree

commandLine/src/addons/ofAddon.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ void ofAddon::parseVariableValue(const string & variable, const string & value,
235235
addReplaceStringVector(frameworks,value,"",addToValue);
236236
}
237237

238+
else if (variable == ADDON_XCFRAMEWORKS) {
239+
addReplaceStringVector(xcframeworks, value, "", addToValue);
240+
}
241+
238242
else if(variable == ADDON_SOURCES){
239243
addReplaceStringVector(srcFiles, value, addonRelPath.string() ,addToValue);
240244
}
@@ -468,6 +472,7 @@ void ofAddon::parseLibsPath(const fs::path & libsPath, const fs::path & parentFo
468472
getLibsRecursively(libsPath, libFiles, libs, platform);
469473
if (platform == "osx" || platform == "ios"){
470474
getFrameworksRecursively(libsPath, frameworks, platform);
475+
getXCFrameworksRecursively(libsPath, frameworks, platform);
471476
}
472477

473478
if (platform == "vs" || platform == "msys2"
@@ -505,10 +510,8 @@ void ofAddon::parseLibsPath(const fs::path & libsPath, const fs::path & parentFo
505510
filesToFolders[s.string()] = folder.string();
506511
}
507512

508-
// FIXME: This is flawed logic, frameworks acquired here will always come from filesystem, config is not yet parsed
509513
// so addons will never be system.
510514
for (const auto & f : frameworks) {
511-
// alert ("addon::fromFS " + f , 35);
512515
// knowing if we are system framework or not is important....
513516
bool bIsSystemFramework = false;
514517
size_t foundUnixPath = f.find('/');
@@ -522,8 +525,6 @@ void ofAddon::parseLibsPath(const fs::path & libsPath, const fs::path & parentFo
522525
; // do we need to do anything here?
523526
} else {
524527
// if addon is local, it is relative to the project folder, and if it is not, it is related to the project folder, ex: addons/ofxSvg
525-
526-
// FIXME:: Cleanup the mess
527528
fs::path rel = fs::relative (f, isLocalAddon ? pathToProject : pathToOF);
528529
fs::path folder = rel.parent_path();
529530

@@ -532,11 +533,22 @@ void ofAddon::parseLibsPath(const fs::path & libsPath, const fs::path & parentFo
532533
folder = fs::path { "local_addons" } / fs::relative(fFS.parent_path(), parentFolder);
533534
}
534535

535-
// alert (f);
536-
// alert (folder.string());
537536
filesToFolders[f] = folder.string();
538537
}
539538
}
539+
540+
for (const auto & f : xcframeworks) {
541+
542+
fs::path rel = fs::relative(f, isLocalAddon ? pathToProject : pathToOF);
543+
fs::path folder = rel.parent_path();
544+
545+
if (isLocalAddon) {
546+
fs::path fFS { f };
547+
folder = fs::path { "local_addons" } / fs::relative(fFS.parent_path(), parentFolder);
548+
}
549+
550+
filesToFolders[f] = folder.string();
551+
}
540552
}
541553

542554
bool ofAddon::fromFS(const fs::path & path, const string & platform){
@@ -636,6 +648,7 @@ bool ofAddon::fromFS(const fs::path & path, const string & platform){
636648
exclude(headersrcFiles, excludeSources);
637649
// exclude(propsFiles, excludeSources);
638650
exclude(frameworks, excludeFrameworks);
651+
exclude(xcframeworks, excludeXCFrameworks);
639652
exclude(libs, excludeLibs);
640653

641654
ofLogVerbose("ofAddon") << "libs after exclusions " << libs.size();

commandLine/src/addons/ofAddon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const string ADDON_DATA = "ADDON_DATA";
7777
// About Env Specific
7878
const string ADDON_PKG_CONFIG_LIBRARIES = "ADDON_PKG_CONFIG_LIBRARIES";
7979
const string ADDON_FRAMEWORKS = "ADDON_FRAMEWORKS";
80+
const string ADDON_XCFRAMEWORKS = "ADDON_XCFRAMEWORKS";
8081
const string ADDON_DLLS_TO_COPY = "ADDON_DLLS_TO_COPY";
8182

8283
const vector<string> AddonProjectVariables = {
@@ -144,6 +145,7 @@ class ofAddon {
144145
vector < string > ldflags;
145146
vector < string > pkgConfigLibs; // linux only
146147
vector < string > frameworks; // osx only
148+
vector <string > xcframeworks; // osx only
147149
vector < string > data;
148150
vector < string > defines;
149151

@@ -185,6 +187,7 @@ class ofAddon {
185187
vector<string> excludeSources;
186188
vector<string> excludeIncludes;
187189
vector<string> excludeFrameworks;
190+
vector<string> excludeXCFrameworks;
188191

189192
fs::path fixPath(const fs::path & path);
190193
};

commandLine/src/projects/xcodeProject.cpp

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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){
587682
void 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

807933
bool xcodeProject::saveProjectFile(){

commandLine/src/projects/xcodeProject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class xcodeProject : public baseProject {
2727
void addDefine(string define, LibType libType = RELEASE_LIB);
2828

2929
void addFramework(const string & name, const fs::path & path, const fs::path & folder);
30+
void addXCFramework(const string & name, const fs::path & path, const fs::path & folder);
3031
void addDylib(const string & name, const fs::path & path, const fs::path & folder);
3132

3233
void addAddon(ofAddon & addon);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#include "LibraryBinary.h"
22

3-
const std::vector<std::string> LibraryBinary::archs{ "x86","Win32","x64","armv7" };
3+
const std::vector<std::string> LibraryBinary::archs { "x86", "Win32", "x64", "armv7", "arm64", "ARM64EC" };
44
const std::vector<std::string> LibraryBinary::targets{ "Debug","Release" };

commandLine/src/utils/LibraryBinary.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//namespace fs = of::filesystem;
88

99
struct LibraryBinary {
10-
// FIXME: FS (and includes)
1110
// fs::path path;
1211
std::string path;
1312
std::string arch;

commandLine/src/utils/Utils.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#ifdef TARGET_WIN32
2525
#include <direct.h>
26+
2627
#define GetCurrentDir _getcwd
2728
#elif defined(TARGET_LINUX)
2829
#include <unistd.h>
@@ -164,8 +165,14 @@ bool isFolderNotCurrentPlatform(const string & folderName, const string & platfo
164165
"ios",
165166
"linux",
166167
"linux64",
168+
"linuxarmv6l",
169+
"linuxarmv7l",
170+
"linuxaarch64"
167171
"android",
168172
"iphone",
173+
"watchos",
174+
"emscripten",
175+
"visionos",
169176
};
170177
}
171178

@@ -197,7 +204,7 @@ void getFoldersRecursively(const fs::path & path, std::vector < fs::path > & fol
197204
// }
198205

199206
// TODO: disable recursion pending... it is not recursive yet.
200-
if (path.extension() != ".framework") {
207+
if ((path.extension() != ".framework") || (path.extension() != ".xcframework")) {
201208
for (const auto & entry : fs::directory_iterator(path)) {
202209
auto f = entry.path();
203210
if (f.filename().c_str()[0] == '.') continue; // avoid hidden files .DS_Store .vscode .git etc
@@ -222,6 +229,19 @@ void getFrameworksRecursively(const fs::path & path, std::vector < string > & fr
222229
}
223230
}
224231

232+
void getXCFrameworksRecursively(const fs::path & path, std::vector<string> & frameworks, string platform) {
233+
alert("getXCFrameworksRecursively " + path.string(), 34);
234+
if (!fs::exists(path) || !fs::is_directory(path)) return;
235+
236+
for (const auto & f : dirList(path)) {
237+
if (fs::is_directory(f)) {
238+
if (f.extension() == ".xcframework") {
239+
frameworks.emplace_back(f.string());
240+
}
241+
}
242+
}
243+
}
244+
225245
void getPropsRecursively(const fs::path & path, std::vector < fs::path > & props, const string & platform) {
226246
// alert ("getPropsRecursively " + path.string(), 34);
227247

@@ -271,7 +291,7 @@ void getLibsRecursively(const fs::path & path, std::vector < fs::path > & libFil
271291

272292
if (fs::is_directory(f)) {
273293
// on osx, framework is a directory, let's not parse it....
274-
if (f.extension() == ".framework") {
294+
if ((f.extension() == ".framework") || (f.extension() == ".xcframework")) {
275295
it.disable_recursion_pending();
276296
continue;
277297
} else {
@@ -301,7 +321,7 @@ void getLibsRecursively(const fs::path & path, std::vector < fs::path > & libFil
301321
}
302322
}
303323

304-
if (ext == ".a" || ext == ".lib" || ext == ".dylib" || ext == ".so" ||
324+
if (ext == ".a" || ext == ".lib" || ext == ".dylib" || ext == ".so" || ext == ".xcframework" ||
305325
(ext == ".dll" && platform != "vs")){
306326
if (platformFound){
307327
// libLibs.emplace_back( f, arch, target );

commandLine/src/utils/Utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void getFilesRecursively(const fs::path & path, std::vector < string > & fileNam
6868
void getFilesRecursively(const fs::path & path, std::vector < fs::path > & fileNames);
6969
void getLibsRecursively(const fs::path & path, std::vector < fs::path > & libFiles, std::vector < LibraryBinary > & libLibs, string platform = "", string arch = "", string target = "");
7070
void getFrameworksRecursively(const fs::path & path, std::vector < string > & frameworks, string platform = "" );
71+
void getXCFrameworksRecursively(const fs::path & path, std::vector<string> & frameworks, string platform = "");
7172
void getPropsRecursively(const fs::path & path, std::vector < fs::path > & props, const string & platform);
7273
void getDllsRecursively(const fs::path & path, std::vector < string > & dlls, string platform);
7374

0 commit comments

Comments
 (0)