Browse Source

Merge pull request #885 from AtomicGameEngine/JME-ATOMIC-SMOOTHBUILD

Updates build to automatically generate script bindings with single cmake invocation
JoshEngebretson 9 years ago
parent
commit
c9f0328fd9

+ 37 - 0
Build/CMake/Modules/AtomicPlatform.cmake

@@ -0,0 +1,37 @@
+
+if (MSVC)
+
+    include(AtomicWindows)
+
+elseif(APPLE)
+
+    if (IOS)
+        include(AtomicIOS)
+    else()
+        include(AtomicMac)
+    endif()
+
+elseif(LINUX)
+
+  include(AtomicLinux)
+
+elseif(ANDROID)
+
+    include(AtomicAndroid)
+
+elseif(EMSCRIPTEN)
+
+	include(AtomicWeb)
+
+endif()
+
+set (JAVASCRIPT_BINDINGS_PLATFORM_ROOT "${CMAKE_SOURCE_DIR}/Artifacts/Build/Source/Generated/${JAVASCRIPT_BINDINGS_PLATFORM}")
+
+if(NOT EXISTS "${JAVASCRIPT_BINDINGS_PLATFORM_ROOT}")
+
+execute_process ( COMMAND ${ATOMIC_NODE_JAKE};build:precreateScriptBindings[${JAVASCRIPT_BINDINGS_PLATFORM}]
+                  WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" )
+
+endif()
+
+file (GLOB_RECURSE JAVASCRIPT_BINDINGS_NATIVE_FILENAMES ${JAVASCRIPT_BINDINGS_PLATFORM_ROOT}/*.cpp ${JAVASCRIPT_BINDINGS_PLATFORM_ROOT}/*.h)

+ 133 - 72
Build/Scripts/BuildCommon.js

@@ -9,48 +9,109 @@ var Tslint = require("tslint");
 
 
 namespace('build', function() {
 namespace('build', function() {
 
 
-  // Linting task
-  task('lint_typescript', {
-      async: true
-  }, function(fileMask, failOnError) {
-
-    console.log("TSLINT: Linting files in " + fileMask);
-    var lintConfig = JSON.parse(fs.readFileSync("./Script/tslint.json"));
-    var options = {
-        configuration: lintConfig,
-        formatter: "prose"
-    };
-
-    // lint
-    // Since TSLint does not yet support recursively searching for files, then we need to
-    // create a command per file.  The main issue with this is that it will abort on the first error instead
-    // of listing out all lint errors
-    glob(fileMask, function(err, results) {
-      var lintErrors = [];
-      results.forEach(function(filename) {
-
-        var contents = fs.readFileSync(filename, "utf8");
-
-        var ll = new Tslint(filename, contents, options);
-        var result = ll.lint();
-        if (result.failureCount > 0) {
-            lintErrors.push(result.output);
+    // Linting task
+    task('lint_typescript', {
+        async: true
+    }, function(fileMask, failOnError) {
+
+        console.log("TSLINT: Linting files in " + fileMask);
+        var lintConfig = JSON.parse(fs.readFileSync("./Script/tslint.json"));
+        var options = {
+            configuration: lintConfig,
+            formatter: "prose"
+        };
+
+        // lint
+        // Since TSLint does not yet support recursively searching for files, then we need to
+        // create a command per file.  The main issue with this is that it will abort on the first error instead
+        // of listing out all lint errors
+        glob(fileMask, function(err, results) {
+            var lintErrors = [];
+            results.forEach(function(filename) {
+
+                var contents = fs.readFileSync(filename, "utf8");
+
+                var ll = new Tslint(filename, contents, options);
+                var result = ll.lint();
+                if (result.failureCount > 0) {
+                    lintErrors.push(result.output);
+                }
+            });
+            if (lintErrors.length > 0) {
+                console.warn("TSLINT: WARNING - Lint errors detected");
+                console.warn(lintErrors.join(''));
+                if (failOnError) {
+                    fail("TSLint errors detected");
+                }
+            }
+            complete();
+        });
+    });
+
+    // precreate script bindgs so they can be picked up by CMake
+    task('precreateScriptBindings', {
+        async: true
+    }, function(platform, clean) {
+
+        if (clean === undefined) {
+            clean = true;
         }
         }
-      });
-      if (lintErrors.length > 0) {
-          console.warn("TSLINT: WARNING - Lint errors detected");
-          console.warn(lintErrors.join(''));
-          if (failOnError) {
-              fail("TSLint errors detected");
-          }
-      }
-      complete();
+        console.log("Precreating script bindings for platorm: " + platform);
+
+        if (clean) {
+            common.cleanCreateDir(common.getGenScriptRootDir(platform))
+        }
+
+        common.createGenScriptFiles(platform);
+
+        complete();
     });
     });
-  });
 
 
-  task('genscripts', {
-    async: true
-  }, function(platform) {
+    function fileExists(filePath)
+    {
+        try
+        {
+            return fs.statSync(filePath).isFile();
+        }
+        catch (err)
+        {
+            return false;
+        }
+    }
+
+    task('genscripts', {
+        async: true
+    }, function(platform, checkZero) {
+
+        if (checkZero === undefined) {
+            checkZero = false;
+        }
+
+        var anyZero = false;
+        if (checkZero) {
+
+            var filenames = common.getGenScriptFilenames(platform);
+            for (var i in filenames) {
+
+                if (!fileExists(filenames[i]))
+                {
+                    console.log("genscripts: file missing, regenerating script bindings: " + filenames[i]);
+                    anyZero = true;
+                    break;
+                }
+
+                var stats = fs.statSync(filenames[i]);
+                if (stats["size"] == 0) {
+                    console.log("genscripts: file zero size, regenerating script bindings: " + filenames[i]);
+                    anyZero = true;
+                    break;
+                }
+            }
+
+            if (!anyZero)
+                return;
+        }
+
 
 
         process.chdir(atomicRoot);
         process.chdir(atomicRoot);
 
 
@@ -63,14 +124,14 @@ namespace('build', function() {
 
 
         switch(os.platform()) {
         switch(os.platform()) {
             case "win32":
             case "win32":
-                node = "Build\\Windows\\node\\node.exe";
-                break;
+            node = "Build\\Windows\\node\\node.exe";
+            break;
             case "darwin":
             case "darwin":
-                node = "Build/Mac/node/node";
-                break;
+            node = "Build/Mac/node/node";
+            break;
             case "linux":
             case "linux":
-                node = "Build/Linux/node/node";
-                break;
+            node = "Build/Linux/node/node";
+            break;
         }
         }
 
 
         var cmds = [];
         var cmds = [];
@@ -79,49 +140,49 @@ namespace('build', function() {
         }
         }
 
 
         if (node) {
         if (node) {
-          // compile
-          cmds.push(node + " " + tsc + " -p ./Script");
-          cmds.push(node + " " + tsc + " -p ./Script/AtomicWebViewEditor");
+            // compile
+            cmds.push(node + " " + tsc + " -p ./Script");
+            cmds.push(node + " " + tsc + " -p ./Script/AtomicWebViewEditor");
 
 
-          // generate combined atomic.d.ts
-          cmds.push(node + " " + dtsGenerator + " --name Atomic --project ./Script/TypeScript --out ./Script/TypeScript/dist/Atomic.d.ts");
+            // generate combined atomic.d.ts
+            cmds.push(node + " " + dtsGenerator + " --name Atomic --project ./Script/TypeScript --out ./Script/TypeScript/dist/Atomic.d.ts");
 
 
-          var lintTask = jake.Task['build:lint_typescript'];
+            var lintTask = jake.Task['build:lint_typescript'];
 
 
-          lintTask.addListener('complete', function () {
-            console.log("\n\nLint: Typescript linting complete.\n\n");
-            jake.exec(cmds, function() {
+            lintTask.addListener('complete', function () {
+                console.log("\n\nLint: Typescript linting complete.\n\n");
+                jake.exec(cmds, function() {
 
 
-                // copy some external dependencies into the editor modules directory
-               var editorModulesDir = "./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/modules";
-               var webeditorModulesDir = "./Data/AtomicEditor/CodeEditor/source/editorCore/modules";
-               var nodeModulesDir = "./Build/node_modules";
-               fs.mkdirsSync(editorModulesDir);
-               // TypeScript
-               fs.copySync(nodeModulesDir + "/typescript/lib/typescript.js", webeditorModulesDir + "/typescript.js")
+                    // copy some external dependencies into the editor modules directory
+                    var editorModulesDir = "./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/modules";
+                    var webeditorModulesDir = "./Data/AtomicEditor/CodeEditor/source/editorCore/modules";
+                    var nodeModulesDir = "./Build/node_modules";
+                    fs.mkdirsSync(editorModulesDir);
+                    // TypeScript
+                    fs.copySync(nodeModulesDir + "/typescript/lib/typescript.js", webeditorModulesDir + "/typescript.js")
 
 
-               // copy lib.core.d.ts into the tool data directory
-               fs.mkdirsSync("./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/TypeScriptSupport");
-               fs.copySync("./Build/node_modules/typescript/lib/lib.core.d.ts","./Data/AtomicEditor/TypeScriptSupport/lib.core.d.ts")
+                    // copy lib.core.d.ts into the tool data directory
+                    fs.mkdirsSync("./Artifacts/Build/Resources/EditorData/AtomicEditor/EditorScripts/AtomicEditor/TypeScriptSupport");
+                    fs.copySync("./Build/node_modules/typescript/lib/lib.core.d.ts","./Data/AtomicEditor/TypeScriptSupport/lib.core.d.ts")
 
 
-               // copy the combined Atomic.d.ts to the tool data directory
-               fs.copySync("./Script/TypeScript/dist/Atomic.d.ts","./Data/AtomicEditor/TypeScriptSupport/Atomic.d.ts")
+                    // copy the combined Atomic.d.ts to the tool data directory
+                    fs.copySync("./Script/TypeScript/dist/Atomic.d.ts","./Data/AtomicEditor/TypeScriptSupport/Atomic.d.ts")
 
 
-               complete();
+                    complete();
 
 
-            }, {
-              printStdout: true
+                }, {
+                    printStdout: true
+                });
             });
             });
-          });
 
 
-          lintTask.invoke("{./Script/AtomicEditor/**/*.ts,./Script/AtomicWebViewEditor/**/*.ts}", false);
+            lintTask.invoke("{./Script/AtomicEditor/**/*.ts,./Script/AtomicWebViewEditor/**/*.ts}", false);
 
 
         } else {
         } else {
             throw new Error("Node not configured for this platform: " + os.platform());
             throw new Error("Node not configured for this platform: " + os.platform());
         }
         }
 
 
 
 
