Skip to content

Commit a96a91e

Browse files
authored
Xcode Project - Local Addon with lib src path fixes, include PROJECT_DEFINES as Preprocessor Macros (#705)
* fix xcode local addons with libs leading to invalid paths * generated xcode project respect PROJECT_DEFINES added in the project config.make file
1 parent 8ec466e commit a96a91e

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎commandLine/src/projects/xcodeProject.cpp‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ xcodeProject::xcodeProject(const string & target)
7171
};
7272

7373
bool xcodeProject::createProjectFile() {
74+
// PROJECT_DEFINES is a makefile setting. Xcode needs each value copied
75+
// into GCC_PREPROCESSOR_DEFINITIONS when the project is generated.
76+
for (const auto & line : fileToStrings(projectDir / "config.make")) {
77+
auto config = ofTrim(line);
78+
if (config.empty() || config[0] == '#') continue;
79+
auto eq = config.find('=');
80+
if (eq == string::npos) continue;
81+
auto variable = ofTrim(config.substr(0, eq));
82+
bool append = !variable.empty() && variable.back() == '+';
83+
if (!variable.empty() && (variable.back() == '+' || variable.back() == '?' || variable.back() == ':')) {
84+
variable = ofTrim(variable.substr(0, variable.size() - 1));
85+
}
86+
if (variable != "PROJECT_DEFINES") continue;
87+
if (!append) projectDefines.clear();
88+
for (const auto & define : ofSplitString(ofTrim(config.substr(eq + 1)), " ", true, true)) {
89+
addDefine(define);
90+
}
91+
}
92+
7493
fs::path xcodeProject = projectDir / (projectName + ".xcodeproj");
7594
try {
7695
fs::create_directories(xcodeProject);
@@ -792,6 +811,32 @@ void xcodeProject::addAddonSrcFiles(ofAddon & addon) {
792811
}
793812
}
794813

814+
// Files discovered under addon/libs are stored relative to OF, while Xcode
815+
// resolves local_addons file references from the project SOURCE_ROOT.
816+
void xcodeProject::addAddonCsrcFiles(ofAddon & addon) {
817+
for (const auto & file : addon.csrcFiles) {
818+
addSrc(makeRelative(projectDir, file), addon.filesToFolders.at(file), C);
819+
}
820+
}
821+
822+
void xcodeProject::addAddonCppsrcFiles(ofAddon & addon) {
823+
for (const auto & file : addon.cppsrcFiles) {
824+
addSrc(makeRelative(projectDir, file), addon.filesToFolders.at(file), CPP);
825+
}
826+
}
827+
828+
void xcodeProject::addAddonObjcsrcFiles(ofAddon & addon) {
829+
for (const auto & file : addon.objcsrcFiles) {
830+
addSrc(makeRelative(projectDir, file), addon.filesToFolders.at(file), OBJC);
831+
}
832+
}
833+
834+
void xcodeProject::addAddonHeadersrcFiles(ofAddon & addon) {
835+
for (const auto & file : addon.headersrcFiles) {
836+
addSrc(makeRelative(projectDir, file), addon.filesToFolders.at(file), HEADER);
837+
}
838+
}
839+
795840
//-----------------------------------------------------------------------------------------------
796841
void xcodeProject::addAddonFrameworks(const ofAddon & addon) {
797842
ofLogVerbose("xcodeProject::addAddonFrameworks") << addon.name;

‎commandLine/src/projects/xcodeProject.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class xcodeProject : public baseProject {
4444
// void addAddonXCFrameworks(const ofAddon& addon) override ;
4545
void addAddonLibs(const ofAddon& addon) override;
4646
void addAddonSrcFiles( ofAddon& addon) override;
47+
void addAddonCsrcFiles(ofAddon& addon) override;
48+
void addAddonCppsrcFiles(ofAddon& addon) override;
49+
void addAddonObjcsrcFiles(ofAddon& addon) override;
50+
void addAddonHeadersrcFiles(ofAddon& addon) override;
4751

4852
void addSrc(const fs::path & srcFile, const fs::path & folder, SrcType type=DEFAULT) override;
4953
void addInclude(const fs::path & includeName) override;

0 commit comments

Comments
 (0)