Skip to content

Commit

Permalink
Support Ninja for emscripten builds
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Mar 14, 2024
1 parent c34087e commit ae5afd6
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 14 deletions.
20 changes: 18 additions & 2 deletions kmake/src/Exporters/EmscriptenExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import * as fs from 'kmake/fsextra';
import * as path from 'path';
import { CompilerCommandsExporter } from 'kmake/Exporters/CompileCommandsExporter';
import { MakeExporter } from 'kmake/Exporters/MakeExporter';
import { NinjaExporter } from 'kmake/Exporters/NinjaExporter';

export class EmscriptenExporter extends Exporter {
compileCommands: CompilerCommandsExporter;
make: MakeExporter;
ninja: NinjaExporter;

constructor(project: Project, options: any) {
super(options);
Expand All @@ -36,10 +38,24 @@ export class EmscriptenExporter extends Exporter {

linkerFlags += ' -o ' + executableName + '.html --preload-file ' + this.debugDirName(project);

this.make = new MakeExporter(options, 'emcc', 'emcc', '', '', '', '.html', this.libsMakeLine);
this.make = new MakeExporter(options, 'emcc', 'emcc', '', '', '', '.html', this.libsLine);
this.ninja = new NinjaExporter(options, 'emcc', 'emcc', '', '', '', '.html', this.libsLine);
}

libsMakeLine(project: Project): string {
libsLine(project: Project): string {
let libs = '';
for (let lib of project.getLibs()) {
if (lib.startsWith('USE_')) {
libs += ' -s' + lib;
}
else {
libs += ' -l' + lib;
}
}
return libs;
}

libsNinjaLine(project: Project): string {
let libs = '';
for (let lib of project.getLibs()) {
if (lib.startsWith('USE_')) {
Expand Down
17 changes: 13 additions & 4 deletions kmake/src/Exporters/NinjaExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@ export class NinjaExporter extends Exporter {
linkerFlags: string;
outputExtension: string;

constructor(options: any, cCompiler: string, cppCompiler: string, cFlags: string, cppFlags: string, linkerFlags: string, outputExtension: string) {
constructor(options: any, cCompiler: string, cppCompiler: string, cFlags: string, cppFlags: string, linkerFlags: string, outputExtension: string, libsLine: (p: Project) => string = null) {
super(options);
this.cCompiler = cCompiler;
this.cppCompiler = cppCompiler;
this.cFlags = cFlags;
this.cppFlags = cppFlags;
this.linkerFlags = linkerFlags;
this.outputExtension = outputExtension;
if (libsLine != null) {
this.libsLine = libsLine;
}
}

libsLine(project: Project): string {
let libs = '';
for (let lib of project.getLibs()) {
libs += ' -l' + lib;
}
return libs;
}

async exportSolution(project: Project, from: string, to: string, platform: string, vrApi: any, options: any) {
Expand Down Expand Up @@ -66,9 +77,7 @@ export class NinjaExporter extends Exporter {
}

let libsline = this.linkerFlags;
for (let lib of project.getLibs()) {
libsline += ' -l' + lib;
}
libsline += this.libsLine(project);
libsline += ' ';

let defline = '';
Expand Down
18 changes: 16 additions & 2 deletions lib/kmake/Exporters/EmscriptenExporter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/kmake/Exporters/EmscriptenExporter.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions lib/kmake/Exporters/NinjaExporter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ae5afd6

Please sign in to comment.