-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.m
121 lines (105 loc) · 3.5 KB
/
install.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function install()
% Copyright 2022-2023 The MathWorks, Inc.
%% Run this script once and follow the instructions
% Make sure you run this script from this folder.
MJ_VER = '2.3.5';
GLFW_VER = '3.3.7';
urlsList = fileread("tools/links.json");
blockPath = './blocks/';
examplePath = './examples/';
srcPath = './src/';
glfwRunTimeLib = 'lib-static-ucrt';
% Universal C Run Time (UCRT) is installed in windows 10 or beyond by
% default
%% DOWNLOAD MUJOCO
clear mex %#ok<CLMEX>
mjPath = downloader(urlsList, "mujoco", MJ_VER);
if ~ispc
folder = fullfile(mjPath, ['mujoco-', MJ_VER]);
copyfile(fullfile(folder, '*'), mjPath);
rmdir(folder, 's');
end
%% DOWNLOAD GLFW
if ispc
glfwTopPath = downloader(urlsList, "glfw", GLFW_VER);
end
%% MATLAB PATH ADDITION
addpath(blockPath);
addpath(examplePath);
savepath
disp(' ')
disp("MuJoCo block library and examples added to MATLAB path and saved");
%% SHARED LIB COPY PATH ADDITION
% Alternatively you can add the dll location to system path
mujocoIncPath = fullfile(mjPath, 'include');
mujocoImportLibPath = fullfile(mjPath, 'lib');
if ispc
mujocoDll = fullfile(mjPath, 'bin', 'mujoco.dll');
copyfile(mujocoDll, blockPath);
glfwPath = fullfile(glfwTopPath, ['glfw-', GLFW_VER, '.bin.WIN64']);
glfwIncPath = fullfile(glfwPath, 'include');
glfwImportLibPath = fullfile(glfwPath, glfwRunTimeLib);
glfwDll = fullfile(glfwImportLibPath, 'glfw3.dll');
copyfile(glfwDll, blockPath);
else
mjSo = fullfile(mjPath, 'lib', ['libmujoco.so.', MJ_VER]);
copyfile(mjSo, blockPath);
end
%% Path (MATLAB)
addpath(srcPath);
addpath(mujocoIncPath);
if ispc
addpath(glfwIncPath);
linkPaths = {glfwImportLibPath, mujocoImportLibPath};
incPaths = {mujocoIncPath, fullfile(pwd, srcPath), glfwIncPath};
else
linkPaths = {mujocoImportLibPath};
incPaths = {mujocoIncPath, fullfile(pwd, srcPath)};
end
savepath
%% MEX Build configuration
if ispref('mujoco')
rmpref('mujoco');
end
addpref('mujoco', 'MJ_VER', MJ_VER);
addpref('mujoco', 'linkPaths', linkPaths);
addpref('mujoco', 'incPaths', incPaths);
addpref('mujoco', 'srcPaths', {fullfile(pwd, srcPath)});
if ispc
addpref('mujoco', 'glfwIncPath', glfwIncPath);
addpref('mujoco', 'glfwImportLibPath', glfwImportLibPath);
end
%% Local functions
function downloadfolder = downloader(urlsList, name, version)
libraryFolder = 'lib';
downloadfolder = fullfile(pwd, libraryFolder, computer('arch'), name);
urlJson = jsondecode(urlsList);
for i=1:length(urlJson.files)
obj = urlJson.files(i);
if strcmp(obj.name, name) && strcmp(obj.version, version) && strcmp(obj.arch, computer('arch'))
downloadLink = obj.downloadLink;
end
end
disp(' ')
disp('Download URL is:');
disp(downloadLink);
if isfolder(downloadfolder)
disp(' ')
disp('folder exists already. it will be overwritten');
end
[~,~,ext]=fileparts(downloadLink);
downloadFile = fullfile(libraryFolder, strcat('download', ext));
status = mkdir(libraryFolder); %#ok<NASGU>
websave(downloadFile, downloadLink);
if strcmp(ext,'.zip')
unzip(downloadFile, downloadfolder);
elseif strcmp(ext, '.gz')
untar(downloadFile, downloadfolder);
else
error('unknown extension. Unable to extract archive');
end
disp(' ')
disp(name + ' downloaded and extracted to this path:');
disp(downloadfolder)
end
end