Skip to content

Commit d900c48

Browse files
committed
add zed template
1 parent bb2e400 commit d900c48

File tree

4 files changed

+262
-5
lines changed

4 files changed

+262
-5
lines changed

commandLine/compile_flags.txt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
-Wno-c++11-extensions
2+
-std=c17
3+
-std=c++2b
4+
-fobjc-arc
5+
-lstdc++fs
6+
-stdlib=libc++
7+
-mmacosx-version-min=12.0
8+
-MMD
9+
-MP
10+
-MF
11+
-O3
12+
-mtune=native
13+
-DNDEBUG
14+
-Wall
15+
-Werror=return-type
16+
-fexceptions
17+
-fpascal-strings
18+
-x
19+
objective-c++
20+
-I../../../libs/openFrameworks
21+
-I../../../libs/openFrameworks/3d
22+
-I../../../libs/openFrameworks/app
23+
-I../../../libs/openFrameworks/communication
24+
-I../../../libs/openFrameworks/events
25+
-I../../../libs/openFrameworks/gl
26+
-I../../../libs/openFrameworks/graphics
27+
-I../../../libs/openFrameworks/math
28+
-I../../../libs/openFrameworks/sound
29+
-I../../../libs/openFrameworks/types
30+
-I../../../libs/openFrameworks/utils
31+
-I../../../libs/openFrameworks/video
32+
-I../../../libs/FreeImage/include
33+
-I../../../libs/cairo/include
34+
-I../../../libs/curl/include
35+
-I../../../libs/freetype/include
36+
-I../../../libs/glew/include
37+
-I../../../libs/glfw/include/GLFW
38+
-I../../../libs/glm/include
39+
-I../../../libs/json/include
40+
-I../../../libs/pugixml/include
41+
-I../../../libs/rtAudio/include
42+
-I../../../libs/tess2/include
43+
-I../../../libs/uriparser/include/uriparser
44+
-I../../../libs/utf8/include
45+
-I./src
46+
-I./src/addons
47+
-I./src/projects
48+
-I./src/utils
49+
-I./src/uuidxx
50+
-I../../../addons/ofxMicroUI/src
51+
-I../../../addons/ofxTools/src
52+
-I../../../addons/ofxTools/src/feature
53+
-I../../../addons/ofxTools/src/fft

commandLine/src/main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <iostream>
12
#define TARGET_NO_SOUND
23
#define TARGET_NODISPLAY
34

