diff --git a/ofxProjectGenerator/src/addons/ofAddon.cpp b/ofxProjectGenerator/src/addons/ofAddon.cpp index 67044030..43430bcb 100644 --- a/ofxProjectGenerator/src/addons/ofAddon.cpp +++ b/ofxProjectGenerator/src/addons/ofAddon.cpp @@ -1,9 +1,9 @@ /* - * ofAddon.cpp - * - * Created on: 28/12/2011 - * Author: arturo - */ +* ofAddon.cpp +* +* Created on: 28/12/2011 +* Author: arturo +*/ #include "ofAddon.h" #include "ofUtils.h" @@ -15,45 +15,45 @@ using namespace std; vector splitStringOnceByLeft(const string &source, const string &delimiter) { - size_t pos = source.find(delimiter); - vector res; - if(pos == string::npos) { - res.push_back(source); - return res; - } - - res.push_back(source.substr(0, pos)); - res.push_back(source.substr(pos + delimiter.length())); - return res; + size_t pos = source.find(delimiter); + vector res; + if (pos == string::npos) { + res.push_back(source); + return res; + } + + res.push_back(source.substr(0, pos)); + res.push_back(source.substr(pos + delimiter.length())); + return res; } -ofAddon::ofAddon(){ - isLocalAddon = false; - pathToProject = "."; - pathToOF = "../../../"; - currentParseState = Unknown; +ofAddon::ofAddon() { + isLocalAddon = false; + pathToProject = "."; + pathToOF = "../../../"; + currentParseState = Unknown; } -ofAddon::ConfigParseState ofAddon::stateFromString(string name){ - if(name=="meta") return Meta; - if(name=="common") return Common; - if(name=="linux64") return Linux64; - if(name=="linux") return Linux; - if(name=="msys2") return MinGW; - if(name=="vs") return VS; - if(name=="linuxarmv6l") return LinuxARMv6; - if(name=="linuxarmv7l") return LinuxARMv7; - if(name=="android/armeabi") return AndroidARMv5; - if(name=="android/armeabi-v7a") return AndroidARMv7; - if(name=="android/x86") return Androidx86; - if(name=="emscripten") return Emscripten; - if(name=="ios") return iOS; - if(name=="osx") return OSX; +ofAddon::ConfigParseState ofAddon::stateFromString(string name) { + if (name == "meta") return Meta; + if (name == "common") return Common; + if (name == "linux64") return Linux64; + if (name == "linux") return Linux; + if (name == "msys2") return MinGW; + if (name == "vs") return VS; + if (name == "linuxarmv6l") return LinuxARMv6; + if (name == "linuxarmv7l") return LinuxARMv7; + if (name == "android/armeabi") return AndroidARMv5; + if (name == "android/armeabi-v7a") return AndroidARMv7; + if (name == "android/x86") return Androidx86; + if (name == "emscripten") return Emscripten; + if (name == "ios") return iOS; + if (name == "osx") return OSX; return Unknown; } -string ofAddon::stateName(ofAddon::ConfigParseState state){ - switch(state){ +string ofAddon::stateName(ofAddon::ConfigParseState state) { + switch (state) { case Meta: return "meta"; case Common: @@ -62,8 +62,8 @@ string ofAddon::stateName(ofAddon::ConfigParseState state){ return "linux"; case Linux64: return "linux64"; - case MinGW: - return "msys2"; + case MinGW: + return "msys2"; case VS: return "vs"; case LinuxARMv6: @@ -89,15 +89,15 @@ string ofAddon::stateName(ofAddon::ConfigParseState state){ } -bool ofAddon::checkCorrectPlatform(ConfigParseState state){ - switch(state){ +bool ofAddon::checkCorrectPlatform(ConfigParseState state) { + switch (state) { case Meta: return true; case Common: return true; case Linux: case Linux64: - case MinGW: + case MinGW: case VS: case LinuxARMv6: case LinuxARMv7: @@ -107,7 +107,7 @@ bool ofAddon::checkCorrectPlatform(ConfigParseState state){ case Emscripten: case iOS: case OSX: - return platform==stateName(state); + return platform == stateName(state); case Unknown: default: return false; @@ -115,14 +115,14 @@ bool ofAddon::checkCorrectPlatform(ConfigParseState state){ } -bool ofAddon::checkCorrectVariable(string variable, ConfigParseState state){ - switch(state){ +bool ofAddon::checkCorrectVariable(string variable, ConfigParseState state) { + switch (state) { case Meta: - return (variable=="ADDON_NAME" || variable=="ADDON_DESCRIPTION" || variable=="ADDON_AUTHOR" || variable=="ADDON_TAGS" || variable=="ADDON_URL"); + return (variable == "ADDON_NAME" || variable == "ADDON_DESCRIPTION" || variable == "ADDON_AUTHOR" || variable == "ADDON_TAGS" || variable == "ADDON_URL"); case Common: case Linux: case Linux64: - case MinGW: + case MinGW: case VS: case LinuxARMv6: case LinuxARMv7: @@ -133,52 +133,54 @@ bool ofAddon::checkCorrectVariable(string variable, ConfigParseState state){ case iOS: case OSX: return (variable == "ADDON_DEPENDENCIES" || variable == "ADDON_INCLUDES" || - variable == "ADDON_CFLAGS" || variable == "ADDON_CPPFLAGS" || - variable == "ADDON_LDFLAGS" || variable == "ADDON_LIBS" || variable == "ADDON_PKG_CONFIG_LIBRARIES" || - variable == "ADDON_FRAMEWORKS" || - variable == "ADDON_SOURCES" || variable == "ADDON_OBJC_SOURCES" || variable == "ADDON_CPP_SOURCES" || variable == "ADDON_HEADER_SOURCES" || - variable == "ADDON_DATA" || - variable == "ADDON_LIBS_EXCLUDE" || variable == "ADDON_SOURCES_EXCLUDE" || variable == "ADDON_INCLUDES_EXCLUDE" || - variable == "ADDON_DLLS_TO_COPY" || - variable == "ADDON_DEFINES"); + variable == "ADDON_CFLAGS" || variable == "ADDON_CPPFLAGS" || + variable == "ADDON_LDFLAGS" || variable == "ADDON_LIBS" || variable == "ADDON_PKG_CONFIG_LIBRARIES" || + variable == "ADDON_FRAMEWORKS" || + variable == "ADDON_SOURCES" || variable == "ADDON_OBJC_SOURCES" || variable == "ADDON_CPP_SOURCES" || variable == "ADDON_HEADER_SOURCES" || + variable == "ADDON_DATA" || + variable == "ADDON_LIBS_EXCLUDE" || variable == "ADDON_SOURCES_EXCLUDE" || variable == "ADDON_INCLUDES_EXCLUDE" || + variable == "ADDON_DLLS_TO_COPY" || + variable == "ADDON_DEFINES"); case Unknown: default: return false; } } -void ofAddon::addReplaceString(string & variable, string value, bool addToVariable){ - if(addToVariable) variable += value; +void ofAddon::addReplaceString(string & variable, string value, bool addToVariable) { + if (addToVariable) variable += value; else variable = value; } -void ofAddon::addReplaceStringVector(std::vector & variable, std::string value, std::string prefix, bool addToVariable){ +void ofAddon::addReplaceStringVector(std::vector & variable, std::string value, std::string prefix, bool addToVariable) { vector values; - if(value.find("\"")!=string::npos){ - values = ofSplitString(value,"\"",true,true); - }else{ - values = ofSplitString(value," ",true,true); + if (value.find("\"") != string::npos) { + values = ofSplitString(value, "\"", true, true); + } + else { + values = ofSplitString(value, " ", true, true); } - if(!addToVariable) variable.clear(); + if (!addToVariable) variable.clear(); Poco::RegularExpression regEX("(?<=\\$\\()[^\\)]*"); - for(int i=0;i<(int)values.size();i++){ - if(values[i]!=""){ - Poco::RegularExpression::Match match; - if(regEX.match(values[i],match)){ - string varName = values[i].substr(match.offset,match.length); - string varValue; - if(varName == "OF_ROOT"){ + for (int i = 0; i<(int)values.size(); i++) { + if (values[i] != "") { + Poco::RegularExpression::Match match; + if (regEX.match(values[i], match)) { + string varName = values[i].substr(match.offset, match.length); + string varValue; + if (varName == "OF_ROOT") { varValue = pathToOF; - }else if(getenv(varName.c_str())){ - varValue = getenv(varName.c_str()); - } - ofStringReplace(values[i],"$("+varName+")",varValue); + } + else if (getenv(varName.c_str())) { + varValue = getenv(varName.c_str()); + } + ofStringReplace(values[i], "$(" + varName + ")", varValue); ofLogVerbose("ofAddon") << "addon config: substituting " << varName << " with " << varValue << " = " << values[i] << endl; - } + } - if(prefix=="" || values[i].find(pathToOF)==0 || ofFilePath::isAbsolute(values[i])) variable.push_back(values[i]); - else variable.push_back(ofFilePath::join(prefix,values[i])); + if (prefix == "" || values[i].find(pathToOF) == 0 || ofFilePath::isAbsolute(values[i])) variable.push_back(values[i]); + else variable.push_back(ofFilePath::join(prefix, values[i])); } } } @@ -200,9 +202,10 @@ void ofAddon::addReplaceStringVector(vector & variable, string va if (regEX.match(values[i], match)) { string varName = values[i].substr(match.offset, match.length); string varValue; - if(varName == "OF_ROOT"){ + if (varName == "OF_ROOT") { varValue = pathToOF; - }else if (getenv(varName.c_str())) { + } + else if (getenv(varName.c_str())) { varValue = getenv(varName.c_str()); } ofStringReplace(values[i], "$(" + varName + ")", varValue); @@ -211,19 +214,20 @@ void ofAddon::addReplaceStringVector(vector & variable, string va if (prefix == "" || values[i].find(pathToOF) == 0 || ofFilePath::isAbsolute(values[i])) { variable.push_back({ values[i], "", "" }); - } else { + } + else { variable.push_back({ ofFilePath::join(prefix, values[i]), "", "" }); } } } } -void ofAddon::parseVariableValue(string variable, string value, bool addToValue, string line, int lineNum){ - if(variable == "ADDON_NAME"){ - if(value!=name){ +void ofAddon::parseVariableValue(string variable, string value, bool addToValue, string line, int lineNum) { + if (variable == "ADDON_NAME") { + if (value != name) { ofLogError() << "Error parsing " << name << " addon_config.mk" << "\n\t\t" - << "line " << lineNum << ": " << line << "\n\t\t" - << "addon name in filesystem " << name << " doesn't match with addon_config.mk " << value; + << "line " << lineNum << ": " << line << "\n\t\t" + << "addon name in filesystem " << name << " doesn't match with addon_config.mk " << value; } return; } @@ -233,96 +237,96 @@ void ofAddon::parseVariableValue(string variable, string value, bool addToValue, if (!isLocalAddon) addonRelPath = ofFilePath::addTrailingSlash(pathToOF) + "addons/" + name; else addonRelPath = addonPath; - if(variable == "ADDON_DESCRIPTION"){ - addReplaceString(description,value,addToValue); + if (variable == "ADDON_DESCRIPTION") { + addReplaceString(description, value, addToValue); return; } - if(variable == "ADDON_AUTHOR"){ - addReplaceString(author,value,addToValue); + if (variable == "ADDON_AUTHOR") { + addReplaceString(author, value, addToValue); return; } - if(variable == "ADDON_TAGS"){ - addReplaceStringVector(tags,value,"",addToValue); + if (variable == "ADDON_TAGS") { + addReplaceStringVector(tags, value, "", addToValue); return; } - if(variable == "ADDON_URL"){ - addReplaceString(url,value,addToValue); + if (variable == "ADDON_URL") { + addReplaceString(url, value, addToValue); return; } - if(variable == "ADDON_DEPENDENCIES"){ - addReplaceStringVector(dependencies,value,"",addToValue); + if (variable == "ADDON_DEPENDENCIES") { + addReplaceStringVector(dependencies, value, "", addToValue); } - if(variable == "ADDON_INCLUDES"){ - addReplaceStringVector(includePaths,value,addonRelPath,addToValue); + if (variable == "ADDON_INCLUDES") { + addReplaceStringVector(includePaths, value, addonRelPath, addToValue); } - if(variable == "ADDON_CFLAGS"){ - addReplaceStringVector(cflags,value,"",addToValue); + if (variable == "ADDON_CFLAGS") { + addReplaceStringVector(cflags, value, "", addToValue); } - if(variable == "ADDON_CPPFLAGS"){ - addReplaceStringVector(cppflags,value,"",addToValue); + if (variable == "ADDON_CPPFLAGS") { + addReplaceStringVector(cppflags, value, "", addToValue); } - if(variable == "ADDON_LDFLAGS"){ - addReplaceStringVector(ldflags,value,"",addToValue); + if (variable == "ADDON_LDFLAGS") { + addReplaceStringVector(ldflags, value, "", addToValue); } - if(variable == "ADDON_LIBS"){ - addReplaceStringVector(libs,value,addonRelPath,addToValue); + if (variable == "ADDON_LIBS") { + addReplaceStringVector(libs, value, addonRelPath, addToValue); } - if(variable == "ADDON_DLLS_TO_COPY"){ - addReplaceStringVector(dllsToCopy,value,"",addToValue); + if (variable == "ADDON_DLLS_TO_COPY") { + addReplaceStringVector(dllsToCopy, value, "", addToValue); } - if(variable == "ADDON_PKG_CONFIG_LIBRARIES"){ - addReplaceStringVector(pkgConfigLibs,value,"",addToValue); + if (variable == "ADDON_PKG_CONFIG_LIBRARIES") { + addReplaceStringVector(pkgConfigLibs, value, "", addToValue); } - if(variable == "ADDON_FRAMEWORKS"){ - addReplaceStringVector(frameworks,value,"",addToValue); + if (variable == "ADDON_FRAMEWORKS") { + addReplaceStringVector(frameworks, value, "", addToValue); } - if(variable == "ADDON_SOURCES"){ - addReplaceStringVector(srcFiles,value,addonRelPath,addToValue); + if (variable == "ADDON_SOURCES") { + addReplaceStringVector(srcFiles, value, addonRelPath, addToValue); } - if(variable == "ADDON_C_SOURCES"){ - addReplaceStringVector(csrcFiles,value,addonRelPath,addToValue); + if (variable == "ADDON_C_SOURCES") { + addReplaceStringVector(csrcFiles, value, addonRelPath, addToValue); } - if(variable == "ADDON_CPP_SOURCES"){ - addReplaceStringVector(cppsrcFiles,value,addonRelPath,addToValue); + if (variable == "ADDON_CPP_SOURCES") { + addReplaceStringVector(cppsrcFiles, value, addonRelPath, addToValue); } - if(variable == "ADDON_HEADER_SOURCES"){ - addReplaceStringVector(headersrcFiles,value,addonRelPath,addToValue); + if (variable == "ADDON_HEADER_SOURCES") { + addReplaceStringVector(headersrcFiles, value, addonRelPath, addToValue); } - if(variable == "ADDON_OBJC_SOURCES"){ - addReplaceStringVector(objcsrcFiles,value,addonRelPath,addToValue); + if (variable == "ADDON_OBJC_SOURCES") { + addReplaceStringVector(objcsrcFiles, value, addonRelPath, addToValue); } - if(variable == "ADDON_DATA"){ - addReplaceStringVector(data,value,"",addToValue); + if (variable == "ADDON_DATA") { + addReplaceStringVector(data, value, "", addToValue); } - if(variable == "ADDON_LIBS_EXCLUDE"){ - addReplaceStringVector(excludeLibs,value,"",addToValue); + if (variable == "ADDON_LIBS_EXCLUDE") { + addReplaceStringVector(excludeLibs, value, "", addToValue); } - if(variable == "ADDON_SOURCES_EXCLUDE"){ - addReplaceStringVector(excludeSources,value,"",addToValue); + if (variable == "ADDON_SOURCES_EXCLUDE") { + addReplaceStringVector(excludeSources, value, "", addToValue); } - if(variable == "ADDON_INCLUDES_EXCLUDE"){ - addReplaceStringVector(excludeIncludes,value,"",addToValue); + if (variable == "ADDON_INCLUDES_EXCLUDE") { + addReplaceStringVector(excludeIncludes, value, "", addToValue); } if (variable == "ADDON_DEFINES") { @@ -330,14 +334,14 @@ void ofAddon::parseVariableValue(string variable, string value, bool addToValue, } } -void ofAddon::exclude(vector & variables, vector exclusions){ - for(auto & exclusion: exclusions){ - ofStringReplace(exclusion,"\\","/"); - ofStringReplace(exclusion,".","\\."); - ofStringReplace(exclusion,"%",".*"); - exclusion =".*"+ exclusion; +void ofAddon::exclude(vector & variables, vector exclusions) { + for (auto & exclusion : exclusions) { + ofStringReplace(exclusion, "\\", "/"); + ofStringReplace(exclusion, ".", "\\."); + ofStringReplace(exclusion, "%", ".*"); + exclusion = ".*" + exclusion; Poco::RegularExpression regExp(exclusion); - variables.erase(std::remove_if(variables.begin(), variables.end(), [&](const string & variable){ + variables.erase(std::remove_if(variables.begin(), variables.end(), [&](const string & variable) { auto forwardSlashedVariable = variable; ofStringReplace(forwardSlashedVariable, "\\", "/"); return regExp.match(forwardSlashedVariable); @@ -346,13 +350,13 @@ void ofAddon::exclude(vector & variables, vector exclusions){ } void ofAddon::exclude(vector & variables, vector exclusions) { - for(auto & exclusion: exclusions){ - ofStringReplace(exclusion,"\\","/"); - ofStringReplace(exclusion,".","\\."); - ofStringReplace(exclusion,"%",".*"); - exclusion =".*"+ exclusion; + for (auto & exclusion : exclusions) { + ofStringReplace(exclusion, "\\", "/"); + ofStringReplace(exclusion, ".", "\\."); + ofStringReplace(exclusion, "%", ".*"); + exclusion = ".*" + exclusion; Poco::RegularExpression regExp(exclusion); - variables.erase(std::remove_if(variables.begin(), variables.end(), [&](const LibraryBinary & variable){ + variables.erase(std::remove_if(variables.begin(), variables.end(), [&](const LibraryBinary & variable) { auto forwardSlashedVariable = variable.path; ofStringReplace(forwardSlashedVariable, "\\", "/"); return regExp.match(forwardSlashedVariable); @@ -360,127 +364,131 @@ void ofAddon::exclude(vector & variables, vector exclusio } } -void ofAddon::parseConfig(){ +void ofAddon::parseConfig() { ofFile addonConfig; - if(isLocalAddon){ - addonConfig.open(ofFilePath::join(ofFilePath::join(pathToProject,addonPath),"addon_config.mk")); - }else{ - addonConfig.open(ofFilePath::join(addonPath,"addon_config.mk")); + if (isLocalAddon) { + addonConfig.open(ofFilePath::join(ofFilePath::join(pathToProject, addonPath), "addon_config.mk")); + } + else { + addonConfig.open(ofFilePath::join(addonPath, "addon_config.mk")); } - if(!addonConfig.exists()) return; + if (!addonConfig.exists()) return; string line, originalLine; int lineNum = 0; - while(addonConfig.good()){ + while (addonConfig.good()) { lineNum++; - std::getline(addonConfig,originalLine); + std::getline(addonConfig, originalLine); line = originalLine; - ofStringReplace(line,"\r",""); - ofStringReplace(line,"\n",""); + ofStringReplace(line, "\r", ""); + ofStringReplace(line, "\n", ""); line = ofTrim(line); // discard comments - if(line[0]=='#' || line == ""){ + if (line[0] == '#' || line == "") { continue; } // found section? - if(line[line.size()-1]==':'){ - ofStringReplace(line,":",""); + if (line[line.size() - 1] == ':') { + ofStringReplace(line, ":", ""); currentParseState = stateFromString(line); - if(currentParseState == Unknown){ + if (currentParseState == Unknown) { ofLogError() << "Error parsing " << name << " addon_config.mk" << "\n\t\t" - << "line " << lineNum << ": " << originalLine << "\n\t\t" - << "sectionName " << stateName(currentParseState) << " not recognized"; + << "line " << lineNum << ": " << originalLine << "\n\t\t" + << "sectionName " << stateName(currentParseState) << " not recognized"; } continue; } // found Variable - if(line.find("=")!=string::npos){ + if (line.find("=") != string::npos) { bool addToValue = false; string variable, value; vector varValue; - if(line.find("+=")!=string::npos){ + if (line.find("+=") != string::npos) { addToValue = true; - varValue = splitStringOnceByLeft(line,"+="); - }else{ + varValue = splitStringOnceByLeft(line, "+="); + } + else { addToValue = false; - varValue = splitStringOnceByLeft(line,"="); + varValue = splitStringOnceByLeft(line, "="); } variable = Poco::trim(varValue[0]); value = Poco::trim(varValue[1]); - if(!checkCorrectPlatform(currentParseState)){ + if (!checkCorrectPlatform(currentParseState)) { continue; } - if(!checkCorrectVariable(variable,currentParseState)){ + if (!checkCorrectVariable(variable, currentParseState)) { ofLogError() << "Error parsing " << name << " addon_config.mk" << "\n\t\t" - << "line " << lineNum << ": " << originalLine << "\n\t\t" - << "variable " << variable << " not recognized for section " << stateName(currentParseState); + << "line " << lineNum << ": " << originalLine << "\n\t\t" + << "variable " << variable << " not recognized for section " << stateName(currentParseState); continue; } parseVariableValue(variable, value, addToValue, originalLine, lineNum); } } - exclude(includePaths,excludeIncludes); + exclude(includePaths, excludeIncludes); exclude(srcFiles, excludeSources); - exclude(csrcFiles,excludeSources); - exclude(cppsrcFiles,excludeSources); - exclude(objcsrcFiles,excludeSources); - exclude(headersrcFiles,excludeSources); + exclude(csrcFiles, excludeSources); + exclude(cppsrcFiles, excludeSources); + exclude(objcsrcFiles, excludeSources); + exclude(headersrcFiles, excludeSources); exclude(propsFiles, excludeSources); - exclude(libs,excludeLibs); + exclude(libs, excludeLibs); ofLogVerbose("ofAddon") << "libs after exclusions " << libs.size(); - for(auto & lib: libs){ + for (auto & lib : libs) { ofLogVerbose("ofAddon") << lib.path; } } -void ofAddon::fromFS(string path, string platform){ - clear(); - this->platform = platform; +void ofAddon::fromFS(string path, string platform) { + clear(); + this->platform = platform; string prefixPath; - string containedPath; - if(isLocalAddon){ - name = std::filesystem::path(path).stem().string(); - addonPath = path; - containedPath = ofFilePath::addTrailingSlash(pathToProject); //we need to add a trailing slash for the erase to work properly - path = ofFilePath::join(pathToProject,path); - }else{ - name = ofFilePath::getFileName(path); - addonPath = path; - containedPath = ofFilePath::addTrailingSlash(getOFRoot()); //we need to add a trailing slash for the erase to work properly - prefixPath = pathToOF; - } - - - string srcPath = ofFilePath::join(path, "/src"); - ofLogVerbose() << "in fromFS, trying src " << srcPath; - if (ofDirectory(srcPath).exists()){ - getFilesRecursively(srcPath, srcFiles); - } - - for(int i=0;i<(int)srcFiles.size();i++){ - srcFiles[i].erase(srcFiles[i].begin(), srcFiles[i].begin()+containedPath.length()); - int end = srcFiles[i].rfind(std::filesystem::path("/").make_preferred().string()); - int init = 0; + string containedPath; + if (isLocalAddon) { + name = std::filesystem::path(path).stem().string(); + addonPath = path; + containedPath = ofFilePath::addTrailingSlash(pathToProject); //we need to add a trailing slash for the erase to work properly + path = ofFilePath::join(pathToProject, path); + } + else { + name = ofFilePath::getFileName(path); + addonPath = path; + containedPath = ofFilePath::addTrailingSlash(getOFRoot()); //we need to add a trailing slash for the erase to work properly + prefixPath = pathToOF; + } + + + string srcPath = ofFilePath::join(path, "/src"); + ofLogVerbose() << "in fromFS, trying src " << srcPath; + if (ofDirectory(srcPath).exists()) { + getFilesRecursively(srcPath, srcFiles); + } + + for (int i = 0; i<(int)srcFiles.size(); i++) { + srcFiles[i].erase(srcFiles[i].begin(), srcFiles[i].begin() + containedPath.length()); + int end = srcFiles[i].rfind(std::filesystem::path("/").make_preferred().string()); + int init = 0; string folder; - if(!isLocalAddon){ - folder = srcFiles[i].substr(init,end); - }else{ - init = srcFiles[i].find(name); - folder = ofFilePath::join("local_addons", srcFiles[i].substr(init,end-init)); - } - srcFiles[i] = prefixPath + srcFiles[i]; - filesToFolders[srcFiles[i]] = folder; - } - + if (!isLocalAddon) { + folder = srcFiles[i].substr(init, end); + } + else { + init = srcFiles[i].find(name); + folder = ofFilePath::join("local_addons", srcFiles[i].substr(init, end - init)); + } + srcFiles[i] = prefixPath + srcFiles[i]; + filesToFolders[srcFiles[i]] = folder; + } + if (platform == "vs" || platform == "msys2") { getPropsRecursively(addonPath, propsFiles, platform); @@ -500,33 +508,33 @@ void ofAddon::fromFS(string path, string platform){ } propsFiles[i] = prefixPath + propsFiles[i]; } - + string libsPath = ofFilePath::join(path, "/libs"); - vector < string > libFiles; + vector < string > libFiles; - if (ofDirectory(libsPath).exists()){ - getLibsRecursively(libsPath, libFiles, libs, platform); + if (ofDirectory(libsPath).exists()) { + getLibsRecursively(libsPath, libFiles, libs, platform); - if (platform == "osx" || platform == "ios"){ - getFrameworksRecursively(libsPath, frameworks, platform); - } + if (platform == "osx" || platform == "ios") { + getFrameworksRecursively(libsPath, frameworks, platform); + } - if(platform == "vs" || platform == "msys2"){ + if (platform == "vs" || platform == "msys2") { getDllsRecursively(libsPath, dllsToCopy, platform); } - } - + } - // I need to add libFiles to srcFiles - for (int i = 0; i < (int)libFiles.size(); i++){ - libFiles[i].erase (libFiles[i].begin(), libFiles[i].begin()+containedPath.length()); + + // I need to add libFiles to srcFiles + for (int i = 0; i < (int)libFiles.size(); i++) { + libFiles[i].erase(libFiles[i].begin(), libFiles[i].begin() + containedPath.length()); //ofLogVerbose() << " libFiles " << libFiles[i]; - int init = 0; - int end = libFiles[i].rfind(std::filesystem::path("/").make_preferred().string()); - if (end > 0){ + int init = 0; + int end = libFiles[i].rfind(std::filesystem::path("/").make_preferred().string()); + if (end > 0) { string folder; if (!isLocalAddon) { folder = libFiles[i].substr(init, end); @@ -535,50 +543,51 @@ void ofAddon::fromFS(string path, string platform){ init = libFiles[i].find(name); folder = ofFilePath::join("local_addons", libFiles[i].substr(init, end - init)); } - libFiles[i] = prefixPath + libFiles[i]; - srcFiles.push_back(libFiles[i]); - filesToFolders[libFiles[i]] = folder; - } - - } - - - - for (int i = 0; i < (int)libs.size(); i++){ - - // does libs[] have any path ? let's fix if so. - int end = libs[i].path.rfind(std::filesystem::path("/").make_preferred().string()); - if (end > 0){ - libs[i].path.erase (libs[i].path.begin(), libs[i].path.begin()+containedPath.length()); - libs[i].path = prefixPath + libs[i].path; - } - - } - - for (int i = 0; i < (int)frameworks.size(); i++){ - - // knowing if we are system framework or not is important.... - - bool bIsSystemFramework = false; - size_t foundUnixPath = frameworks[i].find('/'); - size_t foundWindowsPath = frameworks[i].find('\\'); - if (foundUnixPath==std::string::npos && - foundWindowsPath==std::string::npos){ - bIsSystemFramework = true; // we have no "path" so we are system - } - - if (bIsSystemFramework){ - - ; // do we need to do anything here? - - } else { - - - frameworks[i].erase (frameworks[i].begin(), frameworks[i].begin()+containedPath.length()); - - int init = 0; - int end = frameworks[i].rfind(std::filesystem::path("/").make_preferred().string()); - + libFiles[i] = prefixPath + libFiles[i]; + srcFiles.push_back(libFiles[i]); + filesToFolders[libFiles[i]] = folder; + } + + } + + + + for (int i = 0; i < (int)libs.size(); i++) { + + // does libs[] have any path ? let's fix if so. + int end = libs[i].path.rfind(std::filesystem::path("/").make_preferred().string()); + if (end > 0) { + libs[i].path.erase(libs[i].path.begin(), libs[i].path.begin() + containedPath.length()); + libs[i].path = prefixPath + libs[i].path; + } + + } + + for (int i = 0; i < (int)frameworks.size(); i++) { + + // knowing if we are system framework or not is important.... + + bool bIsSystemFramework = false; + size_t foundUnixPath = frameworks[i].find('/'); + size_t foundWindowsPath = frameworks[i].find('\\'); + if (foundUnixPath == std::string::npos && + foundWindowsPath == std::string::npos) { + bIsSystemFramework = true; // we have no "path" so we are system + } + + if (bIsSystemFramework) { + + ; // do we need to do anything here? + + } + else { + + + frameworks[i].erase(frameworks[i].begin(), frameworks[i].begin() + containedPath.length()); + + int init = 0; + int end = frameworks[i].rfind(std::filesystem::path("/").make_preferred().string()); + string folder; if (!isLocalAddon) { folder = frameworks[i].substr(init, end); @@ -587,61 +596,61 @@ void ofAddon::fromFS(string path, string platform){ init = frameworks[i].find(name); folder = ofFilePath::join("local_addons", frameworks[i].substr(init, end - init)); } - - frameworks[i] = prefixPath + frameworks[i]; - - filesToFolders[frameworks[i]] = folder; + frameworks[i] = prefixPath + frameworks[i]; + + + filesToFolders[frameworks[i]] = folder; + + } - } - - - } + } - // get a unique list of the paths that are needed for the includes. - list < string > paths; - for (int i = 0; i < (int)srcFiles.size(); i++){ - size_t found; - found = srcFiles[i].find_last_of(std::filesystem::path("/").make_preferred().string()); - paths.push_back(srcFiles[i].substr(0,found)); - } - // get every folder in addon/src and addon/libs - vector < string > libFolders; - if(ofDirectory(libsPath).exists()){ - getFoldersRecursively(libsPath, libFolders, platform); - } + // get a unique list of the paths that are needed for the includes. + list < string > paths; + for (int i = 0; i < (int)srcFiles.size(); i++) { + size_t found; + found = srcFiles[i].find_last_of(std::filesystem::path("/").make_preferred().string()); + paths.push_back(srcFiles[i].substr(0, found)); + } + + // get every folder in addon/src and addon/libs + vector < string > libFolders; + if (ofDirectory(libsPath).exists()) { + getFoldersRecursively(libsPath, libFolders, platform); + } - vector < string > srcFolders; - if(ofDirectory(srcPath).exists()){ - getFoldersRecursively(ofFilePath::join(path, "/src"), srcFolders, platform); - } + vector < string > srcFolders; + if (ofDirectory(srcPath).exists()) { + getFoldersRecursively(ofFilePath::join(path, "/src"), srcFolders, platform); + } - for (int i = 0; i < (int)libFolders.size(); i++){ - libFolders[i].erase (libFolders[i].begin(), libFolders[i].begin()+containedPath.length()); - libFolders[i] = prefixPath + libFolders[i]; - paths.push_back(libFolders[i]); - } + for (int i = 0; i < (int)libFolders.size(); i++) { + libFolders[i].erase(libFolders[i].begin(), libFolders[i].begin() + containedPath.length()); + libFolders[i] = prefixPath + libFolders[i]; + paths.push_back(libFolders[i]); + } - for (int i = 0; i < (int)srcFolders.size(); i++){ - srcFolders[i].erase (srcFolders[i].begin(), srcFolders[i].begin()+containedPath.length()); - srcFolders[i] = prefixPath + srcFolders[i]; - paths.push_back(srcFolders[i]); - } + for (int i = 0; i < (int)srcFolders.size(); i++) { + srcFolders[i].erase(srcFolders[i].begin(), srcFolders[i].begin() + containedPath.length()); + srcFolders[i] = prefixPath + srcFolders[i]; + paths.push_back(srcFolders[i]); + } - paths.sort(); - paths.unique(); - for (list::iterator it=paths.begin(); it!=paths.end(); ++it){ - includePaths.push_back(*it); - } + paths.sort(); + paths.unique(); + for (list::iterator it = paths.begin(); it != paths.end(); ++it) { + includePaths.push_back(*it); + } - parseConfig(); + parseConfig(); } @@ -677,11 +686,11 @@ void ofAddon::fromFS(string path, string platform){ //} -void ofAddon::clear(){ - filesToFolders.clear(); - srcFiles.clear(); +void ofAddon::clear() { + filesToFolders.clear(); + srcFiles.clear(); propsFiles.clear(); libs.clear(); - includePaths.clear(); - name.clear(); + includePaths.clear(); + name.clear(); } diff --git a/ofxProjectGenerator/src/addons/ofAddon.h b/ofxProjectGenerator/src/addons/ofAddon.h index b7b1fe8a..18927ccb 100644 --- a/ofxProjectGenerator/src/addons/ofAddon.h +++ b/ofxProjectGenerator/src/addons/ofAddon.h @@ -1,9 +1,9 @@ /* - * ofAddon.h - * - * Created on: 28/12/2011 - * Author: arturo - */ +* ofAddon.h +* +* Created on: 28/12/2011 +* Author: arturo +*/ #ifndef OFADDON_H_ #define OFADDON_H_ @@ -15,91 +15,91 @@ class ofAddon { public: - - ofAddon(); - + + ofAddon(); + void fromFS(std::string path, std::string platform); -// void fromXML(std::string installXmlName); + // void fromXML(std::string installXmlName); void clear(); - // this is source files: + // this is source files: std::map < std::string, std::string > filesToFolders; //the addons has had, for each file, - //sometimes a listing of what folder to put it in, such as "addons/ofxOsc/src" + //sometimes a listing of what folder to put it in, such as "addons/ofxOsc/src" - std::vector < std::string > srcFiles; - std::vector < std::string > csrcFiles; - std::vector < std::string > cppsrcFiles; - std::vector < std::string > headersrcFiles; - std::vector < std::string > objcsrcFiles; + std::vector < std::string > srcFiles; + std::vector < std::string > csrcFiles; + std::vector < std::string > cppsrcFiles; + std::vector < std::string > headersrcFiles; + std::vector < std::string > objcsrcFiles; std::vector < std::string > propsFiles; std::vector < LibraryBinary > libs; - std::vector < std::string > dllsToCopy; - std::vector < std::string > includePaths; - - // From addon_config.mk - std::vector < std::string > dependencies; - std::vector < std::string > cflags; // C_FLAGS - std::vector < std::string > cppflags; // CXX_FLAGS - std::vector < std::string > ldflags; - std::vector < std::string > pkgConfigLibs; // linux only - std::vector < std::string > frameworks; // osx only - std::vector < std::string > data; + std::vector < std::string > dllsToCopy; + std::vector < std::string > includePaths; + + // From addon_config.mk + std::vector < std::string > dependencies; + std::vector < std::string > cflags; // C_FLAGS + std::vector < std::string > cppflags; // CXX_FLAGS + std::vector < std::string > ldflags; + std::vector < std::string > pkgConfigLibs; // linux only + std::vector < std::string > frameworks; // osx only + std::vector < std::string > data; std::vector < std::string > defines; - // metadata - std::string name; - std::string addonPath; - std::string description; - std::string author; - std::vector tags; - std::string url; - - - std::string pathToOF; - std::string pathToProject; - bool isLocalAddon; // set to true if the addon path is realtive to the project instead of in OF/addons/ - - bool operator <(const ofAddon & addon) const{ - return addon.name < name; - } + // metadata + std::string name; + std::string addonPath; + std::string description; + std::string author; + std::vector tags; + std::string url; + + + std::string pathToOF; + std::string pathToProject; + bool isLocalAddon; // set to true if the addon path is realtive to the project instead of in OF/addons/ + + bool operator <(const ofAddon & addon) const { + return addon.name < name; + } private: - enum ConfigParseState{ - Meta, - Common, - Linux, - Linux64, - MinGW, - VS, - LinuxARMv6, - LinuxARMv7, - AndroidARMv5, - AndroidARMv7, + enum ConfigParseState { + Meta, + Common, + Linux, + Linux64, + MinGW, + VS, + LinuxARMv6, + LinuxARMv7, + AndroidARMv5, + AndroidARMv7, Androidx86, Emscripten, - iOS, - OSX, - Unknown - } currentParseState; - - void parseConfig(); - void parseVariableValue(std::string variable, std::string value, bool addToValue, std::string line, int lineNum); - void addReplaceString(std::string & variable, std::string value, bool addToVariable); - void addReplaceStringVector(std::vector & variable, std::string value, std::string prefix, bool addToVariable); + iOS, + OSX, + Unknown + } currentParseState; + + void parseConfig(); + void parseVariableValue(std::string variable, std::string value, bool addToValue, std::string line, int lineNum); + void addReplaceString(std::string & variable, std::string value, bool addToVariable); + void addReplaceStringVector(std::vector & variable, std::string value, std::string prefix, bool addToVariable); void addReplaceStringVector(std::vector & variable, std::string value, std::string prefix, bool addToVariable); - void exclude(std::vector & variable, std::vector exclusions); + void exclude(std::vector & variable, std::vector exclusions); void exclude(std::vector & variable, std::vector exclusions); - ConfigParseState stateFromString(std::string name); - std::string stateName(ConfigParseState state); - bool checkCorrectVariable(std::string variable, ConfigParseState state); - bool checkCorrectPlatform(ConfigParseState state); + ConfigParseState stateFromString(std::string name); + std::string stateName(ConfigParseState state); + bool checkCorrectVariable(std::string variable, ConfigParseState state); + bool checkCorrectPlatform(ConfigParseState state); - std::string platform; + std::string platform; - std::vector excludeLibs; - std::vector excludeSources; - std::vector excludeIncludes; + std::vector excludeLibs; + std::vector excludeSources; + std::vector excludeIncludes; }; #endif /* OFADDON_H_ */ diff --git a/ofxProjectGenerator/src/projects/visualStudioProject.cpp b/ofxProjectGenerator/src/projects/visualStudioProject.cpp index e478e9c7..8a02f646 100644 --- a/ofxProjectGenerator/src/projects/visualStudioProject.cpp +++ b/ofxProjectGenerator/src/projects/visualStudioProject.cpp @@ -334,7 +334,7 @@ void visualStudioProject::addCFLAG(std::string cflag, LibType libType){ if(!additionalOptions){ items[i].node().child("ClCompile").append_child("AdditionalOptions").append_child(pugi::node_pcdata).set_value(cflag.c_str()); }else{ - additionalOptions.set_value((std::string(additionalOptions.value()) + " " + cflag).c_str()); + additionalOptions.first_child().set_value((std::string(additionalOptions.first_child().value()) + " " + cflag).c_str()); } } @@ -357,7 +357,7 @@ void visualStudioProject::addCPPFLAG(std::string cppflag, LibType libType){ if(!additionalOptions){ items[i].node().child("ClCompile").append_child("AdditionalOptions").append_child(pugi::node_pcdata).set_value(cppflag.c_str()); }else{ - additionalOptions.set_value((std::string(additionalOptions.value()) + " " + cppflag).c_str()); + additionalOptions.first_child().set_value((std::string(additionalOptions.first_child().value()) + " " + cppflag).c_str()); } } @@ -371,11 +371,11 @@ void visualStudioProject::addDefine(std::string define, LibType libType) bool found = false; std::string condition(items[i].node().attribute("Condition").value()); if (libType == RELEASE_LIB && condition.find("Debug") != std::string::npos) { - additionalOptions = items[i].node().child("ClCompile").child("AdditionalOptions"); + additionalOptions = items[i].node().child("ClCompile").child("PreprocessorDefinitions"); found = true; } else if (libType == DEBUG_LIB && condition.find("Release") != std::string::npos) { - additionalOptions = items[i].node().child("ClCompile").child("AdditionalOptions"); + additionalOptions = items[i].node().child("ClCompile").child("PreprocessorDefinitions"); found = true; } if (!found) continue; @@ -383,7 +383,7 @@ void visualStudioProject::addDefine(std::string define, LibType libType) items[i].node().child("ClCompile").append_child("PreprocessorDefinitions").append_child(pugi::node_pcdata).set_value(define.c_str()); } else { - additionalOptions.set_value((std::string(additionalOptions.value()) + " " + define).c_str()); + additionalOptions.first_child().set_value((std::string(additionalOptions.first_child().value()) + " " + define).c_str()); } } } @@ -451,6 +451,8 @@ void visualStudioProject::addAddon(ofAddon & addon){ addCFLAG(addon.cflags[i],RELEASE_LIB); addCFLAG(addon.cflags[i],DEBUG_LIB); } + + for(int i=0;i<(int)addon.cppflags.size();i++){ ofLogVerbose() << "adding addon cppflags: " << addon.cppflags[i]; @@ -463,4 +465,5 @@ void visualStudioProject::addAddon(ofAddon & addon){ addDefine(addon.defines[i], RELEASE_LIB); addDefine(addon.defines[i], DEBUG_LIB); } + }