Skip to content

Commit

Permalink
Make rct_image_tools a pure CMake package (#45)
Browse files Browse the repository at this point in the history
* make rct_image_tools a pure cmake package

* fix bad export of Eigen3::Eigen target

* add Eigen3 CMake target workaround to other RCT packages

* fix for missing EIGEN3_INCLUDE_DIRS in older versions of Eigen

* use set_property instead of set_target_properties
  • Loading branch information
schornakj authored Jun 24, 2020
1 parent b95728a commit 29d66b3
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 74 deletions.
29 changes: 17 additions & 12 deletions rct_examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ project(rct_examples)
add_compile_options(-std=c++11 -Wall -Wextra)

find_package(rct_optimizations REQUIRED)
find_package(rct_image_tools REQUIRED)

find_package(catkin REQUIRED COMPONENTS
rct_image_tools
rct_ros_tools
roslib
)
Expand All @@ -17,6 +17,12 @@ find_package(Eigen3 REQUIRED)
if(NOT EIGEN3_INCLUDE_DIRS)
set(EIGEN3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR})
endif()
if(NOT TARGET Eigen3::Eigen)
find_package(Threads REQUIRED)
add_library(Eigen3::Eigen IMPORTED INTERFACE)
set_property(TARGET Eigen3::Eigen PROPERTY INTERFACE_COMPILE_DEFINITIONS ${EIGEN3_DEFINITIONS})
set_property(TARGET Eigen3::Eigen PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${EIGEN3_INCLUDE_DIRS})
endif()

# This package only provides examples. It does not export any tools.
catkin_package()
Expand All @@ -27,7 +33,6 @@ catkin_package()

