-
Notifications
You must be signed in to change notification settings - Fork 10
/
catkin.cmake
287 lines (266 loc) · 15.2 KB
/
catkin.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# http://ros.org/doc/groovy/api/catkin/html/user_guide/supposed.html
cmake_minimum_required(VERSION 2.8.3)
project(hrpsys)
# Load catkin and all dependencies required for this package
find_package(catkin REQUIRED COMPONENTS rostest mk openrtm_aist openhrp3)
# Build hrpsys
# <devel>/lib/<package>/bin/RobotHardware
# <src>/lib/RobotHardware.so # so that `rospack find hrspsys`/lib can find .so
# <src>/<package>/share
# <install>/lib/<package>/RobotHardware # rosrun hrpsys RobtoHardware works
# <install>/lib/RobotHardware.so # so that `rospack find hrspsys`/lib can find .so
# <install>/<package>/share
if(NOT hrpsys_FOUND)
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/installed)
endif()
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/installed)
set(ENV{PATH} ${openrtm_aist_PREFIX}/lib/openrtm_aist/bin/:$ENV{PATH}) #update PATH for rtm-config
execute_process(
COMMAND cmake -E chdir ${CMAKE_CURRENT_BINARY_DIR}
make -f ${PROJECT_SOURCE_DIR}/Makefile.hrpsys-base
INSTALL_DIR=${CATKIN_DEVEL_PREFIX}
OPENRTM_DIR='' # keep blank so that FindOpenRTM.cmake uses rtm-config
MK_DIR=${mk_PREFIX}/share/mk
PATCH_DIR=${PROJECT_SOURCE_DIR}
PKG_CONFIG_PATH=${openhrp3_PREFIX}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH} # for openrtm3.1.pc
installed
RESULT_VARIABLE _make_failed)
if (_make_failed)
message(FATAL_ERROR "Compile hrpsys failed")
endif(_make_failed)
# move programs
# bin -> lib/hrpsys/
if(NOT EXISTS ${CATKIN_DEVEL_PREFIX}/lib/${PROJECT_NAME})
execute_process(
COMMAND cmake -E make_directory ${CATKIN_DEVEL_PREFIX}/lib/${PROJECT_NAME}
RESULT_VARIABLE _make_failed)
if (_make_failed)
message(FATAL_ERROR "make_directory ${CATKIN_DEVEL_PREFIX}/lib/${PROJECT_NAME} failed: ${_make_failed}")
endif(_make_failed)
endif()
execute_process(
COMMAND grep ${CATKIN_DEVEL_PREFIX}/bin ${CMAKE_CURRENT_BINARY_DIR}/build/hrpsys-base/install_manifest.txt
OUTPUT_VARIABLE _bin_files
RESULT_VARIABLE _grep_failed)
if (_grep_failed)
message(FATAL_ERROR "grep : ${CMAKE_CURRENT_BINARY_DIR}/build/hrpsys-base/install_manifest.txt ${_make_failed}")
endif(_grep_failed)
string(REGEX REPLACE "\n" ";" _bin_files ${_bin_files})
foreach(_bin_file ${_bin_files})
get_filename_component(_bin_file_name ${_bin_file} NAME)
execute_process(
COMMAND cmake -E rename ${CATKIN_DEVEL_PREFIX}/bin/${_bin_file_name} ${CATKIN_DEVEL_PREFIX}/lib/${PROJECT_NAME}/${_bin_file_name}
RESULT_VARIABLE _rename_failed)
message("move binary files ${CATKIN_DEVEL_PREFIX}/lib/${PROJECT_NAME}/${_bin_file_name}")
if (_rename_failed)
message(FATAL_ERROR "Move hrpsys/bin failed: ${_make_failed}")
endif(_rename_failed)
endforeach()
# move libraries
# lib -> {source}/lib
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/lib/)
execute_process(
COMMAND cmake -E make_directory ${PROJECT_SOURCE_DIR}/lib/
RESULT_VARIABLE _make_failed)
if (_make_failed)
message(FATAL_ERROR "make_directory ${PROJECT_SOURCE_DIR}/lib/ failed: ${_make_failed}")
endif(_make_failed)
endif()
execute_process(
COMMAND grep ${CATKIN_DEVEL_PREFIX}/lib/ ${CMAKE_CURRENT_BINARY_DIR}/build/hrpsys-base/install_manifest.txt
OUTPUT_VARIABLE _lib_files
RESULT_VARIABLE _grep_failed)
if (_grep_failed)
message(FATAL_ERROR "grep : ${CMAKE_CURRENT_BINARY_DIR}/build/hrpsys-base/install_manifest.txt ${_grep_failed}")
endif(_grep_failed)
string(REGEX REPLACE "\n" ";" _lib_files ${_lib_files})
foreach(_lib_file ${_lib_files})
get_filename_component(_lib_file_name ${_lib_file} NAME)
if(EXISTS ${CATKIN_DEVEL_PREFIX}/lib/${_lib_file_name})
if ("${_lib_file_name}" MATCHES "libhrp.*so") # libhrpsys*.so and libhrpIo.so remains in global directory
else() # RTC components goto `rospack find hrpsys`/lib directory
execute_process(
COMMAND cmake -E rename ${CATKIN_DEVEL_PREFIX}/lib/${_lib_file_name} ${PROJECT_SOURCE_DIR}/lib/${_lib_file_name}
RESULT_VARIABLE _rename_failed)
message("move library files ${PROJECT_SOURCE_DIR}/lib/${_lib_file_name}")
endif()
if (_rename_failed)
message(FATAL_ERROR "Move hrpsys/lib failed: ${_rename_failed}")
endif(_rename_failed)
endif()
endforeach()
# move share directory
if(EXISTS ${PROJECT_SOURCE_DIR}/share/)
execute_process(
COMMAND cmake -E remove_directory ${PROJECT_SOURCE_DIR}/share/
RESULT_VARIABLE _make_failed)
if (_make_failed)
message(FATAL_ERROR "remove_directory ${PROJECT_SOURCE_DIR}/share/share failed: ${_make_failed}")
endif(_make_failed)
endif()
execute_process(
COMMAND cmake -E make_directory ${PROJECT_SOURCE_DIR}/share/
RESULT_VARIABLE _make_failed)
if (_make_failed)
message(FATAL_ERROR "make_directory ${PROJECT_SOURCE_DIR}/share/share failed: ${_make_failed}")
endif(_make_failed)
execute_process(
COMMAND cmake -E rename ${CATKIN_DEVEL_PREFIX}/share/hrpsys ${PROJECT_SOURCE_DIR}/share/hrpsys
RESULT_VARIABLE _make_failed)
message("move share directory ${CATKIN_DEVEL_PREFIX}/share/hrpsys ${PROJECT_SOURCE_DIR}/share/hrpsys")
if (_make_failed)
message(FATAL_ERROR "Move share/hrpsys failed: ${_make_failed}")
endif(_make_failed)
if(EXISTS ${CATKIN_DEVEL_PREFIX}/share/doc)
execute_process(
COMMAND cmake -E rename ${CATKIN_DEVEL_PREFIX}/share/doc ${PROJECT_SOURCE_DIR}/share/doc
RESULT_VARIABLE _make_failed)
message("move doc directory ${CATKIN_DEVEL_PREFIX}/share/doc ${PROJECT_SOURCE_DIR}/share/doc")
if (_make_failed)
message(FATAL_ERROR "Move share/doc failed: ${_make_failed}")
endif(_make_failed)
endif()
# copy src
execute_process(
COMMAND cmake -E make_directory ${PROJECT_SOURCE_DIR}/src/
RESULT_VARIABLE _make_failed)
if (_make_failed)
message(FATAL_ERROR "make_directory ${PROJECT_SOURCE_DIR}/src failed: ${_make_failed}")
endif(_make_failed)
execute_process(
COMMAND cmake -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/build/hrpsys-base-source/rtc/ ${PROJECT_SOURCE_DIR}/src/rtc
RESULT_VARIABLE _make_failed)
message("copy src directory ${CATKIN_DEVEL_PREFIX}/build/hrpsys-base-source/ ${PROJECT_SOURCE_DIR}/src")
if (_make_failed)
message(FATAL_ERROR "copy src failed: ${_make_failed}")
endif(_make_failed)
execute_process(
COMMAND cmake -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/build/hrpsys-base-source/ec/ ${PROJECT_SOURCE_DIR}/src/ec
RESULT_VARIABLE _make_failed)
message("copy ec directory ${CATKIN_DEVEL_PREFIX}/build/hrpsys-base-source/ ${PROJECT_SOURCE_DIR}/src")
if (_make_failed)
message(FATAL_ERROR "copy src failed: ${_make_failed}")
endif(_make_failed)
# copy samples
message("openhrp3_SOURCE_DIR=${openhrp3_SOURCE_DIR}")
message(" openhrp3_PREFIX=${openhrp3_PREFIX}")
file(GLOB _conf_files "${PROJECT_SOURCE_DIR}/share/hrpsys/samples/*/*.conf" "${PROJECT_SOURCE_DIR}/share/hrpsys/samples/*/*.xml" "${PROJECT_SOURCE_DIR}/share/hrpsys/samples/*/*.py")
foreach(_conf_file ${_conf_files})
if (EXISTS ${openhrp3_SOURCE_DIR})
message("sed -i s@\$(PROJECT_DIR)@${openhrp3_SOURCE_DIR}/share/OpenHRP-3.1/sample/project@g ${_conf_file}")
execute_process(COMMAND sed -i s@\$\(PROJECT_DIR\)@${openhrp3_SOURCE_DIR}/share/OpenHRP-3.1/sample/project@g ${_conf_file})
message("sed -i s@${CATKIN_DEVEL_PREFIX}/share/OpenHRP-3.1@${openhrp3_SOURCE_DIR}/share/OpenHRP-3.1@g ${_conf_file}")
execute_process(COMMAND sed -i s@${CATKIN_DEVEL_PREFIX}/share/OpenHRP-3.1@${openhrp3_SOURCE_DIR}/share/OpenHRP-3.1@g ${_conf_file})
else()
message("sed -i s@\$(PROJECT_DIR)@${openhrp3_PREFIX}/share/openhrp3/share/OpenHRP-3.1/sample/project@g ${_conf_file}")
execute_process(COMMAND sed -i s@\$\(PROJECT_DIR\)@${openhrp3_PREFIX}/share/openhrp3/share/OpenHRP-3.1/sample/project@g ${_conf_file})
message("sed -i s@${openhrp3_PREFIX}/share/OpenHRP-3.1@${openhrp3_PREFIX}/share/openhrp3/share/OpenHRP-3.1@g ${_conf_file}")
execute_process(COMMAND sed -i s@${openhrp3_PREFIX}/share/OpenHRP-3.1@${openhrp3_PREFIX}/share/openhrp3/share/OpenHRP-3.1@g ${_conf_file})
endif()
message("sed -i s@${CATKIN_DEVEL_PREFIX}/lib@${PROJECT_SOURCE_DIR}/lib@s ${_conf_file} ")
execute_process(COMMAND sed -i s@${CATKIN_DEVEL_PREFIX}/lib@${PROJECT_SOURCE_DIR}/lib@g ${_conf_file})
message("sed -i s@${CATKIN_DEVEL_PREFIX}/share@${PROJECT_SOURCE_DIR}/share@s ${_conf_file} ")
execute_process(COMMAND sed -i s@${CATKIN_DEVEL_PREFIX}/share@${PROJECT_SOURCE_DIR}/share@g ${_conf_file})
endforeach()
message("fix ${CATKIN_DEVEL_PREFIX}/lib/pkgconfig/hrpsys-base.pc")
execute_process(COMMAND sed -i s@\${prefix}/share@${PROJECT_SOURCE_DIR}/share@g ${CATKIN_DEVEL_PREFIX}/lib/pkgconfig/hrpsys-base.pc) # basic
endif(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/installed)
# #
catkin_package(
)
set(ENV{PKG_CONFIG_PATH} ${CATKIN_DEVEL_PREFIX}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH})
execute_process(COMMAND pkg-config openhrp3.1 --variable=idl_dir OUTPUT_VARIABLE hrp_idldir OUTPUT_STRIP_TRAILING_WHITESPACE)
get_filename_component(OPENHRP3_SAMPLE_DIR "${hrp_idldir}/../sample" ABSOLUTE)
# #
install(
DIRECTORY ${CATKIN_DEVEL_PREFIX}/include/hrpsys
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION})
install(
FILES ${CATKIN_DEVEL_PREFIX}/lib/pkgconfig/hrpsys-base.pc
DESTINATION ${CATKIN_GLOBAL_LIB_DESTINATION}/pkgconfig)
install(DIRECTORY lib/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/lib
USE_SOURCE_PERMISSIONS)
install(DIRECTORY test share samples src
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
USE_SOURCE_PERMISSIONS)
## copy CATKIN_DEVEL_PREFIX/lib directory
execute_process(
COMMAND grep ${CATKIN_DEVEL_PREFIX}/bin ${CMAKE_CURRENT_BINARY_DIR}/build/hrpsys-base/install_manifest.txt
OUTPUT_VARIABLE _bin_files
RESULT_VARIABLE _grep_failed)
if (_grep_failed)
message(FATAL_ERROR "grep : ${CMAKE_CURRENT_BINARY_DIR}/build/hrpsys-base/install_manifest.txt ${_make_failed}")
endif(_grep_failed)
string(REGEX REPLACE "\n" ";" _bin_files ${_bin_files})
foreach(_bin_file ${_bin_files})
get_filename_component(_bin_file_name ${_bin_file} NAME)
install(PROGRAMS ${CATKIN_DEVEL_PREFIX}/lib/${PROJECT_NAME}/${_bin_file_name} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}/${PROJECT_NAME})
endforeach()
execute_process(
COMMAND grep ${CATKIN_DEVEL_PREFIX}/lib/ ${CMAKE_CURRENT_BINARY_DIR}/build/hrpsys-base/install_manifest.txt
OUTPUT_VARIABLE _lib_files
RESULT_VARIABLE _grep_failed)
if (_grep_failed)
message(FATAL_ERROR "grep : ${CMAKE_CURRENT_BINARY_DIR}/build/hrpsys-base/install_manifest.txt ${_grep_failed}")
endif(_grep_failed)
string(REGEX REPLACE "\n" ";" _lib_files ${_lib_files})
foreach(_lib_file ${_lib_files})
get_filename_component(_lib_file_name ${_lib_file} NAME)
if ("${_lib_file}" MATCHES "lib/python*")
# install all python code
string(REGEX REPLACE "${CATKIN_DEVEL_PREFIX}/lib" "" _py_file ${_lib_file})
get_filename_component(_py_file_dir ${_py_file} PATH)
#install(PROGRAMS ${CATKIN_DEVEL_PREFIX}/lib/${_py_file} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}/${_py_file_dir})
install(DIRECTORY ${CATKIN_DEVEL_PREFIX}/lib/${_py_file_dir}/ DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}/${_py_file_dir})
elseif ("${_lib_file_name}" MATCHES "libhrp.*so") # libhrpsys*.so and libhrpIo.so remains in global directory
install(PROGRAMS ${CATKIN_DEVEL_PREFIX}/lib/${_lib_file_name} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
endif()
endforeach()
## done copy libs
install(CODE
"execute_process(COMMAND echo \"fix ${_conf_file} ${PROJECT_SOURCE_DIR} -> ${CMAKE_INSTALL_PREFIX}\")
if (EXISTS ${openhrp3_SOURCE_DIR})
execute_process(COMMAND echo \" ${openhrp3_SOURCE_DIR} -> ${openhrp3_PREFIX}/share/openhrp3\")
endif()
execute_process(COMMAND echo \" ${CATKIN_DEVEL_PREFIX} -> ${CMAKE_INSTALL_PREFIX}\")
file(GLOB _conf_files \"\$ENV{DISTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/share/hrpsys/samples/*/*.*\")
file(GLOB _sample_files \"\$ENV{DISTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/samples/SampleRobot/*.*\")
foreach(_conf_file \${_conf_files} \${_sample_files})
execute_process(COMMAND echo \"fix \${_conf_file}\")
if (EXISTS ${openhrp3_SOURCE_DIR})
execute_process(COMMAND sed -i s@${openhrp3_SOURCE_DIR}/share/OpenHRP-3.1@${openhrp3_PREFIX}/share/openhrp3/share/OpenHRP-3.1@g \${_conf_file})
endif()
execute_process(COMMAND sed -i s@${PROJECT_SOURCE_DIR}/share@${CMAKE_INSTALL_PREFIX}/share/hrpsys/share@g \${_conf_file})
execute_process(COMMAND sed -i s@${PROJECT_SOURCE_DIR}/lib@${CMAKE_INSTALL_PREFIX}/share/hrpsys/lib@g \${_conf_file})
execute_process(COMMAND sed -i s@${CATKIN_DEVEL_PREFIX}@${CMAKE_INSTALL_PREFIX}@g \${_conf_file})
endforeach()
")
install(CODE
"# check if hrpsys-base.pc exists
if (NOT EXISTS \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/hrpsys-base.pc )
message(FATAL_ERROR \"FATAL_ERROR \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/hrpsys-base.pc is not exists\")
endif()
execute_process(COMMAND echo \"fix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/hrpsys-base.pc ${CATKIN_DEVEL_PREFIX} -> ${CMAKE_INSTALL_PREFIX}\")
execute_process(COMMAND sed -i s@${CATKIN_DEVEL_PREFIX}@${CMAKE_INSTALL_PREFIX}@g \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/hrpsys-base.pc) # basic
execute_process(COMMAND sed -i s@{prefix}/bin@${prefix}/lib/hrpsys@g \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/hrpsys-base.pc) # basic
execute_process(COMMAND sed -i s@${PROJECT_SOURCE_DIR}/share@\\\${prefix}/share/hrpsys/share@g \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}/pkgconfig/hrpsys-base.pc) # basic
")
install(CODE
"# check if stable rtc exists
message(STATUS \"check if \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_BIN_DESTINATION}/hrpsys-simulator exists\")
if (NOT EXISTS \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_BIN_DESTINATION}/hrpsys-simulator )
message(FATAL_ERROR \"FATAL_ERROR \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_BIN_DESTINATION}/hrpsys-simulator does not exists\")
endif()
# PYTHONPATH=install/lib/python2.7/dist-packages:$PYTHONPATH python -c 'from hrpsys.hrpsys_config import *; print(\";\".join(map((lambda rtc: rtc[1]), HrpsysConfigurator.__new__(HrpsysConfigurator).getRTCListUnstable())))'
foreach(_rtc SequencePlayer;StateHolder;ForwardKinematics;TorqueFilter;KalmanFilter;VirtualForceSensor;RemoveForceSensorLinkOffset;ImpedanceController;AutoBalancer;Stabilizer;CollisionDetector;TorqueController;SoftErrorLimiter;DataLogger)
message(STATUS \"check if \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/lib/\${_rtc}.so exists\")
if (NOT EXISTS \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/lib/\${_rtc}.so )
message(FATAL_ERROR \"FATAL_ERROR \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/lib/\${_rtc}.so does not exists\")
endif()
endforeach()
")
add_rostest(test/test-hrpsys.test)
add_rostest(test/test-colcheck.test)
add_rostest(test/test-pa10.test)
add_rostest(test/test-simulator.test)