Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 92 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
cmake_minimum_required(VERSION 2.8.3)
project(odva_ethernetip)

find_package(catkin REQUIRED)
cmake_minimum_required(VERSION 3.5.0)
project(odva_ethernetip VERSION 0.1.0 LANGUAGES CXX)

find_package(console_bridge REQUIRED)
find_package(Boost 1.47 REQUIRED COMPONENTS system)

catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
DEPENDS Boost console_bridge
)

include_directories(
include
${Boost_INCLUDE_DIRS}
${console_bridge_INCLUDE_DIRS}
)

## Declare a cpp library for just Ethernet/IP generic stuff
add_library(${PROJECT_NAME}
add_library(${PROJECT_NAME} SHARED
src/connection.cpp
src/copy_serializable.cpp
src/cpf_item.cpp
Expand All @@ -33,49 +19,100 @@ add_library(${PROJECT_NAME}
src/rr_data.cpp
src/session.cpp
)
target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME} PUBLIC
${Boost_LIBRARIES}
${console_bridge_LIBRARIES}
)

## Mark executables and libraries for installation
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
if(CXX_FEATURE_FOUND EQUAL "-1")
target_compile_options(${PROJECT_NAME} PUBLIC -std=c++11)
else()
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
endif()

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

install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC
${Boost_INCLUDE_DIRS}
${console_bridge_INCLUDE_DIRS})


list (APPEND PACKAGE_LIBRARIES ${PROJECT_NAME})

# Mark executables and/or libraries for installation
install(TARGETS ${PACKAGE_LIBRARIES}
EXPORT ${PROJECT_NAME}-targets DESTINATION lib)
install(EXPORT ${PROJECT_NAME}-targets
NAMESPACE odva_ethernetip:: DESTINATION lib/cmake/${PROJECT_NAME})

# Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}
DESTINATION include
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp"
PATTERN ".svn" EXCLUDE
)

install(FILES package.xml DESTINATION share/${PROJECT_NAME})

# Create cmake config files
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
VERSION ${PROJECT_VERSION} COMPATIBILITY ExactVersion)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
DESTINATION lib/cmake/${PROJECT_NAME})

export(EXPORT ${PROJECT_NAME}-targets FILE
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-targets.cmake)

if (ENABLE_TESTS)
enable_testing()
add_custom_target(run_tests ALL
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> -V)

if (CATKIN_ENABLE_TESTING)
catkin_add_gtest(${PROJECT_NAME}-test
test/serialization/buffer_writer_test.cpp
test/serialization/buffer_reader_test.cpp
test/serialization/stream_writer_test.cpp
test/serialization/stream_reader_test.cpp
test/serialization/serializable_buffer_test.cpp
test/serialization/serializable_primitive_test.cpp
test/test_socket_test.cpp
test/encap_header_test.cpp
test/encap_packet_test.cpp
test/cpf_item_test.cpp
test/cpf_packet_test.cpp
test/sequenced_address_item_test.cpp
test/identity_item_data_test.cpp
test/path_test.cpp
test/rr_data_test.cpp
test/message_router_request_test.cpp
test/message_router_response_test.cpp
test/rr_data_request_test.cpp
test/rr_data_response_test.cpp
test/forward_open_request_test.cpp
test/forward_open_success_test.cpp
test/forward_close_request_test.cpp
test/forward_close_success_test.cpp
test/session_test.cpp
test/test_main.cpp
)
target_link_libraries(${PROJECT_NAME}-test ${Boost_LIBRARIES} ${PROJECT_NAME})
add_subdirectory(test)
endif()

