@@ -3,19 +3,17 @@ cmake_minimum_required(VERSION 3.14)
33project (sam_onnx_ros)
44
55# -------------- CMake Policies ------------------#
6- #add_compile_options(-Wall -Werror=all)
7- #add_compile_options(-Wextra -Werror=extra)
6+ # add_compile_options(-Wall -Werror=all)
7+ # add_compile_options(-Wextra -Werror=extra)
88
99# -------------- Support C++17 for using filesystem ------------------#
1010set (CMAKE_CXX_STANDARD 17)
1111set (CMAKE_CXX_STANDARD_REQUIRED ON )
12- set (CMAKE_CXX_EXTENSIONS ON )
13- #set(CMAKE_INCLUDE_CURRENT_DIR ON)
1412set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
13+
1514# -------------- OpenCV ------------------#
1615find_package (OpenCV REQUIRED)
17- include_directories (${OpenCV_INCLUDE_DIRS} )
18-
16+ find_package (console_bridge REQUIRED)
1917
2018# -------------- ONNXRuntime ------------------#
2119set (ONNXRUNTIME_VERSION 1.21.0)
@@ -26,94 +24,124 @@ include_directories(${ONNXRUNTIME_ROOT}/include)
2624add_definitions (-DUSE_CUDA=1)
2725include_directories (/usr/local/cuda/include )
2826
27+ # -------------- Models ------------------#
28+ # TODO: Find proper folder Copy sam_<model>.onnx file to the same folder of the executable file
29+ configure_file (~/Documents/repos/hero_sam.bak/sam_inference/model/SAM_mask_decoder.onnx ${CMAKE_CURRENT_BINARY_DIR} /SAM_mask_decoder.onnx COPYONLY )
30+ configure_file (~/Documents/repos/hero_sam.bak/sam_inference/model/SAM_encoder.onnx ${CMAKE_CURRENT_BINARY_DIR} /SAM_encoder.onnx COPYONLY )
31+
32+
2933find_package (catkin REQUIRED
3034 COMPONENTS
31- # roscpp
32- # tue_config
33- # tue_filesystem
34- # code_profiler
35-
35+ rosconsole
36+ console_bridge
3637 #onnxruntime_ros
3738)
3839
40+ find_package (console_bridge REQUIRED)
41+
3942# ------------------------------------------------------------------------------------------------
4043# CATKIN EXPORT
4144# ------------------------------------------------------------------------------------------------
4245
4346catkin_package(
4447 INCLUDE_DIRS include
45- #LIBRARIES ${PROJECT_NAME}
46- LIBRARIES sam_onnx_ros_core
48+ LIBRARIES ${PROJECT_NAME} _lib
4749 CATKIN_DEPENDS
48- DEPENDS OpenCV
50+ DEPENDS OpenCV console_bridge
4951)
5052
5153# ------------------------------------------------------------------------------------------------
5254# BUILD
5355# ------------------------------------------------------------------------------------------------
5456
55- include_directories (
56- include
57- SYSTEM
58- ${OpenCV_INCLUDE_DIRS}
59- ${catkin_INCLUDE_DIRS}
60- )
61-
62- set (PROJECT_SOURCES
63- src/main.cpp
57+ # Build core library
58+ add_library (${PROJECT_NAME} _lib
6459 src/sam_inference.cpp
6560 src/segmentation.cpp
6661 src/utils.cpp
6762)
6863
69- # Build core library (no main.cpp here)
70- add_library (sam_onnx_ros_core
71- src/sam_inference.cpp
72- src/segmentation.cpp
73- src/utils.cpp
64+ target_include_directories (${PROJECT_NAME} _lib
65+ PUBLIC
66+ include
67+ SYSTEM
68+ ${OpenCV_INCLUDE_DIRS}
69+ ${catkin_INCLUDE_DIRS}
70+ ${console_bridge_INCLUDE_DIRS}
71+ ${ONNXRUNTIME_ROOT} /include
7472)
75- target_link_libraries (sam_onnx_ros_core
73+
74+
75+ target_link_libraries (${PROJECT_NAME} _lib
7676 ${OpenCV_LIBS}
7777 ${catkin_LIBRARIES}
7878 ${ONNXRUNTIME_ROOT} /lib/libonnxruntime.so
7979)
80- target_include_directories (sam_onnx_ros_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /include )
8180
8281# Main executable links the core lib
83- add_executable (${PROJECT_NAME} src/main.cpp)
84- target_link_libraries (${PROJECT_NAME} sam_onnx_ros_core)
82+ add_executable (${PROJECT_NAME}
83+ src/main.cpp
84+ )
8585
86- # Copy sam_<model>.onnx file to the same folder of the executable file
87- configure_file (~/Documents/repos/hero_sam.bak/sam_inference/model/SAM_mask_decoder.onnx ${CMAKE_CURRENT_BINARY_DIR} /SAM_mask_decoder.onnx COPYONLY )
88- configure_file (~/Documents/repos/hero_sam.bak/sam_inference/model/SAM_encoder.onnx ${CMAKE_CURRENT_BINARY_DIR} /SAM_encoder.onnx COPYONLY )
86+ target_link_libraries (${PROJECT_NAME}
87+ ${PROJECT_NAME} _lib
88+ ${catkin_LIBRARIES}
89+ ${ONNXRUNTIME_ROOT} /lib/libonnxruntime.so
90+ )
91+
92+ # ------------------------------------------------------------------------------------------------
93+ # Install Targets
94+ # ------------------------------------------------------------------------------------------------
95+
96+ install (
97+ DIRECTORY include /
98+ DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}
99+ )
89100
90- # Create folder name images in the same folder of the executable file
91- add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
92- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR} /images
101+ install (
102+ TARGETS
103+ ${PROJECT_NAME} _lib
104+ ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
105+ LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
106+ RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
93107)
94108
95- # # Enable testing
109+ install (
110+ TARGETS
111+ ${PROJECT_NAME}
112+ DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
113+ )
114+
115+ # ------------------------------------------------------------------------------------------------
116+ # Testing
117+ # ------------------------------------------------------------------------------------------------
96118if (CATKIN_ENABLE_TESTING)
97- # find_package(catkin_lint_cmake REQUIRED)
98- # catkin_add_catkin_lint_test("-W2 --ignore HEADER_OUTSIDE_PACKAGE_INCLUDE_PATH")
119+ # find_package(catkin_lint_cmake REQUIRED)
120+ # catkin_add_catkin_lint_test("-W2 --ignore HEADER_OUTSIDE_PACKAGE_INCLUDE_PATH")
99121
100122 # Utils unit tests (no models needed)
101123 catkin_add_gtest(utils_tests test /test_utils.cpp)
102124 if (TARGET utils_tests)
103- target_link_libraries (utils_tests sam_onnx_ros_core GTest::gtest_main ${catkin_LIBRARIES} )
104- target_include_directories (utils_tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /include )
125+ target_link_libraries (
126+ utils_tests
127+ ${PROJECT_NAME} _lib
128+ ${catkin_LIBRARIES}
129+ GTest::gtest
130+ GTest::gtest_main
131+ )
132+ #target_include_directories(utils_tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
105133 endif ()
106134
107135 # SAM integration-ish tests (may need models)
108136 catkin_add_gtest(sam_tests test /sam_test.cpp)
109137 if (TARGET sam_tests)
110- target_link_libraries (sam_tests sam_onnx_ros_core GTest::gtest_main ${catkin_LIBRARIES} )
111- target_include_directories (sam_tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /include )
138+ target_link_libraries (
139+ sam_tests
140+ ${PROJECT_NAME} _lib
141+ ${catkin_LIBRARIES}
142+ GTest::gtest
143+ GTest::gtest_main
144+ )
145+ #target_include_directories(sam_tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
112146 endif ()
113147endif ()
114-
115-
116-
117- #If you want to debug
118- # set(CMAKE_BUILD_TYPE Debug)
119- # set(CMAKE_CXX_FLAGS_DEBUG "-g")
0 commit comments