@@ -116,7 +117,6 @@ bool printTemplates() {
116117
auto templates = getTargetProject(target)->listAvailableTemplates(target);
117118
allPlatformsTemplates.emplace_back(templates);
118119
}
119-
120120
std::set<baseProject::Template> commonTemplates;
121121
for (auto & templates : allPlatformsTemplates) {
122122
for (auto & t : templates) {
@@ -333,10 +333,11 @@ int updateOFPath(fs::path path) {
333333
if (!ofPath.empty() && isGoodOFPath(ofPath)) {
334334
ofLogNotice() << "ofPath set and valid using [" << ofPath << "]";
335335
} else {
336-
if(isGoodOFPath(foundOFPath))
336+
if(isGoodOFPath(foundOFPath)) {
337337
setofPath(foundOFPath);
338338
setOFRoot(foundOFPath);
339339
ofLogVerbose() << "ofPath auto-found and valid using [" << ofPath << "]";
340+
}
340341
}
341342
}
342343

@@ -414,8 +415,6 @@ int main(int argc, char ** argv) {
414415
bRecursive = false;
415416
bHelpRequested = false;
416417
bListTemplates = false;
417-
418-
std::cout << "getPlatformString() " << getPlatformString() << std::endl;
419418
targets.emplace_back(getPlatformString());
420419

421420
startTime = 0;
@@ -426,6 +425,8 @@ int main(int argc, char ** argv) {
426425
// ofPath = "";
427426
templateName = "";
428427

428+
429+
429430
// ------------------------------------------------------ parse args
430431
argc -= (argc > 0);
431432
argv += (argc > 0); // skip program name argv[0] if present
@@ -477,7 +478,7 @@ int main(int argc, char ** argv) {
477478
ofLogVerbose() << "ofPath normalised arg: [" << ofPath << "]";
478479
}
479480
}
480-
int updated = updateOFPath(ofPath);
481+
// int updated = updateOFPath(ofPath);
481482

482483
if (options[COMMAND].count() > 0) {
483484
if (options[COMMAND].arg != NULL) {
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
* zedProject.cpp
3+
*
4+
* Created on: 04/01/2025
5+
* Author: Dimitre Lima
6+
*/
7+
8+
#include "zedProject.h"
9+
#include "ofLog.h"
10+
#include "Utils.h"
11+
#include <nlohmann/json.hpp>
12+
13+
14+
using json = nlohmann::json;
15+
16+
struct fileJson {
17+
fs::path fileName;
18+
json data;
19+
20+
// only works for workspace
21+
void addPath(fs::path folder) {
22+
std::string path = folder.is_absolute() ? folder.string() : "${workspaceRoot}/../" + folder.string();
23+
json object;
24+
object["path"] = path;
25+
json::json_pointer p = json::json_pointer("/folders");
26+
data[p].emplace_back( object );
27+
}
28+
29+
void addToArray(string pointer, fs::path value) {
30+
json::json_pointer p = json::json_pointer(pointer);
31+
if (!data[p].is_array()) {
32+
data[p] = json::array();
33+
}
34+
35+
std::string path = fs::path(value).is_absolute() ? value.string() : "${workspaceRoot}/" + value.string();
36+
data[p].emplace_back( path );
37+
}
38+
39+
void load() {
40+
if (!fs::exists(fileName)) {
41+
ofLogError(zedProject::LOG_NAME) << "JSON file not found " << fileName.string();
42+
return;
43+
}
44+
45+
std::ifstream ifs(fileName);
46+
try {
47+
data = json::parse(ifs);
48+
} catch (json::parse_error& ex) {
49+
ofLogError(zedProject::LOG_NAME) << "JSON parse error at byte" << ex.byte;
50+
ofLogError(zedProject::LOG_NAME) << "fileName" << fileName.string();
51+
}
52+
}
53+
54+
void save() {
55+
// alert ("saving now " + fileName.string(), 33);
56+
// std::cout << data.dump(1, '\t') << std::endl;
57+
std::ofstream jsonFile(fileName);
58+
try {
59+
jsonFile << data.dump(1, '\t');
60+
} catch(std::exception & e) {
61+
ofLogError(zedProject::LOG_NAME) << "Error saving json to " << fileName.string() << ": " << e.what();
62+
}
63+
}
64+
};
65+
66+
fileJson workspace;
67+
fileJson cppProperties;
68+
std::string zedProject::LOG_NAME = "zedProject";
69+
70+
bool zedProject::createProjectFile(){
71+
72+
if (backupProjectFiles) {
73+
createBackup({ projectDir / ".vscode" / "c_cpp_properties.json" }, projectDir);
74+
createBackup({ projectDir / ".vscode" / "extensions.json" }, projectDir);
75+
createBackup({ projectDir / ".vscode" / "launch.json" }, projectDir);
76+
createBackup({ projectDir / ".vscode" / "tasks.json" }, projectDir);
77+
createBackup({ projectDir / (projectName + ".code-workspace") }, projectDir);
78+
createBackup({ projectDir / "addons.make" }, projectDir);
79+
createBackup({ projectDir / "config.make" }, projectDir);
80+
createBackup({ projectDir / "Makefile" }, projectDir);
81+
}
82+
83+
#if defined(__MINGW32__) || defined(__MINGW64__)
84+
try {
85+
fs::remove_all(projectDir / ".vscode");
86+
} catch(fs::filesystem_error& e) {
87+
ofLogError(LOG_NAME) << "error removing folder .vscode " << e.what();
88+
return false;
89+
}
90+
#endif
91+
92+
try {
93+
fs::copy(templatePath / ".vscode", projectDir / ".vscode", fs::copy_options::update_existing | fs::copy_options::recursive);
94+
} catch(fs::filesystem_error& e) {
95+
ofLogError(LOG_NAME) << "error copying folder " << templatePath.string() << " : " << projectDir.string() << " : " << e.what();
96+
return false;
97+
}
98+
99+
100+
workspace.fileName = fs::path {
101+
projectDir / (projectName + ".code-workspace")};
102+
cppProperties.fileName = fs::path {
103+
projectDir / ".vscode/c_cpp_properties.json"
104+
};
105+
106+
copyTemplateFiles.push_back({ fs::path { templatePath / "Makefile" },
107+
fs::path { projectDir / "Makefile" }
108+
});
109+
copyTemplateFiles.push_back({ fs::path { templatePath / "config.make" },
110+
fs::path { projectDir / "config.make" }
111+
});
112+
copyTemplateFiles.push_back({ fs::path { templatePath / "emptyExample.code-workspace" },
113+
fs::path { projectDir / workspace.fileName }
114+
});
115+
116+
for (auto & c : copyTemplateFiles) {
117+
try {
118+
c.run();
119+
} catch (const std::exception& e) {
120+
std::cerr << "Error running copy template files: " << e.what() << std::endl;
121+
return false;
122+
}
123+
}
124+
125+
return true;
126+
}
127+
128+
129+
bool zedProject::loadProjectFile(){
130+
workspace.load();
131+
cppProperties.load();
132+
return true;
133+
}
134+
135+
void zedProject::addAddonBegin(const ofAddon& addon) {
136+
// alert("zedProject::addAddon() " + addon.name, 35);
137+
138+
workspace.addPath(addon.addonPath);
139+
140+
// examples of how to add entries to json arrays
141+
// cppProperties.addToArray("/env/PROJECT_ADDON_INCLUDES", addon.addonPath);
142+
// cppProperties.addToArray("/env/PROJECT_EXTRA_INCLUDES", addon.addonPath);
143+
144+
}
145+
146+
147+
bool zedProject::saveProjectFile(){
148+
workspace.data["openFrameworksProjectGeneratorVersion"] = getPGVersion();
149+
workspace.save();
150+
cppProperties.save();
151+
return true;
152+
}
153+
154+
155+
void zedProject::addSrc(const fs::path & srcName, const fs::path & folder, SrcType type){
156+
// alert ("addSrc " + srcName.string(), 33);
157+
}
158+
159+
void zedProject::addInclude(const fs::path & includeName){
160+
// alert ("addInclude " + includeName, 34);
161+
cppProperties.addToArray("/env/PROJECT_EXTRA_INCLUDES", includeName);
162+
}
163+
164+
void zedProject::addLibrary(const LibraryBinary & lib){
165+
// alert ("addLibrary " + lib.path, 35);
166+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* VSCodeProject.h
3+
*
4+
* Created on: 28/09/2023
5+
* Author: Dimitre Lima
6+
*/
7+
8+
#pragma once
9+
10+
#include "baseProject.h"
11+
12+
class zedProject: public baseProject {
13+
public:
14+
zedProject(const std::string & target) : baseProject(target) {};
15+
16+
bool createProjectFile() override;
17+
bool loadProjectFile() override;
18+
bool saveProjectFile() override;
19+
20+
void addSrc(const fs::path & srcName, const fs::path & folder, SrcType type=DEFAULT) override;
21+
void addInclude(const fs::path & includeName) override;
22+
void addLibrary(const LibraryBinary & lib) override;
23+
24+
void addLDFLAG(const std::string& ldflag, LibType libType = RELEASE_LIB) override {}
25+
void addCFLAG(const std::string& cflag, LibType libType = RELEASE_LIB) override {}
26+
void addCPPFLAG(const std::string& cppflag, LibType libType = RELEASE_LIB) override {}
27+
void addAfterRule(const std::string& script) override {}
28+
void addDefine(const std::string& define, LibType libType = RELEASE_LIB) override {}
29+
30+
31+
void addAddonBegin(const ofAddon& addon) override;
32+
33+
static std::string LOG_NAME;
34+
35+
private:
36+
37+
};

0 commit comments

Comments
 (0)