Skip to content

Commit 31a0b6f

Browse files
gumilastikarturoc
authored andcommitted
add props support (#196)
1 parent 91a13cb commit 31a0b6f

6 files changed

Lines changed: 86 additions & 25 deletions

File tree

ofxProjectGenerator/src/addons/ofAddon.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,12 @@ void ofAddon::parseConfig(){
427427
}
428428

429429
exclude(includePaths,excludeIncludes);
430-
exclude(srcFiles,excludeSources);
430+
exclude(srcFiles, excludeSources);
431431
exclude(csrcFiles,excludeSources);
432432
exclude(cppsrcFiles,excludeSources);
433433
exclude(objcsrcFiles,excludeSources);
434434
exclude(headersrcFiles,excludeSources);
435+
exclude(propsFiles, excludeSources);
435436
exclude(libs,excludeLibs);
436437

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

483484

484-
string libsPath = ofFilePath::join(path, "/libs");
485+
if (platform == "vs" || platform == "msys2") {
486+
getPropsRecursively(addonPath, propsFiles, platform);
487+
}
488+
489+
for (int i = 0; i < (int)propsFiles.size(); i++) {
490+
propsFiles[i].erase(propsFiles[i].begin(), propsFiles[i].begin() + containedPath.length());
491+
int end = propsFiles[i].rfind(std::filesystem::path("/").make_preferred().string());
492+
int init = 0;
493+
string folder;
494+
if (!isLocalAddon) {
495+
folder = propsFiles[i].substr(init, end);
496+
}
497+
else {
498+
init = propsFiles[i].find(name);
499+
folder = ofFilePath::join("local_addons", propsFiles[i].substr(init, end - init));
500+
}
501+
propsFiles[i] = prefixPath + propsFiles[i];
502+
}
503+
504+
505+
string libsPath = ofFilePath::join(path, "/libs");
485506
vector < string > libFiles;
486507

487508

@@ -659,7 +680,8 @@ void ofAddon::fromFS(string path, string platform){
659680
void ofAddon::clear(){
660681
filesToFolders.clear();
661682
srcFiles.clear();
662-
libs.clear();
683+
propsFiles.clear();
684+
libs.clear();
663685
includePaths.clear();
664686
name.clear();
665687
}

ofxProjectGenerator/src/addons/ofAddon.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class ofAddon {
3131
std::vector < std::string > cppsrcFiles;
3232
std::vector < std::string > headersrcFiles;
3333
std::vector < std::string > objcsrcFiles;
34-
std::vector < LibraryBinary > libs;
34+
std::vector < std::string > propsFiles;
35+
std::vector < LibraryBinary > libs;
3536
std::vector < std::string > dllsToCopy;
3637
std::vector < std::string > includePaths;
3738

ofxProjectGenerator/src/projects/visualStudioProject.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,23 +265,31 @@ void addLibraryName(const pugi::xpath_node_set & nodes, std::string libName) {
265265
}
266266
}
267267

268-
void visualStudioProject::addLibrary(const LibraryBinary & lib){
268+
void visualStudioProject::addProps(std::string propsFile){
269+
pugi::xpath_node_set items = doc.select_nodes("//ImportGroup");
270+
for (int i = 0; i < items.size(); i++) {
271+
pugi::xml_node additionalOptions;
272+
items[i].node().append_child("Import").append_attribute("Project").set_value(propsFile.c_str());
273+
}
274+
}
275+
276+
void visualStudioProject::addLibrary(const LibraryBinary & lib) {
269277
auto libraryName = lib.path;
270-
fixSlashOrder(libraryName);
278+
fixSlashOrder(libraryName);
271279

272-
// ok first, split path and library name.
273-
size_t found = libraryName.find_last_of("\\");
274-
std::string libFolder = libraryName.substr(0,found);
275-
std::string libName = libraryName.substr(found+1);
280+
// ok first, split path and library name.
281+
size_t found = libraryName.find_last_of("\\");
282+
std::string libFolder = libraryName.substr(0, found);
283+
std::string libName = libraryName.substr(found + 1);
276284

277-
std::string libBaseName;
278-
std::string libExtension;
285+
std::string libBaseName;
286+
std::string libExtension;
279287

280-
splitFromLast( libName, ".", libBaseName, libExtension );
288+
splitFromLast(libName, ".", libBaseName, libExtension);
281289

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

284-
// paths for libraries
292+
// paths for libraries
285293
std::string linkPath;
286294
if (!lib.target.empty() && !lib.arch.empty()) {
287295
linkPath = "//ItemDefinitionGroup[contains(@Condition,'" + lib.target + "') and contains(@Condition,'" + lib.arch + "')]/Link/";
@@ -295,13 +303,13 @@ void visualStudioProject::addLibrary(const LibraryBinary & lib){
295303
else {
296304
linkPath = "//ItemDefinitionGroup/Link/";
297305
}
298-
306+
299307
if (!libFolder.empty()) {
300308
pugi::xpath_node_set addlLibsDir = doc.select_nodes((linkPath + "AdditionalLibraryDirectories").c_str());
301309
addLibraryPath(addlLibsDir, libFolder);
302310
}
303-
304-
pugi::xpath_node_set addlDeps = doc.select_nodes((linkPath + "AdditionalDependencies").c_str());
311+
312+
pugi::xpath_node_set addlDeps = doc.select_nodes((linkPath + "AdditionalDependencies").c_str());
305313
addLibraryName(addlDeps, libName);
306314

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

403+
for (auto & props : addon.propsFiles) {
404+
ofLogVerbose() << "adding addon props: " << props;
405+
addProps(props);
406+
}
407+
395408
for(auto & lib: addon.libs){
396409
ofLogVerbose() << "adding addon libs: " << lib.path;
397410
addLibrary(lib);

ofxProjectGenerator/src/projects/visualStudioProject.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ class visualStudioProject : public baseProject {
1616
bool saveProjectFile();
1717

1818
void addSrc(std::string srcFile, std::string folder, SrcType type=DEFAULT);
19-
void addInclude(std::string includeName);
20-
void addLibrary(const LibraryBinary & lib);
19+
void addInclude(std::string includeName);
20+
void addProps(std::string propsFile);
21+
void addLibrary(const LibraryBinary & lib);
2122
void addCFLAG(std::string cflag, LibType libType = RELEASE_LIB); // C
2223
void addCPPFLAG(std::string cppflag, LibType libType = RELEASE_LIB); // C++
2324
void addDefine(std::string define, LibType libType = RELEASE_LIB);

ofxProjectGenerator/src/utils/Utils.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,40 @@ void getFrameworksRecursively( const std::string & path, std::vector < std::stri
284284

285285

286286

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

291-
for (auto & temp: dir){
292-
if (temp.isDirectory()){
291+
for (auto & temp : dir) {
292+
if (temp.isDirectory()) {
293+
getPropsRecursively(temp.path(), props, platform);
294+
}
295+
else {
296+
std::string ext = "";
297+
std::string first = "";
298+
splitFromLast(temp.path(), ".", first, ext);
299+
if (ext == "props") {
300+
props.push_back(temp.path());
301+
}
302+
}
303+
304+
}
305+
}
306+
307+
308+
void getDllsRecursively(const std::string & path, std::vector < std::string > & dlls, std::string platform) {
309+
ofDirectory dir;
310+
dir.listDir(path);
311+
312+
for (auto & temp : dir) {
313+
if (temp.isDirectory()) {
293314
getDllsRecursively(temp.path(), dlls, platform);
294-
}else{
315+
}
316+
else {
295317
std::string ext = "";
296318
std::string first = "";
297319
splitFromLast(temp.path(), ".", first, ext);
298-
if (ext == "dll"){
320+
if (ext == "dll") {
299321
dlls.push_back(temp.path());
300322
}
301323
}
@@ -305,6 +327,7 @@ void getDllsRecursively( const std::string & path, std::vector < std::string > &
305327

306328

307329

330+
308331
void getLibsRecursively(const std::string & path, std::vector < std::string > & libFiles, std::vector < LibraryBinary > & libLibs, std::string platform, std::string arch, std::string target){
309332
ofDirectory dir;
310333
dir.listDir(path);

ofxProjectGenerator/src/utils/Utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ void getFoldersRecursively(const std::string & path, std::vector < std::string >
3737
void getFilesRecursively(const std::string & path, std::vector < std::string > & fileNames);
3838
void getLibsRecursively(const std::string & path, std::vector < std::string > & libFiles, std::vector < LibraryBinary > & libLibs, std::string platform = "", std::string arch = "", std::string target = "");
3939
void getFrameworksRecursively( const std::string & path, std::vector < std::string > & frameworks, std::string platform = "" );
40-
void getDllsRecursively( const std::string & path, std::vector < std::string > & dlls, std::string platform);
40+
void getPropsRecursively(const std::string & path, std::vector < std::string > & props, std::string platform);
41+
void getDllsRecursively(const std::string & path, std::vector < std::string > & dlls, std::string platform);
4142

4243

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

0 commit comments

Comments
 (0)