-  });
+    });
 
 
 
 
 }); // end of build namespace
 }); // end of build namespace

+ 1 - 25
CMakeLists.txt

@@ -39,31 +39,7 @@ endif()
 
 
 add_definitions( -DATOMIC_WEB )
 add_definitions( -DATOMIC_WEB )
 
 
-if (MSVC)
-
-    include(AtomicWindows)
-
-elseif(APPLE)
-
-    if (IOS)
-        include(AtomicIOS)
-    else()
-        include(AtomicMac)
-    endif()
-
-elseif(LINUX)
-
-  include(AtomicLinux)
-
-elseif(ANDROID)
-
-    include(AtomicAndroid)
-
-elseif(EMSCRIPTEN)
-
-	include(AtomicWeb)
-
-endif()
+include (AtomicPlatform)
 
 
 find_program(CLDOC cldoc)
 find_program(CLDOC cldoc)
 if(CLDOC)
 if(CLDOC)

+ 4 - 0
CMake_Linux.sh

@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+SOURCE=$(cd ${0%/*}; pwd)
+cmake -E make_directory ../AtomicGameEngine-Linux && cmake -E chdir ../AtomicGameEngine-Linux cmake "$SOURCE"
+echo "makefile written to ../AtomicGameEngine-Linux"

+ 4 - 4
CMake_VS2015.bat

@@ -1,11 +1,11 @@
 @ECHO OFF
 @ECHO OFF
 @echo:
 @echo:
 @echo:
 @echo:
-ECHO Generating Visual Studio Solution, this process will take a few minutes
+ECHO Generating Visual Studio Solution (64 bit)
 @echo:
 @echo:
 @echo:
 @echo:
-PAUSE
-Build\Windows\node\node.exe Build\node_modules\jake\bin\cli.js -f ./Build/Scripts/Bootstrap.js build:genvs2015
+call "%VS140COMNTOOLS%..\..\VC\bin\amd64\vcvars64.bat"
+cmake -E make_directory "..\AtomicGameEngine-VS2015" && cmake -E chdir "..\AtomicGameEngine-VS2015" cmake ../AtomicGameEngine -G "Visual Studio 14 2015 Win64"
 @echo:
 @echo:
+ECHO Solution created in ..\AtomicGameEngine-VS2015
 @echo:
 @echo:
-PAUSE

+ 4 - 2
CMake_XCode.sh

@@ -1,2 +1,4 @@
-#!/bin/sh
-./Build/Mac/node/node ./Build/node_modules/jake/bin/cli.js -f ./Build/Scripts/Bootstrap.js build:genxcode --trace
+#!/usr/bin/env bash
+SOURCE=$(cd ${0%/*}; pwd)
+cmake -E make_directory ../AtomicGameEngine-XCode && cmake -E chdir ../AtomicGameEngine-XCode cmake "$SOURCE" -G Xcode
+echo "XCode project written to ../AtomicGameEngine-XCode"

+ 2 - 0
Source/AtomicEditor/CMakeLists.txt

@@ -197,6 +197,8 @@ if (TARGET_PROPERTIES)
     set_target_properties (AtomicEditor PROPERTIES ${TARGET_PROPERTIES})
     set_target_properties (AtomicEditor PROPERTIES ${TARGET_PROPERTIES})
 endif ()
 endif ()
 
 
+add_dependencies(${CEF_TARGET} AtomicTool)
+
 GroupSources("Application")
 GroupSources("Application")
 GroupSources("EditorMode")
 GroupSources("EditorMode")
 GroupSources("Editors")
 GroupSources("Editors")

+ 2 - 0
Source/AtomicJS/CMakeLists.txt

@@ -20,3 +20,5 @@ file (GLOB JAVASCRIPT_BINDINGS_SOURCE ${CMAKE_SOURCE_DIR}/Artifacts/Build/Source
 set (SOURCE_FILES ${JAVASCRIPT_SOURCE} ${JAVASCRIPT_BINDINGS_SOURCE})
 set (SOURCE_FILES ${JAVASCRIPT_SOURCE} ${JAVASCRIPT_BINDINGS_SOURCE})
 
 
 add_library(AtomicJS ${SOURCE_FILES})
 add_library(AtomicJS ${SOURCE_FILES})
+
+add_dependencies(AtomicJS AtomicTool)

+ 2 - 0
Source/AtomicPlayerJS/CMakeLists.txt

@@ -9,3 +9,5 @@ set (SOURCE_FILES ${SOURCE_FILES} ${JAVASCRIPT_BINDINGS_SOURCE} )
 add_library(AtomicPlayerJS ${SOURCE_FILES})
 add_library(AtomicPlayerJS ${SOURCE_FILES})
 
 
 target_link_libraries(AtomicPlayerJS AtomicPlayerLib)
 target_link_libraries(AtomicPlayerJS AtomicPlayerLib)
+
+add_dependencies(AtomicPlayerJS AtomicTool)

+ 4 - 0
Source/AtomicTool/CMakeLists.txt

@@ -27,6 +27,10 @@ add_custom_command( TARGET AtomicTool POST_BUILD
                    COMMAND ${CMAKE_COMMAND}
                    COMMAND ${CMAKE_COMMAND}
                    ARGS -E copy_if_different $<TARGET_FILE:AtomicTool> \"${CMAKE_SOURCE_DIR}/Artifacts/Build/AtomicTool/\" )
                    ARGS -E copy_if_different $<TARGET_FILE:AtomicTool> \"${CMAKE_SOURCE_DIR}/Artifacts/Build/AtomicTool/\" )
 
 
+add_custom_command( TARGET AtomicTool POST_BUILD
+                    WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+                    COMMAND ${ATOMIC_NODE_JAKE};build:genscripts[${JAVASCRIPT_BINDINGS_PLATFORM},true])
+
 if (MSVC)
 if (MSVC)
 
 
 # Copy the D3D shader compiler
 # Copy the D3D shader compiler

+ 2 - 0
Source/AtomicWebView/CMakeLists.txt

@@ -12,3 +12,5 @@ endif()
 set (SOURCE_FILES ${SOURCE_FILES} ${JAVASCRIPT_BINDINGS_SOURCE} ${PLATFORM_SOURCE} )
 set (SOURCE_FILES ${SOURCE_FILES} ${JAVASCRIPT_BINDINGS_SOURCE} ${PLATFORM_SOURCE} )
 
 
 add_library(AtomicWebView ${SOURCE_FILES})
 add_library(AtomicWebView ${SOURCE_FILES})
+
+add_dependencies(AtomicWebView AtomicTool)