#if (CATKIN_ENABLE_TESTING)
# catkin_add_gtest(${PROJECT_NAME}-test
# test/serialization/buffer_writer_test.cpp
# test/serialization/buffer_reader_test.cpp
# test/serialization/stream_writer_test.cpp
# test/serialization/stream_reader_test.cpp
# test/serialization/serializable_buffer_test.cpp
# test/serialization/serializable_primitive_test.cpp
# test/test_socket_test.cpp
# test/encap_header_test.cpp
# test/encap_packet_test.cpp
# test/cpf_item_test.cpp
# test/cpf_packet_test.cpp
# test/sequenced_address_item_test.cpp
# test/identity_item_data_test.cpp
# test/path_test.cpp
# test/rr_data_test.cpp
# test/message_router_request_test.cpp
# test/message_router_response_test.cpp
# test/rr_data_request_test.cpp
# test/rr_data_response_test.cpp
# test/forward_open_request_test.cpp
# test/forward_open_success_test.cpp
# test/forward_close_request_test.cpp
# test/forward_close_success_test.cpp
# test/session_test.cpp
# test/test_main.cpp
# )
# target_link_libraries(${PROJECT_NAME}-test ${Boost_LIBRARIES} ${PROJECT_NAME})
#endif()

15 changes: 15 additions & 0 deletions cmake/odva_ethernetip-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@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)
if(${CMAKE_VERSION} VERSION_LESS "3.10.0")
find_package(Boost COMPONENTS system python thread program_options)
else()
find_dependency(Boost COMPONENTS system python thread program_options)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
6 changes: 3 additions & 3 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<maintainer email="[email protected]">Mike Purvis</maintainer>
<author email="[email protected]">Kareem Shehata</author>

<buildtool_depend>catkin</buildtool_depend>

<depend>boost</depend>
<depend>libconsole-bridge-dev</depend>

<test_depend>rosunit</test_depend>
<export>
<build_type>cmake</build_type>
</export>
</package>
2 changes: 1 addition & 1 deletion src/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void Session::check_packet(EncapPacket& pkt, EIP_UINT exp_cmd)

void Session::getSingleAttributeSerializable(EIP_USINT class_id, EIP_USINT instance_id,
EIP_USINT attribute_id, Serializable& result)
{
{
shared_ptr<Serializable> no_data;
RRDataResponse resp_data = sendRRDataCommand(0x0E,
Path(class_id, instance_id, attribute_id), no_data);
Expand Down
46 changes: 46 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
find_package(GTest REQUIRED)

# odva_ethernetip Test
add_executable(${PROJECT_NAME}_odva_ethernetip_unit
serialization/buffer_writer_test.cpp)
target_link_libraries(${PROJECT_NAME}_odva_ethernetip_unit ${GTEST_BOTH_LIBRARIES} ${PROJECT_NAME})
target_compile_options(${PROJECT_NAME}_odva_ethernetip_unit PRIVATE -Wsuggest-override -Wconversion -Wsign-conversion)
if(CXX_FEATURE_FOUND EQUAL "-1")
target_compile_options(${PROJECT_NAME}_odva_ethernetip_unit PUBLIC -std=c++11)
else()
target_compile_features(${PROJECT_NAME}_odva_ethernetip_unit PRIVATE cxx_std_11)
endif()
target_include_directories(${PROJECT_NAME}_odva_ethernetip_unit PRIVATE ${GTEST_INCLUDE_DIRS})
if(${CMAKE_VERSION} VERSION_LESS "3.10.0")
gtest_add_tests(${PROJECT_NAME}_odva_ethernetip_unit "" AUTO)
else()
gtest_discover_tests(${PROJECT_NAME}_odva_ethernetip_unit)
endif()

add_dependencies(run_tests ${PROJECT_NAME}_odva_ethernetip_unit)

# test/
# test/serialization/buffer_reader_test.cpp
# test/serialization/stream_writer_test.cpp
# test/serialization/stream_reader_test.cpp
# test/serialization/serializable_buffer_test.cpp
# test/serialization/serializable_primitive_test.cpp
# test/test_socket_test.cpp
# test/encap_header_test.cpp
# test/encap_packet_test.cpp
# test/cpf_item_test.cpp
# test/cpf_packet_test.cpp
# test/sequenced_address_item_test.cpp
# test/identity_item_data_test.cpp
# test/path_test.cpp
# test/rr_data_test.cpp
# test/message_router_request_test.cpp
# test/message_router_response_test.cpp
# test/rr_data_request_test.cpp
# test/rr_data_response_test.cpp
# test/forward_open_request_test.cpp
# test/forward_open_success_test.cpp
# test/forward_close_request_test.cpp
# test/forward_close_success_test.cpp
# test/session_test.cpp
# test/test_main.cpp