Skip to content

Commit 4f88f67

Browse files
committed
Xcode fixes for copy/add for known and used types. (.modulemap. .bundle, .tdb, .swift, .plist)
Swift added set flagged with c++ swift interop 5.9 (C++ can be used) Added auto compile flags for non-arc terms (search for non-arc commands in .mm.cpp.m) Added auto objective-c++ flag for .cpp if obj-c commands Added function for checking file for objc++ VS fixed up exclusions for Apple types for projects / cross xcode kept default type for addSrc flag to disable add phases - test
1 parent d3e7724 commit 4f88f67

File tree

3 files changed

+99
-29
lines changed

3 files changed

+99
-29
lines changed

commandLine/src/projects/visualStudioProject.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,27 @@ void visualStudioProject::addSrc(const fs::path & srcFile, const fs::path & fold
260260
nodeAdded.append_attribute("Include").set_value(srcFile.c_str());
261261
nodeAdded.append_child("Filter").append_child(pugi::node_pcdata).set_value(folder.c_str());*/
262262

263-
} else if (ext == ".storyboard" || ext == ".mm" || ext == ".m" || ext == ".swift" || ext == ".java" || ext == ".kotlin") {
263+
} else if (ext == ".java" || ext == ".kotlin") {
264264
// Do not add files for other platforms
265+
} else if (
266+
ext == ".storyboard" || // Xcode Interface Builder files
267+
ext == ".xib" || // Xcode Interface Builder files
268+
ext == ".xcassets" || // Xcode Asset catalogs
269+
ext == ".xcconfig" || // Xcode build configuration files
270+
ext == ".entitlements" || // Code signing entitlements (Apple-specific)
271+
ext == ".plist" || // Property List files (Info.plist, macOS/iOS config)
272+
ext == ".mm" || // Objective-C++
273+
ext == ".m" || // Objective-C
274+
ext == ".swift" || // Swift language files
275+
ext == ".modulemap" || // Clang module definition (Xcode/Clang-specific)
276+
ext == ".metal" || // Metal Shading Language (Apple GPU API)
277+
ext == ".tbd" || // Text-based dynamic libraries (Apple SDKs)
278+
ext == ".dylib" || // Dynamic libraries (macOS/iOS equivalent of .dll)
279+
ext == ".framework" ||
280+
ext == ".bundle" ||
281+
ext == ".app" ||
282+
ext == ".xcworkspace" ||
283+
ext == ".xcodeproj") {
265284
} else{
266285
appendValue(doc, "ClCompile", "Include", srcFileString);
267286

commandLine/src/projects/xcodeProject.cpp

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,7 @@ void xcodeProject::addSrc(const fs::path & srcFile, const fs::path & folder, Src
420420
fp.addToBuildPhase = true;
421421
fp.isSrc = true;
422422

423-
// if( type == DEFAULT ){
424-
if( target == "ios" ){
425-
fp.addToBuildPhase = true;
426-
fp.addToResources = true;
427-
}
423+
if( type == DEFAULT ){
428424

429425
if (ext == ".h" || ext == ".hpp"){
430426
fp.addToBuildPhase = false;
@@ -450,44 +446,93 @@ void xcodeProject::addSrc(const fs::path & srcFile, const fs::path & folder, Src
450446
fp.addToBuildPhase = false;
451447
fp.copyBundleResources = true;
452448
}
449+
else if( ext == ".plist" ){
450+
fp.addToBuildPhase = true;
451+
fp.copyBundleResources = true;
452+
}
453+
else if (ext == ".swift"){
454+
fp.addToBuildPhase = true;
455+
for (auto &c : buildConfigs) {
456+
addCommand("Add :objects:" + c + ":buildSettings:OTHER_SWIFT_FLAGS: string -cxx-interoperability-mode=swift-5.9");
457+
// mark all Swift files as C++ interop available :)
458+
}
459+
}
460+
else if (ext == ".xcassets"){
461+
fp.addToBuildResource = true;
462+
fp.addToResources = true;
463+
}
464+
else if (ext == ".modulemap") {
465+
fp.addToBuildPhase = false;
466+
}
467+
else if (ext == ".bundle") {
468+
fp.addToBuildResource = true;
469+
fp.addToResources = true;
470+
}
471+
else if (ext == ".tbd") {
472+
fp.linkBinaryWithLibraries = true;
473+
}
453474

454475

455-
// }
456-
457-
476+
}
458477
string UUID {
459478
addFile(srcFile, folder, fp)
460479
};
461480

462481
if (ext == ".mm" || ext == ".m") {
463482
addCompileFlagsForMMFile(srcFile);
483+
} else if (ext == ".cpp") {
484+
if (containsObjectiveCPlusPlus(srcFile)) {
485+
addCompileFlagsForMMFile(srcFile);
486+
}
464487
}
465488
}
466489

467490
void xcodeProject::addCompileFlagsForMMFile(const fs::path & srcFile) {
468491

469-
// This requires a moro thorough inspection on how to deal with these files, and determine if these need the -fno-objc-arc flag.
470-
// This flag should be added on a file by file basis, rather than the way it is done below where these are added globally, as such messes up other things.
492+
std::ifstream file(srcFile);
493+
if (!file.is_open()) return;
471494

472-
// std::ifstream file(srcFile);
473-
// std::string line;
474-
// bool containsARCFunctions = false;
475-
//#if __APPLE__
476-
// std::regex arcRegex(R"(\b(alloc|dealloc)\b)");
477-
//
478-
// while (std::getline(file, line)) {
479-
// if (std::regex_search(line, arcRegex)) {
480-
// containsARCFunctions = true;
481-
// break;
482-
// }
483-
// }
484-
//#endif
485-
// if (containsARCFunctions) {
486-
// for (auto & c : buildConfigs) {
487-
// addCommand("Add :objects:"+c+":buildSettings:OTHER_CPLUSPLUSFLAGS: string -fno-objc-arc");
488-
// }
489-
// }
495+
bool requiresNoARC = false;
496+
497+
// Named regex for detecting ARC-related function calls in Objective-C++
498+
const std::regex arcFunctionRegex(R"(\b(alloc|dealloc|retain|release|autorelease)\b)");
499+
500+
for (std::string line; std::getline(file, line); ) {
501+
if (std::regex_search(line, arcFunctionRegex)) {
502+
requiresNoARC = true;
503+
break;
504+
}
505+
}
506+
507+
// Tag file as Objective-C++ in Xcode build settings
508+
for (auto & c : buildConfigs) {
509+
addCommand("Add :objects:" + c + ":buildSettings:OTHER_CPLUSPLUSFLAGS: string -x objective-c++");
510+
511+
if (requiresNoARC) {
512+
addCommand("Add :objects:" + c + ":buildSettings:OTHER_CPLUSPLUSFLAGS: string -fno-objc-arc");
513+
}
514+
}
515+
516+
}
517+
518+
bool xcodeProject::containsObjectiveCPlusPlus(const fs::path &filePath) {
519+
std::ifstream file(filePath);
520+
if (!file.is_open()) return false;
490521

522+
// Objective-C++ specific keywords to check -- this will fix the really hard to debug objc++ linking obiguous
523+
std::vector<std::string> objcKeywords = {
524+
"#import", "@interface", "@implementation", "@property",
525+
"@synthesize", "@end"
526+
};
527+
528+
for (std::string line; std::getline(file, line); ) {
529+
for (const auto &keyword : objcKeywords) {
530+
if (line.find(keyword) != std::string::npos) {
531+
return true;
532+
}
533+
}
534+
}
535+
return false;
491536
}
492537

493538

commandLine/src/projects/xcodeProject.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include "baseProject.h"
44
//#include <unordered_map>
55
#include <map>
6+
#include <fstream>
7+
#include <string>
8+
#include <vector>
9+
#include <regex>
610
using std::string;
711

812
class xcodeProject : public baseProject {
@@ -53,6 +57,8 @@ class xcodeProject : public baseProject {
5357
void addFramework(const fs::path & path, const fs::path & folder, bool isRelativeToSDK = false) override;
5458
void addXCFramework(const fs::path & path, const fs::path & folder);
5559
void addDylib(const fs::path & path, const fs::path & folder);
60+
61+
bool containsObjectiveCPlusPlus(const fs::path &filePath);
5662

5763
void saveScheme();
5864
void renameProject();

0 commit comments

Comments
 (0)