Browse Source

fix protobuf for cartographer & fix protobuf (#3667)

* fix protobuf for cartographer & fix protobuf version:le 3.19.4

* protobuf-cpp: readd 26.1

* try to fix abseil linking

* Revert "try to fix abseil linking"

This reverts commit 03c8ed4215c410086f37249912608f63203e696b.

* protobuf-cpp: use shared abseil

* protobuf-cpp: fix adding shared abseil

* protobuf-cpp: set abseil shared to true

* protobuf-cpp: shared abseil if windows

* protobuf-cpp: use default config for abseil

* protobuf-cpp: add abseil if above greater or equal to 22.0

* protobuf-cpp: add patch to always use links

* abseil: test with cxx 17

* protobuf-cpp: rename patch

* abseil: try use C++14

* abseil: add cxx_standard config & protobuf-cpp: select C++17 if linux
Chi Huu Huynh 1 year ago
parent
commit
d8fc0686b5

+ 3 - 1
packages/a/abseil/xmake.lua

@@ -17,6 +17,8 @@ package("abseil")
 
 
     add_deps("cmake")
     add_deps("cmake")
 
 
+    add_configs("cxx_standard", {description = "Select c++ standard to build.", default = "14", type = "string", values = {"14", "17", "20"}})
+
     if is_plat("macosx") then
     if is_plat("macosx") then
         add_frameworks("CoreFoundation")
         add_frameworks("CoreFoundation")
     end
     end
@@ -32,7 +34,7 @@ package("abseil")
             io.replace(path.join("absl", "synchronization", "internal", "pthread_waiter.h"), "#ifndef _WIN32", "#if !defined(_WIN32) && !defined(__MINGW32__)", {plain = true})
             io.replace(path.join("absl", "synchronization", "internal", "pthread_waiter.h"), "#ifndef _WIN32", "#if !defined(_WIN32) && !defined(__MINGW32__)", {plain = true})
             io.replace(path.join("absl", "synchronization", "internal", "win32_waiter.h"), "#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA", "#if defined(_WIN32) && !defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_VISTA", {plain = true})
             io.replace(path.join("absl", "synchronization", "internal", "win32_waiter.h"), "#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_VISTA", "#if defined(_WIN32) && !defined(__MINGW32__) && _WIN32_WINNT >= _WIN32_WINNT_VISTA", {plain = true})
         end
         end
-        local configs = {"-DCMAKE_CXX_STANDARD=14", "-DABSL_ENABLE_INSTALL=ON", "-DABSL_PROPAGATE_CXX_STD=ON"}
+        local configs = {"-DCMAKE_CXX_STANDARD=" .. package:config("cxx_standard"), "-DABSL_ENABLE_INSTALL=ON", "-DABSL_PROPAGATE_CXX_STD=ON"}
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
         import("package.tools.cmake").install(package, configs, {buildir = os.tmpfile() .. ".dir"})
         import("package.tools.cmake").install(package, configs, {buildir = os.tmpfile() .. ".dir"})

+ 2 - 1
packages/c/cartographer/port/xmake.lua

@@ -1,7 +1,8 @@
 add_rules("mode.debug", "mode.release")
 add_rules("mode.debug", "mode.release")
 
 
 add_requires("ceres-solver 2.1.0", {configs = {suitesparse = true}})
 add_requires("ceres-solver 2.1.0", {configs = {suitesparse = true}})
-add_requires("abseil", "cairo", "eigen", "glog", "lua", "protobuf-cpp", "zlib")
+add_requires("abseil", "cairo", "eigen", "glog", "lua", "zlib")
+add_requires("protobuf-cpp 3.19.4")
 
 
 target("cartographer")
 target("cartographer")
     set_kind("$(kind)")
     set_kind("$(kind)")

+ 2 - 1
packages/c/cartographer/xmake.lua

@@ -21,7 +21,8 @@ package("cartographer")
     add_deps("cmake")
     add_deps("cmake")
     add_deps("zlib")
     add_deps("zlib")
     add_deps("ceres-solver 2.1.0", {configs = {suitesparse = true}})
     add_deps("ceres-solver 2.1.0", {configs = {suitesparse = true}})
-    add_deps("abseil", "cairo", "eigen", "lua", "protobuf-cpp")
+    add_deps("protobuf-cpp 3.19.4")
+    add_deps("abseil", "cairo", "eigen", "lua")
 
 
     on_install("windows|x64", "windows|x86", "macosx|x86_64", "linux", function (package)
     on_install("windows|x64", "windows|x86", "macosx|x86_64", "linux", function (package)
         for _, headerfile in ipairs(os.files("cartographer/**.h")) do
         for _, headerfile in ipairs(os.files("cartographer/**.h")) do

+ 13 - 0
packages/p/protobuf-cpp/patches/26.1/use_abseil_links.patch

@@ -0,0 +1,13 @@
+diff --git a/cmake/abseil-cpp.cmake b/cmake/abseil-cpp.cmake
+index a4e9d22..5e5d4d5 100644
+--- a/cmake/abseil-cpp.cmake
++++ b/cmake/abseil-cpp.cmake
+@@ -37,7 +37,7 @@ elseif(protobuf_ABSL_PROVIDER STREQUAL "package")
+ endif()
+ set(_protobuf_FIND_ABSL "if(NOT TARGET absl::strings)\n  find_package(absl CONFIG)\nendif()")
+ 
+-if (BUILD_SHARED_LIBS AND MSVC)
++if (FALSE)
+   # On MSVC Abseil is bundled into a single DLL.
+   # This condition is necessary as of abseil 20230125.3 when abseil is consumed via add_subdirectory,
+   # the abseil_dll target  is named abseil_dll, while if abseil is consumed via find_package, the target

+ 18 - 6
packages/p/protobuf-cpp/xmake.lua

@@ -18,10 +18,11 @@ package("protobuf-cpp")
 
 
     add_patches("3.17.3", path.join(os.scriptdir(), "patches", "3.17.3", "field_access_listener.patch"), "ac9bdf49611b01e563fe74b2aaf1398214129454c3e18f1198245549eb281e85")
     add_patches("3.17.3", path.join(os.scriptdir(), "patches", "3.17.3", "field_access_listener.patch"), "ac9bdf49611b01e563fe74b2aaf1398214129454c3e18f1198245549eb281e85")
     add_patches("3.19.4", path.join(os.scriptdir(), "patches", "3.19.4", "vs_runtime.patch"), "8e73e585d29f3b9dca3c279df0b11b3ee7651728c07f51381a69e5899b93c367")
     add_patches("3.19.4", path.join(os.scriptdir(), "patches", "3.19.4", "vs_runtime.patch"), "8e73e585d29f3b9dca3c279df0b11b3ee7651728c07f51381a69e5899b93c367")
+    add_patches("26.1", path.join(os.scriptdir(), "patches", "26.1", "use_abseil_links.patch"), "123e3f4b0c602f3fc0470d58cd1be1837ddf41da070d5299041b5891595b2487")
 
 
     add_configs("zlib", {description = "Enable zlib", default = false, type = "boolean"})
     add_configs("zlib", {description = "Enable zlib", default = false, type = "boolean"})
 
 
-    add_deps("cmake", "abseil")
+    add_deps("cmake")
 
 
     if is_plat("windows") then
     if is_plat("windows") then
         add_links("libprotobuf")
         add_links("libprotobuf")
@@ -38,15 +39,26 @@ package("protobuf-cpp")
         if package:config("zlib") then
         if package:config("zlib") then
             package:add("deps", "zlib")
             package:add("deps", "zlib")
         end
         end
+        if package:version():ge("22.0") then
+            package:add("deps", "abseil", {configs = {cxx_standard = (package:is_plat("linux") and "17" or "14")}})
+        end
     end)
     end)
 
 
     on_install("windows", "linux", "macosx", function (package)
     on_install("windows", "linux", "macosx", function (package)
-        -- os.cd("cmake")
+        if package:version():le("3.19.4") then
+            os.cd("cmake")
+        end
         io.replace("CMakeLists.txt", "set(protobuf_DEBUG_POSTFIX \"d\"", "set(protobuf_DEBUG_POSTFIX \"\"", {plain = true})
         io.replace("CMakeLists.txt", "set(protobuf_DEBUG_POSTFIX \"d\"", "set(protobuf_DEBUG_POSTFIX \"\"", {plain = true})
-        local configs = {"-Dprotobuf_BUILD_TESTS=OFF",
-                         "-Dprotobuf_BUILD_PROTOC_BINARIES=ON",
-                         "-Dprotobuf_ABSL_PROVIDER=package"}
+     
+        local configs = {"-Dprotobuf_BUILD_TESTS=OFF", "-Dprotobuf_BUILD_PROTOC_BINARIES=ON"}
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+      
+        local packagedeps = {}
+        if package:version():ge("22.0") then
+            table.insert(packagedeps, "abseil")
+            table.insert(configs, "-Dprotobuf_ABSL_PROVIDER=package")
+        end
+
         if package:is_plat("windows") then
         if package:is_plat("windows") then
             table.insert(configs, "-Dprotobuf_MSVC_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
             table.insert(configs, "-Dprotobuf_MSVC_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
             if package:config("shared") then
             if package:config("shared") then
@@ -56,7 +68,7 @@ package("protobuf-cpp")
         if package:config("zlib") then
         if package:config("zlib") then
             table.insert(configs, "-Dprotobuf_WITH_ZLIB=ON")
             table.insert(configs, "-Dprotobuf_WITH_ZLIB=ON")
         end
         end
-        import("package.tools.cmake").install(package, configs, {buildir = "build"})
+        import("package.tools.cmake").install(package, configs, {buildir = "build", packagedeps = packagedeps})
         os.trycp("build/Release/protoc.exe", package:installdir("bin"))
         os.trycp("build/Release/protoc.exe", package:installdir("bin"))
     end)
     end)