Documentation Center

  • Trial Software
  • Product Updates

coder.BuildConfig class

Package: coder

Build context during code generation

Description

The code generation software creates an object of this class to facilitate access to the build context. The build context encapsulates the settings used by the code generation software including:

  • Target language

  • Code generation target

  • Target hardware

  • Build toolchain

Use coder.BuildConfig methods in the methods that you write for the coder.ExternalDependency class.

Construction

The code generation software creates objects of this class.

Methods

getHardwareImplementationGet handle of copy of hardware implementation object
getStdLibInfoGet standard library information
getTargetLangGet target code generation language
getToolchainInfoReturns handle of copy of toolchain information object
isCodeGenTargetDetermine if build configuration represents specified target
isMatlabHostTargetDetermine if hardware implementation object target is MATLAB host computer

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB® documentation.

Examples

expand all

Use coder.BuildConfig methods to access the build context in coder.ExternalDependency methods

This example shows how to use coder.BuildConfig methods to access the build context in coder.ExternalDependency methods. In this example, you use:

  • coder.BuildConfig.isMatlabHostTarget to verify that the code generation target is the MATLAB host. If the host is not MATLAB report an error.

  • coder.BuildConfig.getStdLibInfo to get the link-time and run-time library file extensions. Use this information to update the build information.

Write a class definition file for an external library that contains the function adder.

%================================================================
% This class abstracts the API to an external Adder library.
% It implements static methods for updating the build information
% at compile time and build time.
%================================================================

classdef AdderAPI < coder.ExternalDependency
    %#codegen
    
    methods (Static)
        
        function bName = getDescriptiveName(~)
            bName = 'AdderAPI';
        end
        
        function tf = isSupportedContext(ctx)
            if  ctx.isMatlabHostTarget()
                tf = true;
            else
                error('adder library not available for this target');
            end
        end
        
        function updateBuildInfo(buildInfo, ctx)
            [~, linkLibExt, execLibExt, ~] = ctx.getStdLibInfo();
            
            % Header files
            hdrFilePath = fullfile(pwd, 'codegen', 'dll', 'adder');
            buildInfo.addIncludePaths(hdrFilePath);
            
            % Link files
            linkFiles = strcat('adder', linkLibExt);
            linkPath = hdrFilePath;
            linkPriority = '';
            linkPrecompiled = true;
            linkLinkOnly = true;
            group = '';
            buildInfo.addLinkObjects(linkFiles, linkPath, ...
                linkPriority, linkPrecompiled, linkLinkOnly, group);
            
            % Non-build files
            nbFiles = 'adder';
            nbFiles = strcat(nbFiles, execLibExt);
            buildInfo.addNonBuildFiles(nbFiles,'','');
        end
        
        %API for library function 'adder'
        function c = adder(a, b)
            if coder.target('MATLAB')
                % running in MATLAB, use built-in addition
                c = a + b;
            else
                % running in generated code, call library function
                coder.cinclude('adder.h');
                
                % Because MATLAB Coder generated adder, use the
                % housekeeping functions before and after calling
                % adder with coder.ceval.
                % Call initialize function before calling adder for the
                % first time.
                
                coder.ceval('adder_initialize');
                c = 0;
                c = coder.ceval('adder', a, b);
                
                
                % Call the terminate function after
                % calling adder for the last time.
                
                coder.ceval('adder_terminate');
            end
        end
    end
end

See Also

|

Was this topic helpful?