include_directories(
${catkin_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
)

#####################
Expand All @@ -39,7 +44,7 @@ set_target_properties(${PROJECT_NAME}_wrist_example PROPERTIES OUTPUT_NAME examp

add_dependencies(${PROJECT_NAME}_wrist_example ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}_wrist_example ${catkin_LIBRARIES} rct::rct_optimizations)
target_link_libraries(${PROJECT_NAME}_wrist_example ${catkin_LIBRARIES} rct::rct_optimizations rct::rct_image_tools)

###############################
## Offline Calibration Tools ##
Expand All @@ -51,7 +56,7 @@ set_target_properties(${PROJECT_NAME}_moving_camera PROPERTIES OUTPUT_NAME movin

add_dependencies(${PROJECT_NAME}_moving_camera ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}_moving_camera ${catkin_LIBRARIES} rct::rct_optimizations)
target_link_libraries(${PROJECT_NAME}_moving_camera ${catkin_LIBRARIES} rct::rct_optimizations rct::rct_image_tools)

# Executable for demonstrating extrinsic cal of static camera, moving target functionality
add_executable(${PROJECT_NAME}_static_camera src/tools/static_camera_extrinsic.cpp)
Expand All @@ -60,7 +65,7 @@ set_target_properties(${PROJECT_NAME}_static_camera PROPERTIES OUTPUT_NAME stati

add_dependencies(${PROJECT_NAME}_static_camera ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}_static_camera ${catkin_LIBRARIES} rct::rct_optimizations)
target_link_libraries(${PROJECT_NAME}_static_camera ${catkin_LIBRARIES} rct::rct_optimizations rct::rct_image_tools)

# Executable for demonstrating extrinsic cal of multiple static camera, moving target functionality
add_executable(${PROJECT_NAME}_multi_static_camera src/tools/multi_static_camera_extrinsic.cpp)
Expand All @@ -69,7 +74,7 @@ set_target_properties(${PROJECT_NAME}_multi_static_camera PROPERTIES OUTPUT_NAME

add_dependencies(${PROJECT_NAME}_multi_static_camera ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}_multi_static_camera ${catkin_LIBRARIES} rct::rct_optimizations)
target_link_libraries(${PROJECT_NAME}_multi_static_camera ${catkin_LIBRARIES} rct::rct_optimizations rct::rct_image_tools)

# Executable for demonstrating extrinsic cal of multiple static camera multi step, moving target functionality
# First it calibrates the cameras to each other then it calibrates the set of camera where there relationship
Expand All @@ -80,7 +85,7 @@ set_target_properties(${PROJECT_NAME}_multi_static_camera_multi_step PROPERTIES

add_dependencies(${PROJECT_NAME}_multi_static_camera_multi_step ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}_multi_static_camera_multi_step ${catkin_LIBRARIES} rct::rct_optimizations)
target_link_libraries(${PROJECT_NAME}_multi_static_camera_multi_step ${catkin_LIBRARIES} rct::rct_optimizations rct::rct_image_tools)

#Executable for demonstrating intrinsic calibration of a camera
add_executable(${PROJECT_NAME}_intr src/tools/intrinsic_calibration.cpp)
Expand All @@ -89,7 +94,7 @@ set_target_properties(${PROJECT_NAME}_intr PROPERTIES OUTPUT_NAME intr_camera_ca

add_dependencies(${PROJECT_NAME}_intr ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}_intr ${catkin_LIBRARIES} rct::rct_optimizations)
target_link_libraries(${PROJECT_NAME}_intr ${catkin_LIBRARIES} rct::rct_optimizations rct::rct_image_tools)

# Executable demonstrating solving for the pose of a target given camera properties
add_executable(${PROJECT_NAME}_pnp src/tools/solve_pnp.cpp)
Expand All @@ -98,7 +103,7 @@ set_target_properties(${PROJECT_NAME}_pnp PROPERTIES OUTPUT_NAME solve_pnp_ex PR

add_dependencies(${PROJECT_NAME}_pnp ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}_pnp ${catkin_LIBRARIES} rct::rct_optimizations)
target_link_libraries(${PROJECT_NAME}_pnp ${catkin_LIBRARIES} rct::rct_optimizations rct::rct_image_tools)

# Executable demonstrating solving for the pose of a target given multiple camera properties
add_executable(${PROJECT_NAME}_multi_camera_pnp src/tools/solve_multi_camera_pnp.cpp)
Expand All @@ -107,17 +112,17 @@ set_target_properties(${PROJECT_NAME}_multi_camera_pnp PROPERTIES OUTPUT_NAME so

add_dependencies(${PROJECT_NAME}_multi_camera_pnp ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}_multi_camera_pnp ${catkin_LIBRARIES} rct::rct_optimizations)
target_link_libraries(${PROJECT_NAME}_multi_camera_pnp ${catkin_LIBRARIES} rct::rct_optimizations rct::rct_image_tools)

#############
## Testing ##
#############
if(CATKIN_ENABLE_TESTING)
if(CATKIN_ENABLE_TESTING AND RCT_BUILD_TESTS)
find_package(GTest REQUIRED)
# Tests extrinsic wrist calibration example
catkin_add_gtest(${PROJECT_NAME}_wrist_test src/examples/camera_on_wrist.cpp)
target_compile_definitions(${PROJECT_NAME}_wrist_test PRIVATE -DRCT_ENABLE_TESTING)
target_link_libraries(${PROJECT_NAME}_wrist_test ${catkin_LIBRARIES} rct::rct_optimizations GTest::GTest GTest::Main)
target_link_libraries(${PROJECT_NAME}_wrist_test ${catkin_LIBRARIES} rct::rct_optimizations rct::rct_image_tools GTest::GTest GTest::Main)
endif()

#############
Expand Down
96 changes: 39 additions & 57 deletions rct_image_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,80 +1,62 @@
cmake_minimum_required(VERSION 3.5.0)
project(rct_image_tools)

add_compile_options(-std=c++11 -Wall -Wextra)
project(rct_image_tools VERSION 0.1.0 LANGUAGES CXX)

find_package(OpenCV REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(rct_common REQUIRED)
find_package(rct_optimizations REQUIRED)

find_package(catkin REQUIRED)

find_package(Eigen3 REQUIRED)
# Eigen 3.2 (Wily) only provides EIGEN3_INCLUDE_DIR, not EIGEN3_INCLUDE_DIRS
if(NOT EIGEN3_INCLUDE_DIRS)
set(EIGEN3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR})
endif()
if(NOT TARGET Eigen3::Eigen)
find_package(Threads REQUIRED)
add_library(Eigen3::Eigen IMPORTED INTERFACE)
set_property(TARGET Eigen3::Eigen PROPERTY INTERFACE_COMPILE_DEFINITIONS ${EIGEN3_DEFINITIONS})
set_property(TARGET Eigen3::Eigen PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${EIGEN3_INCLUDE_DIRS})
endif()

catkin_package(
INCLUDE_DIRS
include
LIBRARIES
${PROJECT_NAME}
yaml-cpp
DEPENDS
OpenCV
Eigen3
)

###########
## Build ##
###########

include_directories(
include
${catkin_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
)

# Declare a C++ library
add_library(${PROJECT_NAME}
add_library(${PROJECT_NAME} SHARED
src/${PROJECT_NAME}/image_observation_finder.cpp
src/${PROJECT_NAME}/aruco_finder.cpp
src/${PROJECT_NAME}/circle_detector.cpp
src/${PROJECT_NAME}/modified_circle_grid_target.cpp
)

add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
${OpenCV_LIBRARIES}
target_compile_options(${PROJECT_NAME} PUBLIC -std=c++11)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra)
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
target_link_libraries(${PROJECT_NAME} PUBLIC
opencv_core
opencv_aruco
opencv_features2d
opencv_imgproc
opencv_highgui
yaml-cpp
Eigen3::Eigen
rct::rct_optimizations
)

add_executable(${PROJECT_NAME}_test
src/observation_finder_tests.cpp
)

add_dependencies(${PROJECT_NAME}_test ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
if(RCT_BUILD_TESTS)
add_executable(${PROJECT_NAME}_test
src/observation_finder_tests.cpp
)

target_link_libraries(${PROJECT_NAME}_test
${catkin_LIBRARIES}
${PROJECT_NAME}
rct::rct_optimizations
)

#############
## Install ##
#############
target_compile_options(${PROJECT_NAME}_test PUBLIC -std=c++11)
target_compile_options(${PROJECT_NAME}_test PRIVATE -Wall -Wextra)
target_include_directories(${PROJECT_NAME}_test PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")
target_link_libraries(${PROJECT_NAME}_test
${PROJECT_NAME}
rct::rct_optimizations
)
endif()

install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
rct_configure_package(${PROJECT_NAME})

install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
install(DIRECTORY include/${PROJECT_NAME}
DESTINATION include
)
12 changes: 12 additions & 0 deletions rct_image_tools/cmake/rct_image_tools-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@PACKAGE_INIT@

set(@PROJECT_NAME@_FOUND ON)
set_and_check(@PROJECT_NAME@_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include")
set_and_check(@PROJECT_NAME@_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/lib")

include(CMakeFindDependencyMacro)
find_dependency(Eigen3)
find_dependency(OpenCV)
find_dependency(yaml-cpp)

include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake")
9 changes: 8 additions & 1 deletion rct_image_tools/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

<license>Apache 2.0</license>

<buildtool_depend>catkin</buildtool_depend>
<depend>rct_common</depend>
<depend>rct_optimizations</depend>
<depend>yaml-cpp</depend>
<depend>libopencv-dev</depend>
<depend>eigen</depend>

<export>
<build_type>cmake</build_type>
</export>

</package>
20 changes: 16 additions & 4 deletions rct_ros_tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@ project(rct_ros_tools)
add_compile_options(-std=c++11 -Wall -Wextra)

find_package(rct_optimizations REQUIRED)
find_package(rct_image_tools REQUIRED)

find_package(OpenCV REQUIRED)

find_package(Eigen3 REQUIRED)
if(NOT EIGEN3_INCLUDE_DIRS)
set(EIGEN3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR})
endif()
if(NOT TARGET Eigen3::Eigen)
find_package(Threads REQUIRED)
add_library(Eigen3::Eigen IMPORTED INTERFACE)
set_property(TARGET Eigen3::Eigen PROPERTY INTERFACE_COMPILE_DEFINITIONS ${EIGEN3_DEFINITIONS})
set_property(TARGET Eigen3::Eigen PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${EIGEN3_INCLUDE_DIRS})
endif()

find_package(catkin REQUIRED COMPONENTS
rct_image_tools
roscpp

# TODO: Export these to a different package dedicated to 'ros tools'
Expand All @@ -16,8 +29,6 @@ find_package(catkin REQUIRED COMPONENTS
eigen_conversions
)

find_package(OpenCV REQUIRED)

# This package only provides examples. It does not export any tools.
catkin_package(
INCLUDE_DIRS
Expand All @@ -27,7 +38,6 @@ catkin_package(
yaml-cpp
CATKIN_DEPENDS
roscpp
rct_image_tools
)

###########
Expand All @@ -51,6 +61,7 @@ target_link_libraries(${PROJECT_NAME}_data_loader
yaml-cpp
${OpenCV_LIBRARIES}
rct::rct_optimizations
rct::rct_image_tools
)

# Executable for collecting data sets via subscribers and triggered with services
Expand All @@ -64,6 +75,7 @@ add_dependencies(${PROJECT_NAME}_cmd ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catki
target_link_libraries(${PROJECT_NAME}_cmd
${catkin_LIBRARIES}
${PROJECT_NAME}_data_loader
rct::rct_image_tools
)

#############
Expand Down

0 comments on commit 29d66b3

Please sign in to comment.