Skip to content

Commit b90c921

Browse files
committed
Fix CMakeLists.txt and the format of one cpp file to make all tests pass.
1 parent f3d43ea commit b90c921

File tree

7 files changed

+76
-40
lines changed

7 files changed

+76
-40
lines changed

ethercat_generic_plugins/ethercat_generic_cia402_drive/CMakeLists.txt

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
cmake_minimum_required(VERSION 3.8)
22
project(ethercat_generic_cia402_drive)
33

4+
# Default to C++17
5+
if(NOT CMAKE_CXX_STANDARD)
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8+
endif()
9+
410
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
511
add_compile_options(-Wall -Wextra -Wpedantic)
612
endif()
@@ -12,19 +18,24 @@ find_package(ethercat_interface REQUIRED)
1218
find_package(ethercat_generic_slave REQUIRED)
1319
find_package(pluginlib REQUIRED)
1420
find_package(yaml_cpp_vendor REQUIRED)
21+
find_package(yaml-cpp REQUIRED)
1522

1623
file(GLOB_RECURSE PLUGINS_SRC src/*.cpp)
17-
add_library(ethercat_generic_cia402_drive ${PLUGINS_SRC})
18-
target_compile_features(ethercat_generic_cia402_drive PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
19-
target_include_directories(ethercat_generic_cia402_drive PUBLIC
24+
add_library(${PROJECT_NAME} ${PLUGINS_SRC})
25+
target_compile_features(${PROJECT_NAME} PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
26+
target_include_directories(${PROJECT_NAME} PUBLIC
2027
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
2128
$<INSTALL_INTERFACE:include>)
29+
target_link_libraries(${PROJECT_NAME} yaml-cpp)
30+
31+
2232
ament_target_dependencies(
23-
ethercat_generic_cia402_drive
33+
${PROJECT_NAME}
2434
ethercat_interface
2535
ethercat_generic_slave
2636
pluginlib
2737
yaml_cpp_vendor
38+
yaml-cpp
2839
)
2940

3041
pluginlib_export_plugin_description_file(ethercat_interface ethercat_plugins.xml)
@@ -35,7 +46,7 @@ install(
3546
)
3647

3748
install(
38-
TARGETS ethercat_generic_cia402_drive
49+
TARGETS ${PROJECT_NAME}
3950
EXPORT export_${PROJECT_NAME}
4051
ARCHIVE DESTINATION lib
4152
LIBRARY DESTINATION lib
@@ -55,9 +66,8 @@ if(BUILD_TESTING)
5566
test/test_load_ec_modules.cpp
5667
)
5768
target_include_directories(test_load_generic_plugins PRIVATE include)
58-
ament_target_dependencies(test_load_generic_plugins
59-
pluginlib
60-
ethercat_interface
69+
target_link_libraries(test_load_generic_plugins
70+
${PROJECT_NAME}
6171
)
6272

6373
# Test Generic EtherCAT CIA402 Drive Plugin
@@ -67,20 +77,15 @@ if(BUILD_TESTING)
6777
)
6878
target_include_directories(test_generic_ec_cia402_drive PRIVATE include)
6979
target_link_libraries(test_generic_ec_cia402_drive
70-
ethercat_generic_cia402_drive
71-
)
72-
ament_target_dependencies(test_generic_ec_cia402_drive
73-
pluginlib
74-
ethercat_interface
75-
ethercat_generic_slave
80+
${PROJECT_NAME}
7681
)
7782
endif()
7883

7984
ament_export_include_directories(
8085
include
8186
)
8287
ament_export_libraries(
83-
ethercat_generic_cia402_drive
88+
${PROJECT_NAME}
8489
)
8590
ament_export_targets(
8691
export_${PROJECT_NAME}

ethercat_generic_plugins/ethercat_generic_slave/CMakeLists.txt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
cmake_minimum_required(VERSION 3.8)
22
project(ethercat_generic_slave)
33

4+
# Default to C++17
5+
if(NOT CMAKE_CXX_STANDARD)
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8+
endif()
9+
410
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
511
add_compile_options(-Wall -Wextra -Wpedantic)
612
endif()
@@ -11,18 +17,23 @@ find_package(ament_cmake_ros REQUIRED)
1117
find_package(ethercat_interface REQUIRED)
1218
find_package(pluginlib REQUIRED)
1319
find_package(yaml_cpp_vendor REQUIRED)
20+
find_package(yaml-cpp REQUIRED)
1421

1522
file(GLOB_RECURSE PLUGINS_SRC src/*.cpp)
16-
add_library(ethercat_generic_slave ${PLUGINS_SRC})
17-
target_compile_features(ethercat_generic_slave PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
18-
target_include_directories(ethercat_generic_slave PUBLIC
23+
add_library(${PROJECT_NAME} ${PLUGINS_SRC})
24+
target_compile_features(${PROJECT_NAME} PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
25+
target_include_directories(${PROJECT_NAME} PUBLIC
1926
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
2027
$<INSTALL_INTERFACE:include>)
2128
ament_target_dependencies(
22-
ethercat_generic_slave
29+
${PROJECT_NAME}
2330
ethercat_interface
2431
pluginlib
2532
yaml_cpp_vendor
33+
yaml-cpp
34+
)
35+
target_link_libraries(${PROJECT_NAME}
36+
yaml-cpp
2637
)
2738

2839
pluginlib_export_plugin_description_file(ethercat_interface ethercat_plugins.xml)
@@ -33,7 +44,7 @@ install(
3344
)
3445

3546
install(
36-
TARGETS ethercat_generic_slave
47+
TARGETS ${PROJECT_NAME}
3748
EXPORT export_${PROJECT_NAME}
3849
ARCHIVE DESTINATION lib
3950
LIBRARY DESTINATION lib
@@ -42,8 +53,6 @@ install(
4253

4354
if(BUILD_TESTING)
4455
find_package(ament_lint_auto REQUIRED)
45-
find_package(pluginlib REQUIRED)
46-
find_package(ethercat_interface REQUIRED)
4756
ament_lint_auto_find_test_dependencies()
4857

4958
# Test Load EtherCAT modules
@@ -52,9 +61,8 @@ if(BUILD_TESTING)
5261
test/test_load_ec_modules.cpp
5362
)
5463
target_include_directories(test_load_generic_plugins PRIVATE include)
55-
ament_target_dependencies(test_load_generic_plugins
56-
pluginlib
57-
ethercat_interface
64+
target_link_libraries(test_load_generic_plugins
65+
${PROJECT_NAME}
5866
)
5967

6068
# Test Generic EtherCAT Slave Plugin
@@ -64,19 +72,15 @@ if(BUILD_TESTING)
6472
)
6573
target_include_directories(test_generic_ec_slave PRIVATE include)
6674
target_link_libraries(test_generic_ec_slave
67-
ethercat_generic_slave
68-
)
69-
ament_target_dependencies(test_generic_ec_slave
70-
pluginlib
71-
ethercat_interface
75+
${PROJECT_NAME}
7276
)
7377
endif()
7478

7579
ament_export_include_directories(
7680
include
7781
)
7882
ament_export_libraries(
79-
ethercat_generic_slave
83+
${PROJECT_NAME}
8084
)
8185
ament_export_targets(
8286
export_${PROJECT_NAME}

ethercat_generic_plugins/ethercat_generic_slave/src/generic_ec_slave.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,20 @@ void GenericEcSlave::setup_syncs()
6868
if (sm_configs_.size() == 0) {
6969
syncs_.push_back({0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE});
7070
syncs_.push_back({1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE});
71-
syncs_.push_back({2, EC_DIR_OUTPUT, (unsigned int)(rpdos_.size()), rpdos_.data(), EC_WD_ENABLE});
72-
syncs_.push_back({3, EC_DIR_INPUT, (unsigned int)(tpdos_.size()), tpdos_.data(), EC_WD_DISABLE});
71+
syncs_.push_back({2, EC_DIR_OUTPUT, (unsigned int)(rpdos_.size()), rpdos_.data(),
72+
EC_WD_ENABLE});
73+
syncs_.push_back({3, EC_DIR_INPUT, (unsigned int)(tpdos_.size()), tpdos_.data(),
74+
EC_WD_DISABLE});
7375
} else {
7476
for (auto & sm : sm_configs_) {
7577
if (sm.pdo_name == "null") {
7678
syncs_.push_back({sm.index, sm.type, 0, NULL, sm.watchdog});
7779
} else if (sm.pdo_name == "rpdo") {
78-
syncs_.push_back({sm.index, sm.type, (unsigned int)(rpdos_.size()), rpdos_.data(), sm.watchdog});
80+
syncs_.push_back({sm.index, sm.type, (unsigned int)(rpdos_.size()), rpdos_.data(),
81+
sm.watchdog});
7982
} else if (sm.pdo_name == "tpdo") {
80-
syncs_.push_back({sm.index, sm.type, (unsigned int)(tpdos_.size()), tpdos_.data(), sm.watchdog});
83+
syncs_.push_back({sm.index, sm.type, (unsigned int)(tpdos_.size()), tpdos_.data(),
84+
sm.watchdog});
8185
}
8286
}
8387
}

ethercat_generic_plugins/ethercat_generic_slave/test/test_load_ec_modules.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
TEST(TestLoadGenericEcSlave, load_ec_module)
2222
{
23-
pluginlib::ClassLoader<ethercat_interface::EcSlave> ec_loader_{
24-
"ethercat_interface", "ethercat_interface::EcSlave"};
23+
pluginlib::ClassLoader<ethercat_interface::EcSlave> ec_loader_(
24+
"ethercat_interface", "ethercat_interface::EcSlave");
2525
ASSERT_NO_THROW(ec_loader_.createSharedInstance("ethercat_generic_plugins/GenericEcSlave"));
2626
}

ethercat_interface/CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
cmake_minimum_required(VERSION 3.8)
22
project(ethercat_interface)
33

4+
5+
# Default to C++17
6+
if(NOT CMAKE_CXX_STANDARD)
7+
set(CMAKE_CXX_STANDARD 17)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
endif()
10+
411
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
512
add_compile_options(-Wall -Wextra -Wpedantic)
613
endif()
@@ -53,7 +60,10 @@ install(
5360
if(BUILD_TESTING)
5461
# find_package(ament_cmake_gtest REQUIRED)
5562
find_package(ament_lint_auto REQUIRED)
63+
5664
find_package(yaml_cpp_vendor REQUIRED)
65+
find_package(yaml-cpp REQUIRED)
66+
5767
ament_lint_auto_find_test_dependencies()
5868

5969
# Test PdoChannelManager
@@ -62,9 +72,10 @@ if(BUILD_TESTING)
6272
test/test_ec_pdo_channel_manager.cpp
6373
)
6474
target_include_directories(test_ec_pdo_channel_manager PRIVATE include ${ETHERLAB_DIR}/include)
65-
ament_target_dependencies(test_ec_pdo_channel_manager
66-
yaml_cpp_vendor
67-
)
75+
76+
target_link_libraries(test_ec_pdo_channel_manager
77+
${PROJECT_NAME}
78+
yaml-cpp)
6879
endif()
6980

7081
## EXPORTS

ethercat_manager/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
cmake_minimum_required(VERSION 3.5)
22
project(ethercat_manager)
33

4+
# Default to C++17
5+
if(NOT CMAKE_CXX_STANDARD)
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8+
endif()
9+
410
find_package(ament_cmake REQUIRED)
511
find_package(rclcpp REQUIRED)
612
find_package(ethercat_msgs REQUIRED)

ethercat_msgs/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
cmake_minimum_required(VERSION 3.8)
22
project(ethercat_msgs)
33

4+
# Default to C++17
5+
if(NOT CMAKE_CXX_STANDARD)
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8+
endif()
9+
410
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
511
add_compile_options(-Wall -Wextra -Wpedantic)
612
endif()

0 commit comments

Comments
 (0)