running cmake on build

pull/1856/head
antelle 2021-04-13 22:39:07 +02:00
parent 08d31c0ffe
commit d374eecb18
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
4 changed files with 133 additions and 5 deletions

View File

@ -741,6 +741,67 @@ module.exports = function (grunt) {
}
},
html: 'dist/index.html'
},
cmake: {
'native-messaging-host-darwin-x64': {
options: {
outputName: 'keeweb-native-messaging-host',
cmakeConfigure: ['-DCMAKE_OSX_ARCHITECTURES=x86_64']
},
files: {
'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/MacOS/keeweb-native-messaging-host':
'extension/native-messaging-host'
}
},
'native-messaging-host-darwin-arm64': {
options: {
outputName: 'keeweb-native-messaging-host',
cmakeConfigure: ['-DCMAKE_OSX_ARCHITECTURES=arm64']
},
files: {
'tmp/desktop/KeeWeb-darwin-arm64/KeeWeb.app/Contents/MacOS/keeweb-native-messaging-host':
'extension/native-messaging-host'
}
},
'native-messaging-host-linux-x64': {
options: {
outputName: 'keeweb-native-messaging-host'
},
files: {
'tmp/desktop/KeeWeb-linux-x64/keeweb-native-messaging-host':
'extension/native-messaging-host'
}
},
'native-messaging-host-win32-x64': {
options: {
outputName: 'keeweb-native-messaging-host.exe',
cmakeConfigure: ['-A', 'x64']
},
files: {
'tmp/desktop/KeeWeb-win32-x64/keeweb-native-messaging-host.exe':
'extension/native-messaging-host'
}
},
'native-messaging-host-win32-ia32': {
options: {
outputName: 'keeweb-native-messaging-host.exe',
cmakeConfigure: ['-A', 'win32']
},
files: {
'tmp/desktop/KeeWeb-win32-ia32/keeweb-native-messaging-host.exe':
'extension/native-messaging-host'
}
},
'native-messaging-host-win32-arm64': {
options: {
outputName: 'keeweb-native-messaging-host.exe',
cmakeConfigure: ['-A', 'arm64']
},
files: {
'tmp/desktop/KeeWeb-win32-arm64/keeweb-native-messaging-host.exe':
'extension/native-messaging-host'
}
}
}
});
};

View File

@ -0,0 +1,58 @@
const path = require('path');
const fs = require('fs');
module.exports = function (grunt) {
grunt.registerMultiTask('cmake', 'Builds with CMake', async function () {
const done = this.async();
const opt = this.options();
for (const file of this.files) {
const dest = file.dest;
const src = file.src[0];
const binPath = path.resolve(src, 'build', opt.outputName);
if (fs.existsSync(binPath)) {
fs.unlinkSync(binPath);
}
try {
await spawnCmake(['-B', 'build', '.', ...opt.cmakeConfigure], src);
} catch (e) {
grunt.warn(`Configure error: ${e}`);
}
try {
await spawnCmake(['--build', 'build', '--config', 'MinSizeRel'], src);
} catch (e) {
grunt.warn(`Build error: ${e}`);
}
grunt.file.copy(binPath, dest);
fs.chmodSync(dest, 0o700);
grunt.log.writeln(`Built ${dest}`);
done();
}
});
function spawnCmake(args, cwd) {
return new Promise((resolve, reject) => {
grunt.log.writeln(`cmake ${args.join(' ')}`);
const child = grunt.util.spawn(
{ cmd: 'cmake', args, opts: { cwd } },
(err, result, code) => {
if (code) {
reject(new Error(`CMake exit code ${code}`));
} else if (err) {
reject(err);
} else {
resolve();
}
}
);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
});
}
};

View File

@ -54,7 +54,8 @@ module.exports = function(grunt) {
'electron-patch:darwin-x64',
'build-darwin-installer',
'copy:desktop-darwin-installer-helper-x64',
'copy:native-modules-darwin-x64'
'copy:native-modules-darwin-x64',
'cmake:native-messaging-host-darwin-x64'
]);
grunt.registerTask('dev-desktop-darwin-signed', 'Build a signed macOS app in dev environment', [
@ -66,7 +67,8 @@ module.exports = function(grunt) {
'default',
'build-desktop-app-content',
'electron:win32-x64',
'copy:native-modules-win32-x64'
'copy:native-modules-win32-x64',
'cmake:native-messaging-host-win32-x64'
]);
grunt.registerTask('dev-desktop-linux', 'Build a Linux app in dev environment', [
@ -74,7 +76,8 @@ module.exports = function(grunt) {
'build-desktop-app-content',
'electron:linux',
'chmod:linux-desktop-x64',
'copy:native-modules-linux-x64'
'copy:native-modules-linux-x64',
'cmake:native-messaging-host-linux-x64'
]);
grunt.registerTask('test', 'Build and run tests', [

View File

@ -28,7 +28,8 @@ module.exports = function (grunt) {
'electron:linux',
'electron-patch:linux',
'chmod:linux-desktop-x64',
'copy:native-modules-linux-x64'
'copy:native-modules-linux-x64',
'cmake:native-messaging-host-linux-x64'
]);
grunt.registerTask('build-desktop-executables-darwin', [
@ -40,7 +41,9 @@ module.exports = function (grunt) {
'copy:desktop-darwin-installer-helper-x64',
'copy:desktop-darwin-installer-helper-arm64',
'copy:native-modules-darwin-x64',
'cmake:native-messaging-host-darwin-x64',
'copy:native-modules-darwin-arm64',
'cmake:native-messaging-host-darwin-arm64',
sign ? 'osx-sign:desktop-x64' : 'noop',
sign ? 'osx-sign:desktop-arm64' : 'noop',
sign ? 'notarize:desktop-x64' : 'noop',
@ -65,7 +68,10 @@ module.exports = function (grunt) {
sign ? 'sign-exe:win32-build-arm64' : 'noop',
'copy:native-modules-win32-x64',
'copy:native-modules-win32-ia32',
'copy:native-modules-win32-arm64'
'copy:native-modules-win32-arm64',
'cmake:native-messaging-host-win32-x64',
'cmake:native-messaging-host-win32-ia32',
'cmake:native-messaging-host-win32-arm64'
]);
grunt.registerTask('build-desktop-executables', [