build_pastel.template.m

Back to Building the Pastel Matlab interface

matlab/

% BUILD_PASTEL
% Builds Pastel Matlab mex-libraries.
%
% build_pastel()
% build_pastel('key', value, ...)
%
% Optional arguments
% ------------------
%
% LIBRARYNAME ('libraryName') is a string, or a cell-array of strings, 
% which specifies the Pastel sub-libraries to build the Matlab 
% mex-libraries for. Each string must be one of
%     sys
%     math
%     geometry
% Default: {'sys', 'math', 'geometry'}
%
% MODE ('mode') is a string which specifies the configuration to use for 
% building the Pastel sub-library. It must be one of 
%     debug
%     release
%     relwithdebinfo
% Default: release
%
% VERBOSE ('verbose') is a string which specifies whether to print 
% additional information about the build process. Must be either 'on' 
% or 'off'.
% Default: off

% Description: Builds Pastel Matlab mex-libraries
% Documentation: building_pastelmatlab.txt

function build_pastel(varargin)

% Optional input arguments
libraryName = {'sys', 'math', 'geometry'};
mode = 'release';
verbose = 'off';
eval(pastelsys.process_options(...
    {'libraryName', 'mode', 'verbose'}, ...
    varargin));

modeSet = {'debug', 'release', 'relwithdebinfo'};
if ~ismember(mode, modeSet)
    error(['MODE must be one of debug, release, or relwithdebinfo.']);
end

verboseSet = {'on', 'off'};
if ~ismember(verbose, verboseSet)
    error(['VERBOSE must be one on or off.']);
end

if iscell(libraryName)
    % There are multiple libraries to build.

    % Remove duplicates.
    libraryName = unique(libraryName);

    % Build the libraries one by one.
    for i = 1 : numel(libraryName)
        parameterSet = ...
            [varargin, {'libraryName', libraryName{i}}];
        build_pastel(parameterSet{:});
    end

    return;
end

libraryNameSet = {'sys', 'math', 'geometry'};
if ~ismember(libraryName, libraryNameSet)
    error('LIBRARYNAME must be one of sys, math, or geometry.');
end

completeLibraryName = ['pastel', libraryName, 'matlab'];

inputDirectory = ['${PastelDirectory}/pastel/', libraryName, 'matlab'];
outputDirectory = ['+pastel', libraryName];

% Directories
% -----------

defineSet = {};
includeDirectorySet = ...
{...
    '${PastelIncludeDirectory}', ...
    '${RangesIncludeDirectory}', ...
    '${BoostIncludeDirectory}', ...
    '${TbbIncludeDirectory}', ...
    '${ArmadilloIncludeDirectory}'...
};

libraryDirectorySet = ...
{...
    ['${PastelLibraryDirectory}/', mode], ...
    '${TbbLibraryDirectory}', ...
    '${ArmadilloLibraryDirectory}', ...
};

if ~ismac()
    libraryDirectorySet = ...
    [...
        libraryDirectorySet, ...
        '${LapackLibraryDirectory}', ...
        '${BlasLibraryDirectory}'
    ];
end

% Libraries

% Note that g++ is sensitive to the order of
% the libraries; they must occur in from the 
% referring library to referred library.
% Otherwise g++ will remove the library, since
% at that point there are no references to it.
% In contrast, Visual Studio is insensitive
% to the ordering.

librarySet = {};

if strcmp(libraryName, 'geometry')
    librarySet = [...
        librarySet, ...
        'pastelgeometrymatlab', ...
        'pastelmathmatlab', ...
        'pastelsysmatlab', ...
        'pastelmatlab', ...
        'pastelgeometry', ...
        'pastelmath', ...
        'pastelsys'
    ];
end

if strcmp(libraryName, 'math')
    librarySet = [...
        librarySet, ...
        'pastelmathmatlab', ...
        'pastelsysmatlab', ...
        'pastelmatlab', ...
        'pastelmath', ...
        'pastelsys'
    ];
end

if strcmp(libraryName, 'sys')
    librarySet = [...
        librarySet, ...
        'pastelsysmatlab', ...
        'pastelmatlab', ...
        'pastelsys' ...
    ];
end

librarySet = [...
    librarySet, ...
    ... Threading Build Blocks ...
    '${TbbLibraryName}', ...
    ... Armadillo ...
    '${ArmadilloLibraryName}' ...
];

if ~ismac()
    librarySet = [...
        librarySet, ...
        ... BLAS ...
        '${BlasLibraryName}', ...
        ... LAPACK ...
        '${LapackLibraryName}' ...
    ];
end

fileSet = {[inputDirectory, '/', completeLibraryName, '.cpp']};

commandSet = form_build_command(...
    fileSet, ...
    'outputLibraryName', completeLibraryName, ...
    'includeDirectorySet', includeDirectorySet, ...
    'libraryDirectorySet', libraryDirectorySet, ...
    'librarySet', librarySet, ...
    'defineSet', defineSet, ...
    'outputDirectory', outputDirectory, ...
    'mode', mode, ...
    'verbose', verbose, ...
    'run', true);

end