-
Notifications
You must be signed in to change notification settings - Fork 236
/
CMakeLists.txt
303 lines (247 loc) · 12 KB
/
CMakeLists.txt
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(gpd)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 14)
# Eigen library
include_directories(${EIGEN3_INCLUDE_DIR})
# PCL
find_package(PCL 1.9 REQUIRED)
#find_package(PCL 1.8 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
# OpenCV
find_package(OpenCV REQUIRED)
#find_package(OpenCV REQUIRED PATHS /usr/local NO_DEFAULT_PATH)
## Set compiler optimization flags
# set(CMAKE_CXX_FLAGS "-O3 -fopenmp -fPIC -Wno-deprecated -Wenum-compare -std=c++14")
#set(CMAKE_CXX_FLAGS "-O3 -fopenmp -fPIC -Wno-deprecated -Wenum-compare -Wno-ignored-attributes -std=c++17")
#set(CMAKE_CXX_FLAGS "-fopenmp -fPIC -Wno-deprecated -Wenum-compare -Wno-ignored-attributes -std=c++17")
# set(CMAKE_CXX_FLAGS "-O3 -fopenmp -fPIC -Wno-deprecated -Wenum-compare")
# set(CMAKE_CXX_FLAGS "-O3 -fopenmp -march=native -mfpmath=sse -funroll-loops -fPIC -Wno-deprecated -Wenum-compare") # no improvement
# set(CMAKE_CXX_FLAGS "-frename-registers -Ofast -march=native -fopenmp -fPIC -Wno-deprecated -Wenum-compare") # no improvement
#set(CMAKE_CXX_FLAGS "-fopenmp -fPIC -Wno-deprecated -Wenum-compare -Wno-ignored-attributes -std=c++17")
set(CMAKE_CXX_FLAGS "-O3 -march=native -mtune=intel -msse4.2 -mavx2 -mfma -flto -fopenmp -fPIC -Wno-deprecated -Wenum-compare -Wno-ignored-attributes -std=c++17")
## Specify additional locations of header files
include_directories(include ${PCL_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
# Classifier depends on what libraries are installed.
option(USE_OPENVINO "use classifier based on OpenVINO toolkit" OFF)
option(USE_CAFFE "use classifier based on Caffe framework" OFF)
option(USE_OPENCV "use classifier based on OpenCV framework" OFF)
if(USE_OPENVINO STREQUAL "ON")
find_package(InferenceEngine 1.0)
if (NOT InferenceEngine_FOUND)
message(FATAL_ERROR "Please install OpenVINO https://software.intel.com/en-us/articles/OpenVINO-Install-Linux")
endif()
include_directories(${InferenceEngine_INCLUDE_DIRS})
link_directories(${InferenceEngine_LIBRARY_DIRS})
add_definitions(-DUSE_OPENVINO)
get_filename_component(MODELS_DIR "models/openvino" ABSOLUTE)
configure_file(include/gpd/net/openvino_classifier.h.in gpd/net/openvino_classifier.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(classifier_src src/${PROJECT_NAME}/net/classifier.cpp src/${PROJECT_NAME}/net/openvino_classifier.cpp)
set(classifier_dep ${InferenceEngine_LIBRARIES})
message("Using OpenVINO")
elseif(USE_CAFFE STREQUAL "ON")
find_package(Caffe)
if (NOT Caffe_FOUND)
message(FATAL_ERROR "Please install Caffe https://caffe.berkeleyvision.org/installation.html")
endif()
include_directories(${Caffe_INCLUDE_DIRS})
add_definitions(${Caffe_DEFINITIONS})
add_definitions(-DUSE_CAFFE)
set(classifier_src src/${PROJECT_NAME}/net/classifier.cpp src/${PROJECT_NAME}/net/caffe_classifier.cpp)
set(classifier_dep ${Caffe_LIBRARIES} ${OpenCV_LIBRARIES})
elseif(USE_OPENCV STREQUAL "ON")
message(FATAL_ERROR "Not supported yet")
else()
add_library(${PROJECT_NAME}_conv_layer src/${PROJECT_NAME}/net/conv_layer.cpp)
add_library(${PROJECT_NAME}_dense_layer src/${PROJECT_NAME}/net/dense_layer.cpp)
set(classifier_src src/${PROJECT_NAME}/net/classifier.cpp src/${PROJECT_NAME}/net/eigen_classifier.cpp)
set(classifier_dep ${PROJECT_NAME}_conv_layer ${PROJECT_NAME}_dense_layer ${OpenCV_LIBRARIES})
endif()
# Optional PCL GPU operations
option(USE_PCL_GPU "use PCL GPU for point cloud operations" OFF)
if(USE_PCL_GPU STREQUAL "ON")
FIND_PACKAGE(CUDA)
if (NOT CUDA_FOUND)
message(FATAL_ERROR "Please install CUDA and compile PCL with Nvidia GPU flags http://pointclouds.org/documentation/tutorials/gpu_install.php")
endif()
INCLUDE(FindCUDA)
add_definitions(-DUSE_PCL_GPU)
message("Using the GPU with PCL")
endif()
# Optional data generation (requires OpenCV Contrib)
option(BUILD_DATA_GENERATION "build data generation (requires OpenCV Contrib for HDF5)" OFF)
if(BUILD_DATA_GENERATION STREQUAL "ON")
add_library(${PROJECT_NAME}_data_generator src/${PROJECT_NAME}/data_generator.cpp)
target_link_libraries(${PROJECT_NAME}_data_generator
${PROJECT_NAME}_grasp_detector
${PCL_LIBRARIES}
${OpenCV_LIBS})
add_executable(${PROJECT_NAME}_generate_data src/generate_data.cpp)
target_link_libraries(${PROJECT_NAME}_generate_data
${PROJECT_NAME}_data_generator)
message("Building data generation module")
endif()
# Generate the shared library from the sources
add_library(${PROJECT_NAME}_grasp_detector SHARED src/${PROJECT_NAME}/grasp_detector.cpp)
add_library(${PROJECT_NAME}_classifier ${classifier_src})
target_link_libraries(${PROJECT_NAME}_classifier
${classifier_dep})
add_library(${PROJECT_NAME}_clustering src/${PROJECT_NAME}/clustering.cpp)
add_library(${PROJECT_NAME}_sequential_importance_sampling src/${PROJECT_NAME}/sequential_importance_sampling.cpp)
# namespace candidate
add_library(${PROJECT_NAME}_antipodal src/${PROJECT_NAME}/candidate/antipodal.cpp)
add_library(${PROJECT_NAME}_candidates_generator src/${PROJECT_NAME}/candidate/candidates_generator.cpp)
add_library(${PROJECT_NAME}_finger_hand src/${PROJECT_NAME}/candidate/finger_hand.cpp)
add_library(${PROJECT_NAME}_frame_estimator src/${PROJECT_NAME}/candidate/frame_estimator.cpp)
add_library(${PROJECT_NAME}_hand src/${PROJECT_NAME}/candidate/hand.cpp)
add_library(${PROJECT_NAME}_hand_set src/${PROJECT_NAME}/candidate/hand_set.cpp)
add_library(${PROJECT_NAME}_hand_geometry src/${PROJECT_NAME}/candidate/hand_geometry.cpp)
add_library(${PROJECT_NAME}_hand_search src/${PROJECT_NAME}/candidate/hand_search.cpp)
add_library(${PROJECT_NAME}_local_frame src/${PROJECT_NAME}/candidate/local_frame.cpp)
# namespace util
add_library(${PROJECT_NAME}_cloud src/${PROJECT_NAME}/util/cloud.cpp)
add_library(${PROJECT_NAME}_config_file src/${PROJECT_NAME}/util/config_file.cpp)
add_library(${PROJECT_NAME}_eigen_utils src/${PROJECT_NAME}/util/eigen_utils.cpp)
add_library(${PROJECT_NAME}_plot src/${PROJECT_NAME}/util/plot.cpp)
add_library(${PROJECT_NAME}_point_list src/${PROJECT_NAME}/util/point_list.cpp)
# namespace descriptor
add_library(${PROJECT_NAME}_image_strategy src/${PROJECT_NAME}/descriptor/image_strategy.cpp)
add_library(${PROJECT_NAME}_image_1_channels_strategy src/${PROJECT_NAME}/descriptor/image_1_channels_strategy.cpp)
add_library(${PROJECT_NAME}_image_3_channels_strategy src/${PROJECT_NAME}/descriptor/image_3_channels_strategy.cpp)
add_library(${PROJECT_NAME}_image_12_channels_strategy src/${PROJECT_NAME}/descriptor/image_12_channels_strategy.cpp)
add_library(${PROJECT_NAME}_image_15_channels_strategy src/${PROJECT_NAME}/descriptor/image_15_channels_strategy.cpp)
add_library(${PROJECT_NAME}_image_geometry src/${PROJECT_NAME}/descriptor/image_geometry.cpp)
add_library(${PROJECT_NAME}_image_generator src/${PROJECT_NAME}/descriptor/image_generator.cpp)
## Declare C++ executables
add_executable(${PROJECT_NAME}_cem_detect_grasps src/cem_detect_grasps.cpp)
add_executable(${PROJECT_NAME}_detect_grasps src/detect_grasps.cpp)
add_executable(${PROJECT_NAME}_generate_candidates src/generate_candidates.cpp)
add_executable(${PROJECT_NAME}_label_grasps src/label_grasps.cpp)
add_executable(${PROJECT_NAME}_test_grasp_image src/tests/test_grasp_image.cpp)
# add_executable(${PROJECT_NAME}_test_conv_layer src/tests/test_conv_layer.cpp)
# add_executable(${PROJECT_NAME}_test_hdf5 src/tests/test_hdf5.cpp)
## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}_clustering
${PROJECT_NAME}_hand)
target_link_libraries(${PROJECT_NAME}_grasp_detector
${PROJECT_NAME}_clustering
${PROJECT_NAME}_image_generator
${PROJECT_NAME}_classifier
${PROJECT_NAME}_candidates_generator
${PROJECT_NAME}_hand_geometry
${PROJECT_NAME}_hand_set
${PROJECT_NAME}_config_file
${PROJECT_NAME}_plot)
target_link_libraries(${PROJECT_NAME}_generate_candidates
${PROJECT_NAME}_config_file
${PROJECT_NAME}_candidates_generator)
# Linking for libraries
target_link_libraries(${PROJECT_NAME}_antipodal
${PROJECT_NAME}_point_list)
target_link_libraries(${PROJECT_NAME}_cloud
${PROJECT_NAME}_eigen_utils
${PCL_LIBRARIES})
target_link_libraries(${PROJECT_NAME}_eigen_utils
${EIGEN_LIBRARIES})
target_link_libraries(${PROJECT_NAME}_frame_estimator
${PROJECT_NAME}_cloud
${PROJECT_NAME}_local_frame)
target_link_libraries(${PROJECT_NAME}_hand
${PROJECT_NAME}_finger_hand)
target_link_libraries(${PROJECT_NAME}_hand_set
${PROJECT_NAME}_antipodal
${PROJECT_NAME}_config_file
${PROJECT_NAME}_hand
${PROJECT_NAME}_hand_geometry
${PROJECT_NAME}_local_frame
${PROJECT_NAME}_point_list)
target_link_libraries(${PROJECT_NAME}_hand_geometry
${PROJECT_NAME}_config_file)
target_link_libraries(${PROJECT_NAME}_hand_search
${PROJECT_NAME}_antipodal
${PROJECT_NAME}_cloud
${PROJECT_NAME}_frame_estimator
${PROJECT_NAME}_hand_set
${PROJECT_NAME}_hand_geometry
${PROJECT_NAME}_plot)
target_link_libraries(${PROJECT_NAME}_plot
${PROJECT_NAME}_cloud
${PROJECT_NAME}_hand_set
${PROJECT_NAME}_image_geometry
${PROJECT_NAME}_local_frame)
target_link_libraries(${PROJECT_NAME}_candidates_generator
${PROJECT_NAME}_config_file
${PROJECT_NAME}_hand_geometry
${PROJECT_NAME}_hand_search)
target_link_libraries(${PROJECT_NAME}_point_list
${PROJECT_NAME}_eigen_utils)
target_link_libraries(${PROJECT_NAME}_image_strategy
${PROJECT_NAME}_image_geometry
${PROJECT_NAME}_image_1_channels_strategy
${PROJECT_NAME}_image_3_channels_strategy
${PROJECT_NAME}_image_12_channels_strategy
${PROJECT_NAME}_image_15_channels_strategy
${PROJECT_NAME}_hand_set
${OpenCV_LIBS})
target_link_libraries(${PROJECT_NAME}_image_1_channels_strategy
${PROJECT_NAME}_image_strategy)
target_link_libraries(${PROJECT_NAME}_image_3_channels_strategy
${PROJECT_NAME}_image_strategy)
target_link_libraries(${PROJECT_NAME}_image_12_channels_strategy
${PROJECT_NAME}_image_strategy)
target_link_libraries(${PROJECT_NAME}_image_15_channels_strategy
${PROJECT_NAME}_image_strategy)
target_link_libraries(${PROJECT_NAME}_image_geometry
${PROJECT_NAME}_config_file)
target_link_libraries(${PROJECT_NAME}_image_generator
${PROJECT_NAME}_image_strategy
${PROJECT_NAME}_hand_set
${PROJECT_NAME}_image_strategy
${PROJECT_NAME}_cloud
${PROJECT_NAME}_eigen_utils)
target_link_libraries(${PROJECT_NAME}_sequential_importance_sampling
${PROJECT_NAME}_grasp_detector)
target_link_libraries(${PROJECT_NAME}_test_grasp_image
${PROJECT_NAME}_image_generator
${PROJECT_NAME}_classifier
${PROJECT_NAME}_plot
${PROJECT_NAME}_candidates_generator
${PCL_LIBRARIES})
target_link_libraries(${PROJECT_NAME}_detect_grasps
${PROJECT_NAME}_grasp_detector
${PROJECT_NAME}_config_file
${PCL_LIBRARIES})
target_link_libraries(${PROJECT_NAME}_label_grasps
${PROJECT_NAME}_grasp_detector
${PROJECT_NAME}_config_file
${PCL_LIBRARIES})
target_link_libraries(${PROJECT_NAME}_cem_detect_grasps
${PROJECT_NAME}_sequential_importance_sampling
${PROJECT_NAME}_config_file
${PCL_LIBRARIES})
target_link_libraries(${PROJECT_NAME}_image_generator
${PROJECT_NAME}_hand_set
${PROJECT_NAME}_image_strategy)
# Rename targets to simplify their names.
set_target_properties(${PROJECT_NAME}_test_grasp_image
PROPERTIES OUTPUT_NAME test_grasp_image PREFIX "")
set_target_properties(${PROJECT_NAME}_cem_detect_grasps
PROPERTIES OUTPUT_NAME cem_detect_grasps PREFIX "")
set_target_properties(${PROJECT_NAME}_detect_grasps
PROPERTIES OUTPUT_NAME detect_grasps PREFIX "")
set_target_properties(${PROJECT_NAME}_generate_candidates
PROPERTIES OUTPUT_NAME generate_candidates PREFIX "")
if(BUILD_DATA_GENERATION STREQUAL "ON")
set_target_properties(${PROJECT_NAME}_generate_data
PROPERTIES OUTPUT_NAME generate_data PREFIX "")
endif()
set_target_properties(${PROJECT_NAME}_label_grasps
PROPERTIES OUTPUT_NAME label_grasps PREFIX "")
set_target_properties(${PROJECT_NAME}_grasp_detector
PROPERTIES OUTPUT_NAME gpd)
# Set the location for library installation
install(TARGETS ${PROJECT_NAME}_grasp_detector DESTINATION lib)
install(DIRECTORY include/gpd DESTINATION include)