Skip to content

Commit f89523b

Browse files
authored
Add another libs folder recursively - for ofxAssimp (#445)
#changelog #filesystem
1 parent 07e7e85 commit f89523b

6 files changed

Lines changed: 125 additions & 105 deletions

File tree

commandLine/src/addons/ofAddon.cpp

Lines changed: 98 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ void ofAddon::parseVariableValue(string variable, string value, bool addToValue,
171171
addonRelPath = addonPath;
172172
}
173173

174+
if (variable == "ADDON_ADDITIONAL_LIBS") {
175+
additionalLibsFolder.emplace_back(value);
176+
return;
177+
}
178+
174179
if(variable == "ADDON_DESCRIPTION"){
175180
addReplaceString(description,value,addToValue);
176181
return;
@@ -376,111 +381,35 @@ void ofAddon::parseConfig(){
376381
}
377382
}
378383

379-
exclude(includePaths,excludeIncludes);
380-
exclude(srcFiles, excludeSources);
381-
exclude(csrcFiles,excludeSources);
382-
exclude(cppsrcFiles,excludeSources);
383-
exclude(objcsrcFiles,excludeSources);
384-
exclude(headersrcFiles,excludeSources);
385-
// exclude(propsFiles, excludeSources);
386-
exclude(frameworks, excludeFrameworks);
387-
exclude(libs,excludeLibs);
388384

389-
ofLogVerbose("ofAddon") << "libs after exclusions " << libs.size();
390-
for(auto & lib: libs){
391-
ofLogVerbose("ofAddon") << lib.path;
392-
}
393385
}
394386

