Skip to content

Commit

Permalink
[WIP] Enable more modern cmake usage
Browse files Browse the repository at this point in the history
* Attempt fix for ros-perception#245

Signed-off-by: Ryan Friedman <[email protected]>
  • Loading branch information
RFRIEDM-Trimble committed May 30, 2022
1 parent 54c269f commit 3d32d81
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 38 deletions.
72 changes: 48 additions & 24 deletions camera_calibration_parsers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,50 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake_ros REQUIRED)
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_auto REQUIRED)

# set(CMAKE_FIND_DEBUG_MODE TRUE)
find_package(rclcpp REQUIRED)
find_package(rcpputils REQUIRED)
# set(CMAKE_FIND_DEBUG_MODE FALSE)
find_package(sensor_msgs REQUIRED)
find_package(yaml_cpp_vendor REQUIRED)

include_directories(include)
message("TARGETS: ${yaml_cpp_vendor_TARGETS}")

# define the library
add_library(${PROJECT_NAME}
src/parse.cpp
src/parse_ini.cpp
src/parse_yml.cpp
)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_compile_definitions(${PROJECT_NAME} PRIVATE "CAMERA_CALIBRATION_PARSERS_BUILDING_DLL")

if(CMAKE_COMPILER_IS_GNUCXX)
target_link_libraries(${PROJECT_NAME} stdc++fs)
target_link_libraries(${PROJECT_NAME} PUBLIC stdc++fs)
endif()

ament_target_dependencies(
${PROJECT_NAME}
rclcpp
rcpputils
sensor_msgs
yaml_cpp_vendor
message("Include Dirs for RCLCPP: ${rclcpp_INCLUDE_DIRS}")
target_link_libraries(${PROJECT_NAME} PUBLIC
rclcpp::rclcpp # rclcpp::rclcpp generates linker errors if used
sensor_msgs::sensor_msgs_library # https://github.com/ros2/common_interfaces/pull/178
yaml-cpp # https://github.com/jbeder/yaml-cpp/pull/741
)

# ament_target_dependencies(
# ${PROJECT_NAME}
# rclcpp
# rcpputils # If uncommented, add a call to find_package and ament_export_dependencies
# sensor_msgs
# yaml_cpp_vendor
# )

# TODO: Reenable Python Wrapper with new serialization technique.
#find_package(PythonLibs REQUIRED)
#if(PYTHONLIBS_VERSION_STRING VERSION_LESS 3)
Expand All @@ -59,28 +73,38 @@ ament_target_dependencies(

# define the exe to convert
add_executable(convert src/convert.cpp)
target_link_libraries(convert ${PROJECT_NAME})
target_link_libraries(convert PRIVATE ${PROJECT_NAME}::${PROJECT_NAME})

install(
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

install(
TARGETS convert
RUNTIME DESTINATION lib/${PROJECT_NAME}
DIRECTORY include/
DESTINATION include
)

install(
DIRECTORY include/
DESTINATION include
EXPORT export_${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/
)

install(
TARGETS convert
RUNTIME DESTINATION lib/${PROJECT_NAME}
)

ament_export_include_directories(include)
# ament_export_include_directories(include)
if(NOT TARGET ${PROJECT_NAME}::${PROJECT_NAME})
message(ERROR "Unable to export not found targets")
endif()
ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(rclcpp rcpputils sensor_msgs yaml_cpp_vendor)
ament_export_dependencies(rclcpp sensor_msgs yaml_cpp_vendor)


if(BUILD_TESTING)
Expand All @@ -97,17 +121,17 @@ if(BUILD_TESTING)
ament_cpplint()
ament_lint_cmake()
ament_uncrustify()
find_package(ament_cmake_gtest)
include(GoogleTest)

ament_add_gtest(${PROJECT_NAME}-parse_ini test/test_parse_ini.cpp)
gtest_add_tests(TARGET ${PROJECT_NAME}-parse_ini SOURCES test/test_parse_ini.cpp)
if(TARGET ${PROJECT_NAME}-parse_ini)
target_link_libraries(${PROJECT_NAME}-parse_ini ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}-parse_ini PRIVATE ${PROJECT_NAME})
endif()

ament_add_gtest(${PROJECT_NAME}-parse_yml test/test_parse_yml.cpp)
gtest_add_tests(TARGET ${PROJECT_NAME}-parse_yml SOURCES test/test_parse_yml.cpp)
if(TARGET ${PROJECT_NAME}-parse_yml)
target_link_libraries(${PROJECT_NAME}-parse_yml ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}-parse_yml PRIVATE ${PROJECT_NAME})
endif()
endif()

ament_package()
ament_auto_package()
51 changes: 37 additions & 14 deletions camera_info_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,66 @@ endif()

find_package(ament_cmake_ros REQUIRED)

find_package(ament_index_cpp REQUIRED)
find_package(camera_calibration_parsers REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rcpputils REQUIRED)
find_package(camera_calibration_parsers REQUIRED)
find_package(sensor_msgs REQUIRED)

include_directories(include)

# add a library
add_library(${PROJECT_NAME} src/camera_info_manager.cpp)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_compile_definitions(${PROJECT_NAME} PRIVATE "CAMERA_INFO_MANAGER_BUILDING_DLL")

ament_target_dependencies(
target_link_libraries(
${PROJECT_NAME}
ament_index_cpp
camera_calibration_parsers
rclcpp
rcpputils
sensor_msgs
PUBLIC
rclcpp::rclcpp

# For now, use the module mode properties to link the libraries since alias targets aren't supplied
${camera_calibration_parsers_LIBRARIES}
${sensor_msgs_LIBRARIES}
)

# Because sensor_msgs doesn't yet support modern cmake, add the header include directory manually
# ament_target_dependencies could also be used
target_include_directories(${PROJECT_NAME} PUBLIC
${sensor_msgs_INCLUDE_DIRS}
${camera_calibration_parsers_INCLUDE_DIRS}
)
# ament_target_dependencies(
# ${PROJECT_NAME}
# camera_calibration_parsers
# rclcpp
# sensor_msgs
# )

install(
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)

install(
EXPORT export_${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/
)

install(
DIRECTORY include/
DESTINATION include
)

ament_export_include_directories(include)
ament_export_dependencies(ament_index_cpp camera_calibration_parsers rclcpp rcpputils sensor_msgs)
ament_export_libraries(${PROJECT_NAME})
# ament_export_include_directories(include)
# ament_export_libraries(${PROJECT_NAME})

if(BUILD_TESTING)
#TODO(mjcarroll) switch back to this once I can fix copyright check
Expand Down

0 comments on commit 3d32d81

Please sign in to comment.