CMakeWindows.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. var fs = require('fs-extra');
  2. var path = require("path");
  3. var host = require("./Host");
  4. var buildTasks = require("./BuildTasks");
  5. var config = require("./BuildConfig");
  6. const nodeSpawn = require('child_process').spawn;
  7. var atomicRoot = config.atomicRoot;
  8. var buildDir = config.artifactsRoot + "Build/Windows/";
  9. var editorAppFolder = config.editorAppFolder
  10. namespace('build', function() {
  11. // converts / to \ and removes trailing slash
  12. function fixpath(path) {
  13. return path.replace(/\//g, "\\").replace(/\\$/, "");
  14. }
  15. // get CMake flags for generator, vsver parameter can be VS2017/VS2015, etc
  16. function getCMakeFlags(vsver) {
  17. // local cmake builds are always dev builds
  18. var flags = "-DATOMIC_DEV_BUILD=1";
  19. // graphics backend overrides, defaults DX11
  20. flags += " -DATOMIC_OPENGL=" + (config["opengl"] ? "ON" : "OFF");
  21. flags += " -DATOMIC_D3D11=" + (config["d3d9"] ? "OFF" : "ON");
  22. return flags;
  23. }
  24. // spawn cmake process
  25. function spawnCMake(vsver) {
  26. host.cleanCreateDir(atomicRoot + "/Artifacts/Build/Source/Generated");
  27. var slnRoot = fixpath(path.resolve(atomicRoot, "") + "-" + vsver);
  28. // we're running cmd.exe, this exits the shell when the command have finished
  29. var args = ["/C"];
  30. // Windows batch file which runs cmake
  31. args.push(fixpath(atomicRoot + "\\Build\\Scripts\\Windows\\GenerateVSSolution.bat"));
  32. // vsver VS2015/VS2017
  33. args.push(vsver);
  34. // Atomic root source dir
  35. args.push(fixpath(atomicRoot));
  36. // Folder to put generated solution in
  37. args.push(fixpath(slnRoot));
  38. // CMake flags
  39. args.push(getCMakeFlags(vsver));
  40. // we're using nodeSpawn here instead of jake.exec as the later was having much trouble with quotes
  41. var cmakeProcess = nodeSpawn("cmd.exe", args);
  42. cmakeProcess.stdout.on('data', (data) => {
  43. process.stdout.write(data.toString());
  44. });
  45. cmakeProcess.stderr.on('data', (data) => {
  46. process.stdout.write(data.toString());
  47. });
  48. cmakeProcess.on('exit', (code) => {
  49. if (code != 0) {
  50. fail(`CMake process exited with code ${code}`);
  51. }
  52. console.log("\n\n" + vsver + " solution created in " + fixpath(slnRoot) + "\n\n");
  53. complete();
  54. });
  55. }
  56. task('genvs2017', {
  57. async: true
  58. }, function() {
  59. spawnCMake("VS2017");
  60. }, {
  61. printStdout: true,
  62. printStderr: true
  63. });
  64. // Generate a Visual Studio 2015 solution
  65. task('genvs2015', {
  66. async: true
  67. }, function() {
  68. spawnCMake("VS2015");
  69. });
  70. });// end of build namespace