forked from RobotLocomotion/cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matlab_pods.cmake
173 lines (148 loc) · 5.27 KB
/
matlab_pods.cmake
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Functions to simplify matlab use in a pods setting.
#
# To enable the macros, add the following lines to CMakeLists.txt:
# set(POD_NAME <pod-name>)
# include(cmake/pods.cmake)
# include(cmake/matlab_pods.cmake)
#
# Assumes that <project_path>/build/matlab is on the matlab path
# Provides the following functions, see individual functions for documentation:
#
# pods_install_matlab_path(...)
# pods_configure_matlab_paths(...)
#
# ----
# pods_install_matlab_path(<module_name>
# [directory])
#
# Create addpath_<module_name> function to access functions in directory
#
# If directory argument is not present it is assumed to be matlab
# directory may also be set to CURRENT_DIRECTORY
function(pods_install_matlab_path)
list(GET ARGV 0 MODULE_NAME)
if(ARGC LESS 2)
set(SUBDIR_NAME matlab)
else()
list(GET ARGV 1 SUBDIR_NAME)
if(SUBDIR_NAME STREQUAL CURRENT_DIRECTORY)
set(SUBDIR_NAME "")
endif()
endif()
set(ADDPATH_FILE ${PROJECT_BINARY_DIR}/matlab/addpath_${MODULE_NAME}.m)
file(WRITE ${ADDPATH_FILE}
"function addpath_${MODULE_NAME}(recurse)\n"
"global ${MODULE_NAME}_path_added\n"
"if ${MODULE_NAME}_path_added\n"
" return;\n"
"end\n"
"${MODULE_NAME}_path_added = 1;\n"
"path = '${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR_NAME}';\n"
"if nargin==0\n"
" recurse = 1;\n"
"end\n"
"if recurse\n"
" all_paths = genpath(path);\n"
" split_paths = regexp(all_paths, ':','split');\n"
" for ii=1:length(split_paths)\n"
" ind = strfind(split_paths{ii},'.svn');\n"
" if isempty(ind)\n"
" addpath(split_paths{ii})\n"
" end\n"
" end\n"
"else\n"
" rmpath(path)\n"
"end\n"
)
set(RMPATH_FILE ${PROJECT_BINARY_DIR}/matlab/rmpath_${MODULE_NAME}.m)
file(WRITE ${RMPATH_FILE}
"function rmpath_${MODULE_NAME}(recurse)\n"
"global ${MODULE_NAME}_path_added\n"
"if ~${MODULE_NAME}_path_added\n"
" return\n"
"end\n"
"${MODULE_NAME}_path_added = 0;\n"
"path = '${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIR_NAME}';\n"
"if nargin==0\n"
" recurse = 1;\n"
"end\n"
"if recurse\n"
" all_paths = genpath(path);\n"
" split_paths = regexp(all_paths, ':','split');\n"
" for ii=1:length(split_paths)\n"
" ind = strfind(split_paths{ii},'.svn');\n"
" if isempty(ind)\n"
" rmpath(split_paths{ii})\n"
" end\n"
" end\n"
"else\n"
" rmpath(path)\n"
"end\n"
)
install(FILES ${ADDPATH_FILE} DESTINATION matlab/)
install(FILES ${RMPATH_FILE} DESTINATION matlab/)
endfunction(pods_install_matlab_path)
# pods_configure_matlab_paths()
#
# provides access to pods and cmake paths inside of matlab
#
# after calling, functions are available in matlab:
# >> pods_get_base_path()
#
# only needs to be called once per project
function(pods_configure_matlab_paths)
set(PODS_PATHFILE ${PROJECT_BINARY_DIR}/matlab/pods_get_r_path.m)
file(WRITE ${PODS_PATHFILE}
"function path = pods_get_r_path()\n"
"path = fullfile(pods_get_base_path, 'lib');\n"
)
install(FILES ${PODS_PATHFILE} DESTINATION matlab/)
set(PODS_PATHFILE ${PROJECT_BINARY_DIR}/matlab/pods_get_lib_path.m)
file(WRITE ${PODS_PATHFILE}
"function path = pods_get_lib_path()\n"
"path = fullfile(pods_get_base_path, 'lib');\n"
)
install(FILES ${PODS_PATHFILE} DESTINATION matlab/)
set(PODS_PATHFILE ${PROJECT_BINARY_DIR}/matlab/pods_get_bin_path.m)
file(WRITE ${PODS_PATHFILE}
"function path = pods_get_bin_path()\n"
"path = fullfile(pods_get_base_path, 'bin');\n"
)
install(FILES ${PODS_PATHFILE} DESTINATION matlab/)
set(PODS_PATHFILE ${PROJECT_BINARY_DIR}/matlab/pods_get_include_path.m)
file(WRITE ${PODS_PATHFILE}
"function path = pods_get_include_path()\n"
"path = fullfile(pods_get_base_path, 'include');\n"
)
install(FILES ${PODS_PATHFILE} DESTINATION matlab/)
set(PODS_PATHFILE ${PROJECT_BINARY_DIR}/matlab/pods_get_pkgconfig_path.m)
file(WRITE ${PODS_PATHFILE}
"function path = pods_get_pkgconfig_path()\n"
"path = fullfile(pods_get_base_path, 'lib', 'pkgconfig');\n"
)
install(FILES ${PODS_PATHFILE} DESTINATION matlab/)
set(PODS_PATHFILE ${PROJECT_BINARY_DIR}/matlab/pods_get_base_path.m)
file(WRITE ${PODS_PATHFILE}
"function path = pods_get_base_path()\n"
" path = fullfile(fileparts(which(mfilename)),'..');\n"
)
install(FILES ${PODS_PATHFILE} DESTINATION matlab/)
set(PODS_PATHFILE ${PROJECT_BINARY_DIR}/matlab/pods_get_data_path.m)
file(WRITE ${PODS_PATHFILE}
"function path = pods_get_data_path()\n"
"path = fullfile(pods_get_base_path(),'data');\n"
)
install(FILES ${PODS_PATHFILE} DESTINATION matlab/)
set(PODS_PATHFILE ${PROJECT_BINARY_DIR}/matlab/pods_get_config_path.m)
file(WRITE ${PODS_PATHFILE}
"function path = pods_get_config_path()\n"
"path = fullfile(pods_get_base_path(),'config');\n"
)
install(FILES ${PODS_PATHFILE} DESTINATION matlab/)
set(PODS_PATHFILE ${PROJECT_BINARY_DIR}/matlab/pods_get_models_path.m)
file(WRITE ${PODS_PATHFILE}
"function path = pods_get_models_path()\n"
"path = fullfile(pods_get_base_path(),'models');\n"
)
install(FILES ${PODS_PATHFILE} DESTINATION matlab/)
endfunction(pods_configure_matlab_paths)