395-
396-
bool ofAddon::fromFS(const fs::path & path, const string & platform){
397-
// alert("ofAddon::fromFS path : " + path.string());
398-
399-
clear();
400-
this->platform = platform;
401-
402-
addonPath = path;
403-
if (isLocalAddon) {
404-
name = path.stem().string();
405-
} else {
406-
name = path.filename().string();
407-
}
408-
409-
if (!fs::exists(path)) {
410-
return false;
411-
}
412-
413-
fs::path srcPath { path / "src" };
414-
if (fs::exists(srcPath)) {
415-
getFilesRecursively(srcPath, srcFiles);
387+
void ofAddon::parseLibsPath(const fs::path & libsPath, const fs::path & parentFolder) {
388+
// alert ("parseLibsPath " + libsPath.string(), 35);
389+
390+
if (!fs::exists(libsPath)) {
391+
// alert("file not found " + libsPath.string(), 35);
392+
return;
416393
}
394+
395+
vector <fs::path> libFiles;
417396

418-
// MARK: srcFiles to fs::path
419-
// not possible today because there are string based exclusion functions
420-
421-
fs::path parentFolder = path.parent_path();
422-
423-
for (auto & s : srcFiles) {
424-
fs::path sFS { s };
425-
fs::path folder;
426-
if (isLocalAddon) {
427-
// folder = sFS.parent_path();
428-
// folder = fs::path { "local_addons" } / sFS.parent_path().filename();
429-
folder = fs::path { "local_addons" } / fs::relative(sFS.parent_path(), parentFolder);
430-
// alert ("isLocal folder=" + folder.string(), 36);
431-
} else {
432-
sFS = fixPath(s);
433-
s = sFS.string();
434-
folder = fs::relative(sFS.parent_path(), getOFRoot());
435-
}
436-
filesToFolders[s] = folder.string();
397+
getLibsRecursively(libsPath, libFiles, libs, platform);
398+
if (platform == "osx" || platform == "ios"){
399+
getFrameworksRecursively(libsPath, frameworks, platform);
437400
}
438-
439-
if (platform == "vs" || platform == "msys2") {
440-
// here addonPath is the same as path.
441-
getPropsRecursively(addonPath, propsFiles, platform);
401+
402+
if (platform == "vs" || platform == "msys2"
403+
|| platform == "vscode"
404+
|| platform == "linux"
405+
|| platform == "linux64"
406+
|| platform == "linuxarmv6l"
407+
|| platform == "linuxarmv7l"
408+
|| platform == "linuxaarch64"
409+
) {
410+
getDllsRecursively(libsPath, dllsToCopy, platform);
442411
}
443412

444-
// TODO: Remove comments
445-
// int i = 0;
446-
// for (auto & s : propsFiles) {
447-
// fs::path sFS { s };
448-
// fs::path folder;
449-
// if (isLocalAddon) {
450-
// folder = sFS.parent_path();
451-
// } else {
452-
// folder = fs::relative(sFS.parent_path(), getOFRoot());
453-
// }
454-
// cout << s << endl;
455-
// cout << folder << endl;
456-
// propsFiles[i] = folder;
457-
// i++;
458-
// }
459-
460-
fs::path libsPath = path / "libs";
461-
vector < fs::path > libFiles;
462-
463-
// alert ("libsPath " + libsPath.string());
464-
if (fs::exists(libsPath)) {
465-
// alert ("exists");
466-
getLibsRecursively(libsPath, libFiles, libs, platform);
467-
if (platform == "osx" || platform == "ios"){
468-
getFrameworksRecursively(libsPath, frameworks, platform);
469-
470-
471-
}
472-
// if(platform == "vs" || platform == "msys2"){
473-
if(platform == "vs" || platform == "msys2"
474-
|| platform == "vscode"
475-
|| platform == "linux"
476-
|| platform == "linux64"
477-
|| platform == "linuxarmv6l"
478-
|| platform == "linuxarmv7l"
479-
|| platform == "linuxaarch64"
480-
){
481-
getDllsRecursively(libsPath, dllsToCopy, platform);
482-
}
483-
}
484413

485414
// TODO: this is not needed even if it is local addon but project is outside OF root path
486415
// Absolute paths will be used in this case too.
@@ -493,7 +422,6 @@ bool ofAddon::fromFS(const fs::path & path, const string & platform){
493422
}
494423
}
495424

496-
// libFiles is fs::path
497425
for (auto & s : libFiles) {
498426
fs::path folder;
499427
if (isLocalAddon) {
@@ -538,9 +466,63 @@ bool ofAddon::fromFS(const fs::path & path, const string & platform){
538466
filesToFolders[f] = folder.string();
539467
}
540468
}
469+
}
470+
471+
bool ofAddon::fromFS(const fs::path & path, const string & platform){
472+
// alert("ofAddon::fromFS path : " + path.string());
473+
474+
clear();
475+
this->platform = platform;
476+
477+
addonPath = path;
478+
if (isLocalAddon) {
479+
name = path.stem().string();
480+
} else {
481+
name = path.filename().string();
482+
}
483+
484+
if (!fs::exists(path)) {
485+
return false;
486+
}
487+
488+
fs::path srcPath { path / "src" };
489+
if (fs::exists(srcPath)) {
490+
getFilesRecursively(srcPath, srcFiles);
491+
}
492+
493+
// MARK: srcFiles to fs::path
494+
// not possible today because there are string based exclusion functions
495+
496+
fs::path parentFolder = path.parent_path();
497+
498+
for (auto & s : srcFiles) {
499+
fs::path sFS { s };
500+
fs::path folder;
501+
if (isLocalAddon) {
502+
folder = fs::path { "local_addons" } / fs::relative(sFS.parent_path(), parentFolder);
503+
} else {
504+
sFS = fixPath(s);
505+
s = sFS.string();
506+
folder = fs::relative(sFS.parent_path(), getOFRoot());
507+
}
508+
filesToFolders[s] = folder.string();
509+
}
541510

511+
if (platform == "vs" || platform == "msys2") {
512+
// here addonPath is the same as path.
513+
getPropsRecursively(addonPath, propsFiles, platform);
514+
}
542515

543516

517+
parseConfig();
518+
519+
fs::path libsPath = path / "libs";
520+
parseLibsPath(libsPath, parentFolder);
521+
522+
for (auto & a : additionalLibsFolder) {
523+
// parseLibsPath(fs::weakly_canonical(path / a), parentFolder);
524+
parseLibsPath((path / a), parentFolder);
525+
}
544526

545527
// paths that are needed for the includes.
546528
std::list < fs::path > paths;
@@ -569,7 +551,24 @@ bool ofAddon::fromFS(const fs::path & path, const string & platform){
569551
includePaths.emplace_back(p.string());
570552
}
571553

572-
parseConfig();
554+
555+
556+
557+
exclude(includePaths, excludeIncludes);
558+
exclude(srcFiles, excludeSources);
559+
exclude(csrcFiles, excludeSources);
560+
exclude(cppsrcFiles, excludeSources);
561+
exclude(objcsrcFiles, excludeSources);
562+
exclude(headersrcFiles, excludeSources);
563+
// exclude(propsFiles, excludeSources);
564+
exclude(frameworks, excludeFrameworks);
565+
exclude(libs, excludeLibs);
566+
567+
ofLogVerbose("ofAddon") << "libs after exclusions " << libs.size();
568+
569+
for (auto & lib: libs) {
570+
ofLogVerbose("ofAddon") << lib.path;
571+
}
573572

574573
return true;
575574
}

commandLine/src/addons/ofAddon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ class ofAddon {
110110
ofAddon();
111111

112112
bool fromFS(const fs::path & path, const string & platform);
113+
void parseLibsPath(const fs::path & path, const fs::path & parentFolder);
114+
vector <fs::path> additionalLibsFolder;
115+
113116
// void fromXML(string installXmlName);
114117
void clear();
115118

commandLine/src/projects/baseProject.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ bool baseProject::create(const fs::path & path, string templateName){
122122
// alert("path " + path.string());
123123
// alert("path " + fs::weakly_canonical(fs::absolute(path)).string());
124124

125+
// FIXME: Rewrite here
125126
if (ofIsPathInPath(fs::absolute(path), getOFRoot())) {
126127
// alert ("bMakeRelative true", 35);
127128
bMakeRelative = true;

commandLine/src/projects/baseProject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#define PG_VERSION "28"
3+
#define PG_VERSION "30"
44

55
#include "ofAddon.h"
66
#include "ofFileUtils.h"
@@ -48,6 +48,7 @@ class baseProject {
4848
virtual void addInclude(std::string includeName) = 0;
4949
virtual void addLibrary(const LibraryBinary & lib) = 0;
5050

51+
// FIXME: change some strings to const &
5152
virtual void addLDFLAG(std::string ldflag, LibType libType = RELEASE_LIB){}
5253
virtual void addCFLAG(std::string cflag, LibType libType = RELEASE_LIB){} // C_FLAGS
5354
virtual void addCPPFLAG(std::string cppflag, LibType libType = RELEASE_LIB){} // CXX_FLAGS

commandLine/src/projects/visualStudioProject.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ void visualStudioProject::addSrc(const fs::path & srcFile, const fs::path & fold
257257
}
258258

259259
void visualStudioProject::addInclude(string includeName){
260-
// alert ("addInclude " + includeName, 35);
261260
fixSlashOrder(includeName);
261+
// alert ("addInclude " + includeName, 35);
262262

263263
pugi::xpath_node_set source = doc.select_nodes("//ClCompile/AdditionalIncludeDirectories");
264264
for (pugi::xpath_node_set::const_iterator it = source.begin(); it != source.end(); ++it){
@@ -274,6 +274,7 @@ void visualStudioProject::addInclude(string includeName){
274274
if (bAdd == true){
275275
strings.emplace_back(includeName);
276276
string includesNew = unsplitString(strings, ";");
277+
// alert ("includesNew " + includesNew);
277278
node.node().first_child().set_value(includesNew.c_str());
278279
}
279280

commandLine/src/utils/Utils.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ void getFoldersRecursively(const fs::path & path, std::vector < fs::path > & fol
210210
}
211211

212212
void getFrameworksRecursively(const fs::path & path, std::vector < string > & frameworks, string platform) {
213+
alert ("getFrameworksRecursively " + path.string(), 34);
213214
if (!fs::exists(path) || !fs::is_directory(path)) return;
214215

215216
for (const auto & f : dirList(path)) {
@@ -222,7 +223,8 @@ void getFrameworksRecursively(const fs::path & path, std::vector < string > & fr
222223
}
223224

224225
void getPropsRecursively(const fs::path & path, std::vector < fs::path > & props, const string & platform) {
225-
// alert("getPropsRecursively " + path.string());
226+
// alert ("getPropsRecursively " + path.string(), 34);
227+
226228
if (!fs::exists(path) || !fs::is_directory(path)) return;
227229

228230
for (const auto & f : dirList(path)) {
@@ -235,7 +237,13 @@ void getPropsRecursively(const fs::path & path, std::vector < fs::path > & props
235237
}
236238

237239
void getDllsRecursively(const fs::path & path, std::vector < string > & dlls, string platform) {
238-
if (!fs::exists(path) || !fs::is_directory(path)) return;
240+
// alert ("getDllsRecursively " + path.string(), 34);
241+
// if (!fs::exists(path) || !fs::is_directory(path)) return;
242+
if (!fs::exists(path) || !fs::is_directory(path)) {
243+
// alert ("not found!");
244+
return;
245+
}
246+
239247

240248
for (const auto & f : dirList(path)) {
241249
if (fs::is_regular_file(f) && (f.extension() == ".dll" || f.extension() == ".so")) {
@@ -245,8 +253,15 @@ void getDllsRecursively(const fs::path & path, std::vector < string > & dlls, st
245253
}
246254

247255
void getLibsRecursively(const fs::path & path, std::vector < fs::path > & libFiles, std::vector < LibraryBinary > & libLibs, string platform, string arch, string target) {
248-
// cout << ">> getLibsRecursively " << path << endl;
249-
if (!fs::exists(path) || !fs::is_directory(path)) return;
256+
// alert ("getLibsRecursively " + path.string(), 34);
257+
// alert ("platform " + platform, 34);
258+
// alert ("arch " + arch, 34);
259+
// alert ("target " + target, 34);
260+
// if (!fs::exists(path) || !fs::is_directory(path)) return;
261+
if (!fs::exists(path) || !fs::is_directory(path)) {
262+
// alert ("not found!");
263+
return;
264+
}
250265

251266
fs::recursive_directory_iterator it { path };
252267
fs::recursive_directory_iterator last { };

0 commit comments

Comments
 (0)