Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion commandLine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ enum optionIndex { UNKNOWN,
COMMAND,
BACKUP_PROJECT_FILES,
FRAMEWORKS,
CLEANNAME_DISABLE
CLEANNAME_DISABLE,
DEFINES
};

constexpr option::Descriptor usage[] = {
Expand All @@ -58,6 +59,8 @@ constexpr option::Descriptor usage[] = {

{ CLEANNAME_DISABLE, 0, "n", "cleanname", option::Arg::Optional, " --cleanname, -f \tcleanname" },

{ DEFINES, 0, "D", "defines", option::Arg::Optional, " --defines, -D \tpreprocessor defines list (such as OF_USE_ANGLE=1,MY_FLAG)" },

{ 0, 0, 0, 0, 0, 0 }
};

Expand All @@ -84,6 +87,7 @@ vector<string> addons;
vector<fs::path> srcPaths;
vector<string> targets;
vector<string> frameworks;
vector<string> defines;
string ofPathEnv;
string templateName;

Expand Down Expand Up @@ -267,6 +271,14 @@ void updateProject(const fs::path & path, const string & target, bool bConsiderP
project->addFramework(f, "Frameworks", true);
}

// matches addAddonDefines()'s existing convention (single call, default RELEASE_LIB) -
// xcodeProject::addDefine ignores libType and applies to all build configs anyway,
// but visualStudioProject::addDefine doesn't, so a define here is Release-only for VS,
// consistent with how addon-provided defines already behave there
for (auto & d : defines) {
project->addProjectDefine(d);
}

for (auto & srcPath : srcPaths) {
project->addSrcRecursively(srcPath);
}
Expand Down Expand Up @@ -583,6 +595,10 @@ int main(int argc, char ** argv) {
}
}

if (options[DEFINES].count() > 0 && options[DEFINES].arg != NULL) {
defines = ofSplitString(options[DEFINES].arg, ",", true, true);
}


