|
| 1 | +cmake_minimum_required(VERSION 3.15) |
| 2 | +project(bio_ik) |
| 3 | + |
| 4 | +set(CMAKE_BUILD_TYPE Release) |
| 5 | + |
| 6 | +find_package(ament_cmake REQUIRED) |
| 7 | +find_package(ament_cmake_ros REQUIRED) |
| 8 | + |
| 9 | +set(THIS_PACKAGE_INCLUDE_DEPENDS |
| 10 | + Eigen3 |
| 11 | + moveit_core |
| 12 | + moveit_ros_planning |
| 13 | + pluginlib |
| 14 | + rclcpp |
| 15 | + tf2_eigen |
| 16 | + tf2_ros |
| 17 | + tf2_kdl |
| 18 | + tf2_geometry_msgs |
| 19 | +) |
| 20 | + |
| 21 | +foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS}) |
| 22 | + find_package(${Dependency} REQUIRED) |
| 23 | +endforeach() |
| 24 | + |
| 25 | +find_package(OpenMP) |
| 26 | +# the specific flag is not yet present in cmake 2.8.12 |
| 27 | +if(OpenMP_CXX_FOUND OR OPENMP_FOUND) |
| 28 | + message(STATUS "OPENMP FOUND") |
| 29 | + add_compile_options(${OpenMP_CXX_FLAGS}) |
| 30 | + if(NOT OpenMP_CXX_LIBRARIES) |
| 31 | + # cmake 2.8.12 does not yet specify the library - assume we might need libgomp |
| 32 | + set(OpenMP_LIBS gomp) |
| 33 | + else() |
| 34 | + set(OpenMP_LIBS ${OpenMP_CXX_LIBRARIES}) |
| 35 | + endif() |
| 36 | +else() |
| 37 | + message(WARNING "OPENMP NOT FOUND. You will suffer performance loss.") |
| 38 | + set(OpenMP_LIBS) |
| 39 | +endif() |
| 40 | + |
| 41 | +option(USE_FANN "build the neural-network-based IK solver (experimental)" OFF) |
| 42 | +if(USE_FANN) |
| 43 | + find_library(FANN_LIBRARIES NAMES fann) |
| 44 | + find_path(FANN_INCLUDE_DIRS NAMES fann.h) |
| 45 | + if(NOT FANN_INCLUDE_DIRS OR NOT FANN_LIBRARIES) |
| 46 | + message(FATAL_ERROR "Neural network solver requested, but libfann was not found.") |
| 47 | + else() |
| 48 | + message("Found libfann: ${FANN_LIBRARIES} / ${FANN_INCLUDE_DIRS}") |
| 49 | + endif() |
| 50 | +else() |
| 51 | + set(FANN_LIBRARIES) |
| 52 | + set(FANN_INCLUDE_DIRS) |
| 53 | +endif() |
| 54 | + |
| 55 | +option(USE_CPPOPTLIB "Include gradient-based solvers from CppNumericalSolvers (bio_ik also provides its own solver)" OFF) |
| 56 | +if(USE_CPPOPTLIB) |
| 57 | + find_path(CPPOPTLIB_INCLUDE_DIRS |
| 58 | + NAMES cppoptlib/solver/bfgssolver.h |
| 59 | + HINTS ../../CppNumericalSolvers/include) |
| 60 | + if(NOT CPPOPTLIB_INCLUDE_DIRS) |
| 61 | + message(FATAL_ERROR "cppoptlib support requested, but the headers could not be found.") |
| 62 | + else() |
| 63 | + message("Found cppoptlib: ${CPPOPTLIB_INCLUDE_DIRS}") |
| 64 | + endif() |
| 65 | + add_definitions(-DENABLE_CPP_OPTLIB) |
| 66 | +else() |
| 67 | + set(CPPOPTLIB_INCLUDE_DIRS) |
| 68 | +endif() |
| 69 | + |
| 70 | +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 71 | + add_compile_options(-frecord-gcc-switches) |
| 72 | +endif() |
| 73 | + |
| 74 | +add_compile_options($<$<CONFIG:Release>:-O3>) |
| 75 | +add_compile_options($<$<CONFIG:Release>:-ftree-vectorize>) |
| 76 | +add_compile_options($<$<CONFIG:Release>:-ffast-math>) |
| 77 | + |
| 78 | +include_directories( |
| 79 | + include |
| 80 | + ${FANN_INCLUDE_DIRS} |
| 81 | + ${CPPOPTLIB_INCLUDE_DIRS} |
| 82 | +) |
| 83 | + |
| 84 | +set(SOURCES |
| 85 | + src/goal_types.cpp |
| 86 | + src/problem.cpp |
| 87 | + src/ik_test.cpp |
| 88 | + src/ik_gradient.cpp |
| 89 | + src/ik_evolution_1.cpp |
| 90 | + src/ik_evolution_2.cpp |
| 91 | +) |
| 92 | + |
| 93 | +if(USE_FANN) |
| 94 | + list(APPEND SOURCES src/ik_neural.cpp) |
| 95 | +endif() |
| 96 | + |
| 97 | +if(USE_CPPOPTLIB) |
| 98 | + list(APPEND SOURCES src/ik_cppoptlib.cpp) |
| 99 | +endif() |
| 100 | + |
| 101 | +add_library(${PROJECT_NAME} ${SOURCES}) |
| 102 | + |
| 103 | +target_include_directories(${PROJECT_NAME} PUBLIC |
| 104 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 105 | + $<INSTALL_INTERFACE:include> |
| 106 | +) |
| 107 | + |
| 108 | +ament_target_dependencies( |
| 109 | + ${PROJECT_NAME} |
| 110 | + PUBLIC |
| 111 | + ${THIS_PACKAGE_INCLUDE_DEPENDS} |
| 112 | +) |
| 113 | + |
| 114 | +target_link_libraries( |
| 115 | + ${PROJECT_NAME} |
| 116 | + PUBLIC |
| 117 | + ${FANN_LIBRARIES} |
| 118 | + ${OpenMP_LIBS} |
| 119 | +) |
| 120 | + |
| 121 | +add_library(${PROJECT_NAME}_plugin SHARED |
| 122 | + ${SOURCES} |
| 123 | + src/kinematics_plugin.cpp |
| 124 | +) |
| 125 | + |
| 126 | +target_include_directories(${PROJECT_NAME}_plugin PUBLIC |
| 127 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 128 | + $<INSTALL_INTERFACE:include> |
| 129 | +) |
| 130 | + |
| 131 | +target_link_libraries( |
| 132 | + ${PROJECT_NAME}_plugin |
| 133 | + PRIVATE |
| 134 | + ${PROJECT_NAME} |
| 135 | +) |
| 136 | + |
| 137 | + |
| 138 | +install( |
| 139 | + DIRECTORY include/ |
| 140 | + DESTINATION include |
| 141 | +) |
| 142 | +install( |
| 143 | + TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_plugin |
| 144 | + EXPORT export_${PROJECT_NAME} |
| 145 | + LIBRARY DESTINATION lib |
| 146 | + ARCHIVE DESTINATION lib |
| 147 | + RUNTIME DESTINATION bin |
| 148 | + INCLUDES DESTINATION include |
| 149 | +) |
| 150 | + |
| 151 | + |
| 152 | +pluginlib_export_plugin_description_file( |
| 153 | + moveit_core |
| 154 | + bio_ik_kinematics_description.xml |
| 155 | +) |
| 156 | + |
| 157 | +ament_export_include_directories( |
| 158 | + include |
| 159 | +) |
| 160 | +ament_export_libraries( |
| 161 | + ${PROJECT_NAME}_plugin |
| 162 | +) |
| 163 | +ament_export_targets( |
| 164 | + export_${PROJECT_NAME} |
| 165 | +) |
| 166 | + |
| 167 | +ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS}) |
| 168 | + |
| 169 | +if(BUILD_TESTING) |
| 170 | + find_package(ament_cmake_gtest REQUIRED) |
| 171 | + |
| 172 | + ament_add_gtest(bio_ik_test test/utest.cpp) |
| 173 | + target_link_libraries(bio_ik_test |
| 174 | + bio_ik |
| 175 | + ) |
| 176 | + target_include_directories(bio_ik_test |
| 177 | + PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 178 | + PUBLIC $<INSTALL_INTERFACE:include>) |
| 179 | + |
| 180 | +endif() |
| 181 | + |
| 182 | +ament_package() |
0 commit comments