diff --git a/CMakeLists.txt b/CMakeLists.txt index 5652f85..c1b7b39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 + "$" + "$") -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 $ -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() + diff --git a/cmake/odva_ethernetip-config.cmake.in b/cmake/odva_ethernetip-config.cmake.in new file mode 100644 index 0000000..40b256b --- /dev/null +++ b/cmake/odva_ethernetip-config.cmake.in @@ -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}/@PROJECT_NAME@-targets.cmake") \ No newline at end of file diff --git a/package.xml b/package.xml index dc1d8ee..a747c14 100644 --- a/package.xml +++ b/package.xml @@ -8,10 +8,10 @@ Mike Purvis Kareem Shehata - catkin - boost libconsole-bridge-dev - rosunit + + cmake + diff --git a/src/session.cpp b/src/session.cpp index d1ffd30..2af8691 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -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 no_data; RRDataResponse resp_data = sendRRDataCommand(0x0E, Path(class_id, instance_id, attribute_id), no_data); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..c04311f --- /dev/null +++ b/test/CMakeLists.txt @@ -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