itaVA_build.m.proto 2.03 KB
Newer Older
1
% THIS FILE WILL BE OVERWRITTEN BY CMAKE WITHOUT WARNING
2 3 4 5 6 7 8 9 10 11
%
% Code generator for the VA Matlab interface facade class
%
% Desc:     This script generates the code for the Matlab
%           facade class to the VAInterface MEXExtension.
%           It takes the class template code and inserts
%           all stubs for the functions in the VAConnector
%           interface. These are derived using the reflexion
%           mechanism ('enumerateFunctions')
%
12

13 14
script_dir = '@VAMATLAB_SCRIPT_DIR@'; % Matlab scripts target directory
deploy_dir = '@VAMATLAB_DEPLOY_DIR@'; % Deploy directory, i.e. 'C:/dev/VA/dist/win32-x64.vc12'
15 16 17 18 19
lib_dir = '@VAMATLAB_LIB_DIR@';

if exist( deploy_dir, 'dir' ) ~= 7
    error( 'Deploy dir ''%s'' does not exist. Please build and install VAMatlab first.', deploy_dir )
end
20

21 22 23 24
if exist( script_dir, 'dir' ) ~= 7
   mkdir( script_dir );
end

25
if exist( [ 'VAMatlab' mexext ], 'file' )
26 27
    warning( 'VAMatlab already found at location "%s", are you sure to build itaVA against this executable? Will proceed now.', which( 'VAMatlab' ) )
else
28
    % Add to PATH temporarily and attempt to move lib to bin dir
29
    addpath( script_dir, deploy_dir )
30

31
    [ s ] = movefile( fullfile( lib_dir, 'VAMatlab*' ), deploy_dir );
32
    if ~s && ~exist( [ 'VAMatlab' '.' mexext ], 'file' )
33 34
        error( 'Could locate VAMatlab executable. Please make sure that it can be found.' )
    end
35
end
36 37

% Parameters
38
templateFile = 'itaVA.m.proto';
39 40 41 42
outputFile = fullfile( script_dir, 'itaVA.m' );

fprintf( 'Generating code for itaVA Matlab class ''%s'' ...\n', outputFile );
code = fileread( templateFile );
43
stubCode = itaVA_generateStubs();
44 45 46 47 48 49 50 51

code = strrep( code, '###STUBCODE###', stubCode );

% Write the results
fid = fopen( outputFile, 'w' );
fprintf( fid, '%s', code );
fclose( fid );

52
fprintf( 'Matlab class ''%s'' successfully built\n', outputFile );
53

54 55 56
% Install examples
copyfile( 'itaVA_example*', script_dir );

57
% Remove from MATLABPATH (otherwise naming conflicts may occur with
58
% ITA-Toolbox/applications/VirtualAcoustics/VA/* scripts)
59
rmpath( script_dir, deploy_dir )