Skip to content

Commit e47390c

Browse files
committed
Find torch based on pip install
1 parent e0f90c2 commit e47390c

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

ed_sensor_integration/CMakeLists.txt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ project(ed_sensor_integration)
44
add_compile_options(-Wall -Werror=all)
55
add_compile_options(-Wextra -Werror=extra)
66

7+
find_package (Python COMPONENTS Interpreter REQUIRED)
8+
execute_process(
9+
COMMAND ${PYTHON_EXECUTABLE} -c "import torch; print(torch.__path__[0])"
10+
OUTPUT_VARIABLE TORCH_LIBRARY_PATH
11+
OUTPUT_STRIP_TRAILING_WHITESPACE
12+
ERROR_QUIET
13+
)
14+
message(VERBOSE "TORCH_LIBRARY_PATH: ${TORCH_LIBRARY_PATH}")
15+
716
find_package(OpenCV REQUIRED)
817
find_package(PCL REQUIRED COMPONENTS common kdtree)
18+
find_package(Torch 1.10 REQUIRED
19+
PATHS "${TORCH_LIBRARY_PATH}/share/cmake"
20+
)
921
find_package(catkin REQUIRED COMPONENTS
1022
code_profiler
1123
ed
@@ -31,7 +43,7 @@ catkin_package(
3143
INCLUDE_DIRS include
3244
LIBRARIES ed_kinect
3345
CATKIN_DEPENDS code_profiler ed ${PROJECT_NAME}_msgs geolib2 image_geometry rgbd rgbd_image_buffer roscpp tue_config visualization_msgs
34-
DEPENDS OpenCV PCL
46+
DEPENDS OpenCV PCL Torch
3547
)
3648

3749
# ------------------------------------------------------------------------------------------------
@@ -42,6 +54,7 @@ include_directories(
4254
include
4355
SYSTEM
4456
${OpenCV_INCLUDE_DIRS}
57+
${TORCH_INCLUDE_DIRS}
4558
${catkin_INCLUDE_DIRS}
4659
)
4760

@@ -121,6 +134,9 @@ target_link_libraries(ed_clearer_plugin ${catkin_LIBRARIES})
121134
# TOOLS
122135
# ------------------------------------------------------------------------------------------------
123136

137+
add_executable(test_torch tools/test_torch.cpp)
138+
target_link_libraries(test_torch ${TORCH_LIBRARIES})
139+
124140
add_executable(ed_image_saver tools/image_saver.cpp)
125141
target_link_libraries(ed_image_saver ${catkin_LIBRARIES})
126142
add_dependencies(ed_image_saver ${catkin_EXPORTED_TARGETS})
@@ -168,6 +184,7 @@ install(
168184
ed_fitter_live
169185
ed_image_saver
170186
ed_segmenter
187+
test_torch
171188
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
172189
)
173190

@@ -184,6 +201,3 @@ if (CATKIN_ENABLE_TESTING)
184201
catkin_add_gtest(test_laser_fitting test/test_laser_segmenter.cpp)
185202
target_link_libraries(test_laser_fitting ${PROJECT_NAME}_console_bridge ed_laser ${OpenCV_LIBRARIES} ${catkin_LIBRARIES})
186203
endif ()
187-
188-
189-
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <torch/torch.h>
2+
#include <iostream>
3+
4+
int main() {
5+
torch::Tensor tensor = torch::eye(3);
6+
std::cout << tensor << std::endl;
7+
}

0 commit comments

Comments
 (0)