Missing include files when using AZ Code Generator

Hello all,

this is my first post in the forum, apologies if I might do it incorrectly.

So I am experimenting with AZ Code Generator for components, I am following the examples in Code > Tools > AzCodeGenerator > AzCodeGenratorUnitTests. Code generation works correctly, .h, .cpp and .inline files are generated. Problem is when I try to include those generated files in my component, I get a missing include error from the compiler.

I’ve looked for the generated files and noticed they are generated into BinTemp > win_x64_vs2017_profile > azcg > MyProjectName > Source. I would have assumed the VS2017 solution would be aware of that generated folder but not. What am I doing wrong? Is there a setting to change where the generated files are outputted? How do I inform the VS compiler of this folder? In general, what’s the recommended process for this? In AzCodeGenratorUnitTests, there seem not to be any changes to the *.waf_files to add the generated files as I would have expected.

I am a bit stuck and not sure what to do. Could anybody help me? Thanks a lot in advance!

The relevant extract from the wscript file:

# Add additional custom build options here
        features = ['az_code_gen'],
        az_code_gen = [
            {
                'files' : ['Source/TestCodeGenComponent.h'],
                'scripts' : ['../../../Code/Framework/AzFramework/CodeGen/AzFramework.py'],
                'arguments' : [
                  #'-OnlyRunDiagnosticsOnMainFile=false',
                  #'-SuppressDiagnostics=false',
                  #'-SuppressErrorsAsWarnings=false',
                  '-output-redirection=file',
                  # Diagnostics:
                  #'-SuppressIncludeNotFoundError=false',
                  #'-SkipFunctionBodies=false',
                  #'-DelayedTemplateParsing=false',
                  #'-EnableIncrementalProcessing=false',
                ],
                'options' : [
                  'PrintOutputRedirectionFile',
                  #'Profile'
                ]
            },
        ],

A snippet of the component declaration (that fails to find the include):

#pragma once

#include <AzCore/Component/Component.h>

#include <AzCore/Preprocessor/CodeGen.h>

#include "TestCodeGenComponent.generated.h"

class TestCodeGenComponent : public AZ::Component
// ...

The *.waf_files contents:

{
    "auto": {
        "Include": [
            "Include/TestProject/TestProjectBus.h"
        ],
        "Source": [
            "Source/TestProjectModule.cpp",
            "Source/TestProjectSystemComponent.cpp",
            "Source/TestProjectSystemComponent.h",
            "Source/TestCodeGenComponent.h",
            "Source/TestCodeGenComponent.cpp"
        ]
    }
}

The compiler error I get:

c:\Amazon\Lumberyard\1.21.0.0\dev\TestProject\Gem\Code\Source\TestCodeGenComponent.h(7): fatal error C1083: Cannot open include file: 'TestCodeGenComponent.generated.h': No such file or directory

Hi, probably you need use - driver_node gem_node script_canvas_dir
try to declare it with using your paths

here is my wsript with using az_code_gen feature


def build(bld):
    import os
    driver_node = bld.path.find_or_declare('Gems/ScriptCanvas/Code/Include/ScriptCanvas')
    gem_node = bld.path.find_or_declare('ActionGame/Gem/Code')
    script_canvas_dir = driver_node.path_from(gem_node)

    CODEGEN_FILE_LIST = [
		'Source/ScriptCanvas/AIStateMachineNodes.h',
		'Source/ScriptCanvas/AIStateMachineTransitionNode.h',
		'Source/ScriptCanvas/AIStateMachineNavigationNode.h',
		'Source/ScriptCanvas/AIStateMachineVisionNode.h',
		'Source/ScriptCanvas/AIStateMachineDebugNode.h'
    ]

    bld.DefineGem(
        # General
		pch             = 'Source/ActionGame_precompiled.cpp',
        includes  = [ '.',
                      bld.Path('Code/CryEngine/CryCommon'),
                      bld.Path('Code/CryEngine/CryAction'),
                      bld.Path('Gems/EMotionFX/Code/EMotionFX')
					  ],

        use                     = [ '.',
									'AzCore',
									'AzFramework',
									'AzGameFramework',
									'AzToolsFramework',
									'LmbrCentral',
									'ScriptCanvas',
									'EMotionFX',
								],
        features        = ['az_code_gen'],
        az_code_gen = [
            {
                'files'   : CODEGEN_FILE_LIST,
                'scripts' : [os.path.join(script_canvas_dir, 'CodeGen/Drivers/ScriptCanvasNode.py')],
            }
        ],
        # Platform Specific

        restricted_script       = 'update_restricted_parameters',

        # Testing
        #test_all_file_list      = ['project3_tests.waf_files'],

        # Add additional custom build options here

    )

Tried to use your suggestion, but it doesn’t work. Modified my wscript, so now it looks like yours:


def build(bld):
    import os
    driver_node = bld.path.find_or_declare('Code/Framework/AzFramework')
    gem_node = bld.path.find_or_declare('TestProject/Gem/Code')
    codegen_dir = driver_node.path_from(gem_node)

    CODEGEN_FILE_LIST = [
      'Source/TestCodeGenComponent.h'
    ]

    bld.DefineGem(
        # General
        includes                = ['.'],
        use                     = ['AzGameFramework'],
        disable_pch             = True,

        features = ['az_code_gen'],
        az_code_gen = [
            {
                'files' : CODEGEN_FILE_LIST,
                'scripts' : [os.path.join(codegen_dir, 'CodeGen/AzFramework.py')],
            },
        ],

        # Platform Specific

        restricted_script       = 'update_restricted_parameters',

        # Testing
        #test_all_file_list      = ['testproject_tests.waf_files'],

        # Add additional custom build options here
    )

But still getting the same include error. The compiler fails to include the files generated by the template driver, like this: #include "TestCodeGenComponent.generated.h". In the output I can see that the code generation is run correctly, and the file are still generated (TestCodeGenComponent.generated.h, TestCodeGenComponent.generated.cpp, TestCodeGenComponent.)generated.inline) but under BinTemp > win_x64_vs2017_profile > azcg > MyProjectName > Source, which, or some reason, I think is not considered by the compiler while building the project. Not sure if I am missing an option in the various config files (like a copy step to get the file to a different location or something to inform the compiler about the location of these generated files?) or there is something else obvious I am not setting up correctly.

Hi, it’s seems all looks fine, but I think something wrong with this line

#include "TestCodeGenComponent.generated.h"

bcoz I have for instance:
for MyIncrementNode.h file

#include <Source/ScriptCanvas/MyIncrementNode.generated.h>

and at the end of MyIncrementNode.cpp file

#include <Source/ScriptCanvas/MyIncrementNode.generated.cpp>

I guess you need add #include <Source/TestCodeGenComponent.generated.h> for h
and at the end of cpp - #include <Source/TestCodeGenComponent.generated.cpp>

That worked! Thank you very much.