Skip to content

Commit

Permalink
add props support (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
gumilastik authored and arturoc committed Dec 14, 2018
1 parent 91a13cb commit 31a0b6f
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 25 deletions.
28 changes: 25 additions & 3 deletions ofxProjectGenerator/src/addons/ofAddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,12 @@ void ofAddon::parseConfig(){
}

exclude(includePaths,excludeIncludes);
exclude(srcFiles,excludeSources);
exclude(srcFiles, excludeSources);
exclude(csrcFiles,excludeSources);
exclude(cppsrcFiles,excludeSources);
exclude(objcsrcFiles,excludeSources);
exclude(headersrcFiles,excludeSources);
exclude(propsFiles, excludeSources);
exclude(libs,excludeLibs);

ofLogVerbose("ofAddon") << "libs after exclusions " << libs.size();
Expand Down Expand Up @@ -481,7 +482,27 @@ void ofAddon::fromFS(string path, string platform){
}


string libsPath = ofFilePath::join(path, "/libs");
if (platform == "vs" || platform == "msys2") {
getPropsRecursively(addonPath, propsFiles, platform);
}

for (int i = 0; i < (int)propsFiles.size(); i++) {
propsFiles[i].erase(propsFiles[i].begin(), propsFiles[i].begin() + containedPath.length());
int end = propsFiles[i].rfind(std::filesystem::path("/").make_preferred().string());
int init = 0;
string folder;
if (!isLocalAddon) {
folder = propsFiles[i].substr(init, end);
}
else {
init = propsFiles[i].find(name);
folder = ofFilePath::join("local_addons", propsFiles[i].substr(init, end - init));
}
propsFiles[i] = prefixPath + propsFiles[i];
}


string libsPath = ofFilePath::join(path, "/libs");
vector < string > libFiles;


Expand Down Expand Up @@ -659,7 +680,8 @@ void ofAddon::fromFS(string path, string platform){
void ofAddon::clear(){
filesToFolders.clear();
srcFiles.clear();
libs.clear();
propsFiles.clear();
libs.clear();
includePaths.clear();
name.clear();
}
3 changes: 2 additions & 1 deletion ofxProjectGenerator/src/addons/ofAddon.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class ofAddon {
std::vector < std::string > cppsrcFiles;
std::vector < std::string > headersrcFiles;
std::vector < std::string > objcsrcFiles;
std::vector < LibraryBinary > libs;
std::vector < std::string > propsFiles;
std::vector < LibraryBinary > libs;
std::vector < std::string > dllsToCopy;
std::vector < std::string > includePaths;

Expand Down
39 changes: 26 additions & 13 deletions ofxProjectGenerator/src/projects/visualStudioProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,23 +265,31 @@ void addLibraryName(const pugi::xpath_node_set & nodes, std::string libName) {
}
}

void visualStudioProject::addLibrary(const LibraryBinary & lib){
void visualStudioProject::addProps(std::string propsFile){
pugi::xpath_node_set items = doc.select_nodes("//ImportGroup");
for (int i = 0; i < items.size(); i++) {
pugi::xml_node additionalOptions;
items[i].node().append_child("Import").append_attribute("Project").set_value(propsFile.c_str());
}
}

void visualStudioProject::addLibrary(const LibraryBinary & lib) {
auto libraryName = lib.path;
fixSlashOrder(libraryName);
fixSlashOrder(libraryName);

// ok first, split path and library name.
size_t found = libraryName.find_last_of("\\");
std::string libFolder = libraryName.substr(0,found);
std::string libName = libraryName.substr(found+1);
// ok first, split path and library name.
size_t found = libraryName.find_last_of("\\");
std::string libFolder = libraryName.substr(0, found);
std::string libName = libraryName.substr(found + 1);

std::string libBaseName;
std::string libExtension;
std::string libBaseName;
std::string libExtension;

splitFromLast( libName, ".", libBaseName, libExtension );
splitFromLast(libName, ".", libBaseName, libExtension);

// ---------| invariant: libExtension is `lib`

// paths for libraries
// paths for libraries
std::string linkPath;
if (!lib.target.empty() && !lib.arch.empty()) {
linkPath = "//ItemDefinitionGroup[contains(@Condition,'" + lib.target + "') and contains(@Condition,'" + lib.arch + "')]/Link/";
Expand All @@ -295,13 +303,13 @@ void visualStudioProject::addLibrary(const LibraryBinary & lib){
else {
linkPath = "//ItemDefinitionGroup/Link/";
}

if (!libFolder.empty()) {
pugi::xpath_node_set addlLibsDir = doc.select_nodes((linkPath + "AdditionalLibraryDirectories").c_str());
addLibraryPath(addlLibsDir, libFolder);
}
pugi::xpath_node_set addlDeps = doc.select_nodes((linkPath + "AdditionalDependencies").c_str());

pugi::xpath_node_set addlDeps = doc.select_nodes((linkPath + "AdditionalDependencies").c_str());
addLibraryName(addlDeps, libName);

ofLogVerbose() << "adding lib path " << libFolder;
Expand Down Expand Up @@ -392,6 +400,11 @@ void visualStudioProject::addAddon(ofAddon & addon){
addInclude(addon.includePaths[i]);
}

for (auto & props : addon.propsFiles) {
ofLogVerbose() << "adding addon props: " << props;
addProps(props);
}

for(auto & lib: addon.libs){
ofLogVerbose() << "adding addon libs: " << lib.path;
addLibrary(lib);
Expand Down
5 changes: 3 additions & 2 deletions ofxProjectGenerator/src/projects/visualStudioProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class visualStudioProject : public baseProject {
bool saveProjectFile();

void addSrc(std::string srcFile, std::string folder, SrcType type=DEFAULT);
void addInclude(std::string includeName);
void addLibrary(const LibraryBinary & lib);
void addInclude(std::string includeName);
void addProps(std::string propsFile);
void addLibrary(const LibraryBinary & lib);
void addCFLAG(std::string cflag, LibType libType = RELEASE_LIB); // C
void addCPPFLAG(std::string cppflag, LibType libType = RELEASE_LIB); // C++
void addDefine(std::string define, LibType libType = RELEASE_LIB);
Expand Down
33 changes: 28 additions & 5 deletions ofxProjectGenerator/src/utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,40 @@ void getFrameworksRecursively( const std::string & path, std::vector < std::stri



void getDllsRecursively( const std::string & path, std::vector < std::string > & dlls, std::string platform){
void getPropsRecursively(const std::string & path, std::vector < std::string > & props, std::string platform) {
ofDirectory dir;
dir.listDir(path);

for (auto & temp: dir){
if (temp.isDirectory()){
for (auto & temp : dir) {
if (temp.isDirectory()) {
getPropsRecursively(temp.path(), props, platform);
}
else {
std::string ext = "";
std::string first = "";
splitFromLast(temp.path(), ".", first, ext);
if (ext == "props") {
props.push_back(temp.path());
}
}

}
}


void getDllsRecursively(const std::string & path, std::vector < std::string > & dlls, std::string platform) {
ofDirectory dir;
dir.listDir(path);

for (auto & temp : dir) {
if (temp.isDirectory()) {
getDllsRecursively(temp.path(), dlls, platform);
}else{
}
else {
std::string ext = "";
std::string first = "";
splitFromLast(temp.path(), ".", first, ext);
if (ext == "dll"){
if (ext == "dll") {
dlls.push_back(temp.path());
}
}
Expand All @@ -305,6 +327,7 @@ void getDllsRecursively( const std::string & path, std::vector < std::string > &




void getLibsRecursively(const std::string & path, std::vector < std::string > & libFiles, std::vector < LibraryBinary > & libLibs, std::string platform, std::string arch, std::string target){
ofDirectory dir;
dir.listDir(path);
Expand Down
3 changes: 2 additions & 1 deletion ofxProjectGenerator/src/utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ void getFoldersRecursively(const std::string & path, std::vector < std::string >
void getFilesRecursively(const std::string & path, std::vector < std::string > & fileNames);
void getLibsRecursively(const std::string & path, std::vector < std::string > & libFiles, std::vector < LibraryBinary > & libLibs, std::string platform = "", std::string arch = "", std::string target = "");
void getFrameworksRecursively( const std::string & path, std::vector < std::string > & frameworks, std::string platform = "" );
void getDllsRecursively( const std::string & path, std::vector < std::string > & dlls, std::string platform);
void getPropsRecursively(const std::string & path, std::vector < std::string > & props, std::string platform);
void getDllsRecursively(const std::string & path, std::vector < std::string > & dlls, std::string platform);


void splitFromLast(std::string toSplit, std::string deliminator, std::string & first, std::string & second);
Expand Down

0 comments on commit 31a0b6f

Please sign in to comment.