From 616b1b7d9f06b80c4d297a4595fc5bf20be64ae8 Mon Sep 17 00:00:00 2001 From: alexdevteam Date: Fri, 21 Jun 2024 14:06:50 +0200 Subject: [PATCH] Fix build on Windows/MSVC --- .gitignore | 1 + CMakeLists.txt | 31 ++++++++++++++++++++++--------- include/mstsp_solver/TargetSet.h | 1 + src/MapPolygon.cpp | 7 ++++--- src/ShortestPathCalculator.cpp | 2 +- src/algorithms.cpp | 2 +- src/main.cpp | 6 +++--- 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 95bd13f..a7ced60 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea +.vscode cmake-build-* build **path_*.csv diff --git a/CMakeLists.txt b/CMakeLists.txt index 01b1da6..3d43f19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,20 +5,33 @@ project(coverage_mission_planner) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -if(MSVC) - add_compile_options(/W4 /WX) -else() - add_compile_options(-Wall -Wextra -pedantic -Werror) -endif() - if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() add_executable(${PROJECT_NAME} src/main.cpp src/MapPolygon.cpp include/MapPolygon.hpp src/utils.cpp src/algorithms.cpp src/EnergyCalculator.cpp src/ShortestPathCalculator.cpp include/ShortestPathCalculator.hpp include/custom_types.hpp include/mstsp_solver/Target.h src/mstsp_solver/TargetSet.cpp include/mstsp_solver/TargetSet.h include/mstsp_solver/SolverConfig.h src/mstsp_solver/MstspSolver.cpp include/mstsp_solver/MstspSolver.h include/mstsp_solver/Insertion.h include/SimpleLogger.h include/LoggerRos.h) -find_package(yaml-cpp) +if(MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX /D_USE_MATH_DEFINES) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic -Werror) +endif() + +include(FetchContent) + +FetchContent_Declare( + yaml-cpp + GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git + GIT_TAG 0.8.0 +) +FetchContent_GetProperties(yaml-cpp) + +if(NOT yaml-cpp_POPULATED) + message(STATUS "Fetching yaml-cpp...") + FetchContent_Populate(yaml-cpp) + add_subdirectory(${yaml-cpp_SOURCE_DIR} ${yaml-cpp_BINARY_DIR}) +endif() -target_include_directories(${PROJECT_NAME} PUBLIC include ${YAML_CPP_INCLUDE_DIRS}) -target_link_libraries(${PROJECT_NAME} ${YAML_CPP_LIBRARIES}) +target_link_libraries(${PROJECT_NAME} PRIVATE yaml-cpp::yaml-cpp) +target_include_directories(${PROJECT_NAME} PRIVATE include) \ No newline at end of file diff --git a/include/mstsp_solver/TargetSet.h b/include/mstsp_solver/TargetSet.h index bc47e33..7fc0109 100644 --- a/include/mstsp_solver/TargetSet.h +++ b/include/mstsp_solver/TargetSet.h @@ -9,6 +9,7 @@ #include #include "Target.h" #include +#include #include "MapPolygon.hpp" #include "EnergyCalculator.h" diff --git a/src/MapPolygon.cpp b/src/MapPolygon.cpp index ec18867..a9f5830 100644 --- a/src/MapPolygon.cpp +++ b/src/MapPolygon.cpp @@ -5,6 +5,7 @@ #include #include #include "algorithms.hpp" +#include // TODO: make most of methods external functions (maybe, working on not MapPolygons but just on vector> // TODO: make use of some external polygons library like @@ -242,7 +243,7 @@ std::vector MapPolygon::split_into_pieces(double max_piece_area) { try { - int res_polygons = std::ceil(area() / max_piece_area); + auto res_polygons = static_cast(std::ceil(area() / max_piece_area)); double split_piece_area = area() / res_polygons; auto cur_polygon = *this; std::vector res; @@ -269,7 +270,7 @@ std::vector MapPolygon::split_into_pieces(double max_piece_area) { } res.push_back(cur_polygon); return res; - } catch (std::runtime_error &e) { + } catch (std::runtime_error &) { // m_logger->log_err("[PathGenerator]: ERROR while dividing polygon: " + std::string(e.what())); } return {}; @@ -328,7 +329,7 @@ namespace { } double l = 0, r = largest_area; auto current_num_of_pols = sub_polygons.size(); - while (r - l > 1 and current_num_of_pols != n) { + while (r - l > 1 && current_num_of_pols != n) { double m = (r + l) / 2; size_t number_of_decomposed = 0; for (auto &pol: sub_polygons) { diff --git a/src/ShortestPathCalculator.cpp b/src/ShortestPathCalculator.cpp index 199eb54..99f9d8e 100644 --- a/src/ShortestPathCalculator.cpp +++ b/src/ShortestPathCalculator.cpp @@ -89,7 +89,7 @@ ShortestPathCalculator::ShortestPathCalculator(const MapPolygon &polygon) { // And 2-d matrix for the Floyd-Warshall algorithm m_next_vertex_in_path = std::vector>(m_polygon_points.size()); std::for_each(m_next_vertex_in_path.begin(), m_next_vertex_in_path.end(), - [&](auto &row) { row = std::vector(m_polygon_points.size(), -1); }); + [&](auto &row) { row = std::vector(m_polygon_points.size(), ~static_cast(0)); }); m_floyd_warshall_d = std::vector>(m_polygon_points.size()); std::for_each(m_floyd_warshall_d.begin(), m_floyd_warshall_d.end(), [&](auto &row) { row = std::vector(m_polygon_points.size(), HUGE_VAL); }); diff --git a/src/algorithms.cpp b/src/algorithms.cpp index 19c7e9a..d5f0d65 100644 --- a/src/algorithms.cpp +++ b/src/algorithms.cpp @@ -155,7 +155,7 @@ vpdd thin_polygon_coverage(const MapPolygon &polygon, double sweeping_step, doub vpdd sweeping(const MapPolygon &polygon, double angle, double sweeping_step, double wall_distance, bool start_up) { auto thin_sweeping = thin_polygon_coverage(polygon, sweeping_step, wall_distance); - if (not thin_sweeping.empty()) { + if (!thin_sweeping.empty()) { return thin_sweeping; } diff --git a/src/main.cpp b/src/main.cpp index 076f070..28d67b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) { }; best_solution = generate_with_constraints(algorithm_config.max_single_path_energy * 3600, algorithm_config.number_of_drones, f); - } catch (const polygon_decomposition_error &e) { + } catch (const polygon_decomposition_error &) { std::cout << "Error while decomposing the polygon" << std::endl; return -1; } catch (const std::runtime_error &e) { @@ -187,7 +187,7 @@ generate_with_constraints(double max_energy_bound, unsigned int n_uavs, F f) { return solution; } // if the energy consumption is divided well, this should be enough - unsigned int updated_n_uavs = std::ceil(solution.path_energies_sum / max_energy_bound); + auto updated_n_uavs = static_cast(std::ceil(solution.path_energies_sum / max_energy_bound)); // if the needed number of UAVs is estimated to be smaller than on previous step, make it larger if (updated_n_uavs <= current_n_uavs) { @@ -227,7 +227,7 @@ std::vector read_points_from_csv(const std::string &filename) { is.close(); // Make sure that the first point is always the same as the last one - if (not points.empty() and points[0] != points[points.size() - 1]) { + if (!points.empty() && points[0] != points[points.size() - 1]) { points.push_back(points[0]); } return points;