From f674f33635aa8622e9c13a511403e48bf73b5b0a Mon Sep 17 00:00:00 2001 From: Chi Huu Huynh <73843190+Chi-EEE@users.noreply.github.com> Date: Wed, 17 Jan 2024 09:20:11 +0000 Subject: [PATCH] cartographer: add package (#2804) * cartographer: add package * clean unneeded code * cartographer: replace cairo with correct header * cartographer: update port `xmake.lua` * cartographer: patch to remove include config.h * cartographer: fixed only on linux * cartographer: use cxx17 * cartographer: set test C++ to 17 * cartographer: Remove all test files and remove unistd for windows * cartographer: remove config via io.replace * cartographer: fix for windows * cartographer: add zlib * cartographer: move zlib above boost * cartographer: specify boost version * cartographer: use boost 1.83.0 * cartographer: remove specify boost version * Update xmake.lua * cartographer: disable shared for windows --------- Co-authored-by: ruki --- .../patches/1.0.0/fix-build-error.patch | 39 ++++++++++++++ packages/c/cartographer/port/xmake.lua | 53 +++++++++++++++++++ packages/c/cartographer/xmake.lua | 47 ++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 packages/c/cartographer/patches/1.0.0/fix-build-error.patch create mode 100644 packages/c/cartographer/port/xmake.lua create mode 100644 packages/c/cartographer/xmake.lua diff --git a/packages/c/cartographer/patches/1.0.0/fix-build-error.patch b/packages/c/cartographer/patches/1.0.0/fix-build-error.patch new file mode 100644 index 00000000000..b1f15a15019 --- /dev/null +++ b/packages/c/cartographer/patches/1.0.0/fix-build-error.patch @@ -0,0 +1,39 @@ +diff --git a/cartographer/common/math.h b/cartographer/common/math.h +index c4a77ef..0248f66 100644 +--- a/cartographer/common/math.h ++++ b/cartographer/common/math.h +@@ -17,6 +17,10 @@ + #ifndef CARTOGRAPHER_COMMON_MATH_H_ + #define CARTOGRAPHER_COMMON_MATH_H_ + ++#ifndef M_PI ++#define M_PI 3.14159265358979323846 ++#endif ++ + #include + #include + +diff --git a/cartographer/common/thread_pool.cc b/cartographer/common/thread_pool.cc +index bc3c743..c61704d 100644 +--- a/cartographer/common/thread_pool.cc ++++ b/cartographer/common/thread_pool.cc +@@ -16,7 +16,6 @@ + + #include "cartographer/common/thread_pool.h" + +-#include + #include + #include + #include +diff --git a/cartographer/mapping/pose_graph_interface.h b/cartographer/mapping/pose_graph_interface.h +index 6483ef4..6456720 100644 +--- a/cartographer/mapping/pose_graph_interface.h ++++ b/cartographer/mapping/pose_graph_interface.h +@@ -18,6 +18,7 @@ + #define CARTOGRAPHER_MAPPING_POSE_GRAPH_INTERFACE_H_ + + #include ++#include + + #include "cartographer/common/optional.h" + #include "cartographer/mapping/id.h" diff --git a/packages/c/cartographer/port/xmake.lua b/packages/c/cartographer/port/xmake.lua new file mode 100644 index 00000000000..8f419c03e92 --- /dev/null +++ b/packages/c/cartographer/port/xmake.lua @@ -0,0 +1,53 @@ +add_rules("mode.debug", "mode.release") + +add_requires("boost", {configs = {iostreams = true}}) +add_requires("ceres-solver", {configs = {suitesparse = true}}) +add_requires("abseil", "cairo", "eigen", "glog", "lua", "protobuf-cpp", "zlib") + +target("cartographer") + set_kind("$(kind)") + set_languages("cxx17") + + add_packages( + "abseil", + "boost", + "ceres-solver", + "cairo", + "eigen", + "glog", + "lua", + "zlib" + ) + + add_packages("protobuf-cpp", {public = true}) + add_rules("protobuf.cpp") + + add_files("cartographer/**.proto", {proto_rootdir = "cartographer", proto_autogendir = path.join("$(buildir)", "proto") , proto_public = true}) + + add_includedirs("$(buildir)/proto/cartographer") + add_includedirs("$(buildir)/proto", { public = true }) + + add_headerfiles("$(buildir)/proto/(cartographer/**.h)") + add_headerfiles("$(buildir)/proto/cartographer/(**.h)") + + remove_files("cartographer/**_service.proto") + + add_headerfiles("(cartographer/**.h)") + add_files("cartographer/**.cc") + + remove_files("cartographer/io/serialization_format_migration.cc") + remove_headerfiles("cartographer/io/serialization_format_migration.h") + + remove_headerfiles("**/fake_*.h", "**/*test*.h", "**/mock*.h") + remove_files("**/fake_*.cc", "**/mock*.cc", "**/*_main.cc", "**/*test*.cc") + + -- BUILD_GRPC is not enabled + remove_headerfiles("cartographer/cloud/**.h") + remove_files("cartographer/cloud/**.cc") + remove_files("cartographer/cloud/proto/**.proto") + + add_includedirs(".", { public = true }) + + if is_plat("windows") then + add_defines("NOMINMAX") + end diff --git a/packages/c/cartographer/xmake.lua b/packages/c/cartographer/xmake.lua new file mode 100644 index 00000000000..205c303fc2f --- /dev/null +++ b/packages/c/cartographer/xmake.lua @@ -0,0 +1,47 @@ +package("cartographer") + set_homepage("https://github.com/cartographer-project/cartographer") + set_description("Cartographer is a system that provides real-time simultaneous localization and mapping (SLAM) in 2D and 3D across multiple platforms and sensor configurations.") + set_license("Apache-2.0") + + add_urls("https://github.com/cartographer-project/cartographer/archive/refs/tags/$(version).tar.gz", + "https://github.com/cartographer-project/cartographer.git") + + add_versions("1.0.0", "474a410bf6457eb8a0fd92ea412d7889fb013051e625d3ee25e8d65e4113fd6c") + + add_patches("1.0.0", path.join(os.scriptdir(), "patches", "1.0.0", "fix-build-error.patch"), "a4bb53d6f098c77a397d72c244d4283af1f9eec8a4ca7a7fa28de77b06d1201e") + + if is_plat("windows") then + add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true}) + end + + add_deps("cmake") + add_deps("zlib") + add_deps("boost", {configs = {iostreams = true}}) + add_deps("ceres-solver", {configs = {suitesparse = true}}) + add_deps("abseil", "cairo", "eigen", "lua", "protobuf-cpp") + + on_install("windows|x64", "windows|x86", "macosx|x86_64", "linux", function (package) + for _, headerfile in ipairs(os.files("cartographer/**.h")) do + io.replace(headerfile, "cairo/cairo.h", "cairo.h", {plain = true}) + end + for _, protofile in ipairs(os.files("cartographer/**.proto")) do + io.replace(protofile, [[import "cartographer/]], [[import "]], {plain = true}) + end + os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua") + io.replace("cartographer/common/configuration_file_resolver.cc", [[#include "cartographer/common/config.h"]], "", {plain = true}) + io.replace("cartographer/common/configuration_file_resolver.cc", [[configuration_files_directories_.push_back(kConfigurationFilesDirectory);]], "", {plain = true}) + local configs = {} + if is_plat("windows") then + io.replace("cartographer/common/thread_pool.cc", "#include ", "", {plain = true}) + end + import("package.tools.xmake").install(package, configs) + end) + + on_test(function (package) + assert(package:check_cxxsnippets({test = [[ + #include "cartographer/mapping/proto/map_builder_options.pb.h" + void test() { + cartographer::mapping::proto::MapBuilderOptions map_builder_options; + } + ]]}, {configs = {languages = "c++17"}})) + end)