if (parse.nonOptionsCount() > 0) {
projectName = parse.nonOption(0);
Expand Down Expand Up @@ -734,6 +750,10 @@ int main(int argc, char ** argv) {
project->addFramework(f, "Frameworks", true);
}

for (auto & d : defines) {
project->addProjectDefine(d);
}

for (auto & s : srcPaths) {
project->addSrcRecursively(s);
}
Expand Down
5 changes: 5 additions & 0 deletions commandLine/src/projects/baseProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class baseProject {

virtual void addFramework(const fs::path & path, const fs::path & folder, bool isRelativeToSDK = false){};

// public entry point for project-level preprocessor defines (e.g. -D/--defines on the
// CLI, or a GUI-driven renderer choice) - addDefine() itself stays protected since it's
// also invoked internally by addAddonDefines() for addon-provided defines
void addProjectDefine(const std::string & define, LibType libType = RELEASE_LIB) { addDefine(define, libType); }


#ifdef OFADDON_OUTPUT_JSON_DEBUG
void saveAddonsToJson(){
Expand Down
8 changes: 7 additions & 1 deletion commandLine/src/projects/xcodeProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,13 @@ bool xcodeProject::saveProjectFile() {
// alert (c, 31);
// cout << "this is not array, creating" << endl;
// cout << thispath << endl;
auto v { j[p] };
// NOTE: must be copy-init (=), not brace-init ({}) - nlohmann::json's
// initializer_list constructor wraps a single json value in an array,
// so `auto v { j[p] }` on a null j[p] makes v == [null] rather than
// null, and that gets pushed into the array below instead of being
// correctly skipped, corrupting every freshly-created array key with a
// leading [null] element (e.g. GCC_PREPROCESSOR_DEFINITIONS via addDefine)
auto v = j[p];
j[p] = json::array();
if (!v.is_null()) {
// cout << "thispath " << thispath << endl;
Expand Down
27 changes: 26 additions & 1 deletion frontend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,9 @@ function setup() {
ipcRenderer.send('setLanguage', lang);
});

$('#rendererDropdown').dropdown();
$('#rendererDropdown').dropdown('set exactly', 'default');

// reflesh template dropdown list depends on selected platforms
$("#platformsDropdown").on('change', () => {
const selectedPlatforms = $("#platformsDropdown input").val();
Expand All @@ -969,6 +972,15 @@ function setup() {
}
console.log(arg);
ipcRenderer.send('refreshTemplateList', arg);

// renderer choice (OF_USE_ANGLE / OF_USE_DAWN) only applies to the Xcode-based
// osx/ios/macos (mega iOS/tvOS/macOS) targets
const rendererPlatforms = ['osx', 'ios', 'macos'];
if (selectedPlatformArray.some((p) => rendererPlatforms.includes(p))) {
$('#rendererField').show();
} else {
$('#rendererField').hide();
}
})
$("#platformsDropdownMulti").on('change', () => {
const selectedPlatforms = $("#platformsDropdownMulti input").val();
Expand Down Expand Up @@ -1151,6 +1163,18 @@ function generate() {

const lengthOfPlatforms = platformValueArray.length;

// renderer choice adds its OF_USE_* define on top of whatever the user typed manually
const rendererDefines = {
angle: 'OF_USE_ANGLE=1',
dawn: 'OF_USE_DAWN=1'
};
const rendererChoice = $('#rendererDropdown').dropdown('get value');
const customDefinesText = $('#customDefines').val().trim();
const definesArr = customDefinesText ? customDefinesText.split(',').map((s) => s.trim()).filter(Boolean) : [];
if (rendererDefines[rendererChoice]) {
definesArr.push(rendererDefines[rendererChoice]);
}

const gen = {
projectName: $("#projectName").val(),
projectPath: $("#projectPath").val(),
Expand All @@ -1159,7 +1183,8 @@ function generate() {
templateList: templateValueArray,
addonList: addonValueArray, //$("#addonsDropdown").val();
ofPath: $("#ofPath").val(),
verbose: bVerbose
verbose: bVerbose,
defines: definesArr.join(',')
};

// console.log(gen);
Expand Down
23 changes: 23 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,29 @@
</div>
<div id="test"></div>
</div>
<div class="field" id="rendererField" style="display: none">
<label>Renderer:</label>
<div class="ui selection dropdown" id="rendererDropdown">
<input type="hidden" id="rendererValue" value="default">
<i class="dropdown icon"></i>
<div class="text">Default (OpenGL)</div>
<div class="menu">
<div class="item" data-value="default">Default (OpenGL)</div>
<div class="item" data-value="angle">ANGLE (OF_USE_ANGLE)</div>
<div class="item" data-value="dawn">Dawn / WebGPU (OF_USE_DAWN)</div>
</div>
</div>
</div>
<div class="field">
<label>Custom defines: &nbsp;
<a class="ui icon tooltip" href="#" data-content="Comma-separated preprocessor defines, e.g. MY_FLAG,OTHER_FLAG=1" data-position="right center">
<i class="help circle icon"></i>
</a>
</label>
<div class="ui icon input fluid">
<input type="text" placeholder="MY_FLAG,OTHER_FLAG=1..." id="customDefines">
</div>
</div>
<div id="templateSection" class="field">
<label data-i18n="field.template">Template:</label>
<div class="ui multiple search selection dropdown" id="templatesDropdown">
Expand Down
6 changes: 6 additions & 0 deletions frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ ipcMain.on('runOfMenu', (event, { command, ofPath }) => {
* addonList: Array<string>,
* ofPath: string,
* verbose: boolean,
* defines: string,
* }} GenerateArgument */

/**
Expand All @@ -1255,6 +1256,7 @@ function generateFunction(event, generate) {
verbose,
projectPath,
projectName,
defines,
} = generate;

const args = [];
Expand Down Expand Up @@ -1285,6 +1287,10 @@ function generateFunction(event, generate) {
args.push(`-t${templateList.join(",")}`);
}

if (defines != null && defines.length > 0) {
args.push(`-D${defines}`);
}

if (projectName != null && projectPath != null) {
args.push(path.join(projectPath, projectName));
}
Expand Down
Loading