Просмотр исходного кода

microsoft-apsi: support cross-compilation (#5828)

* microsoft-apsi: support cross-compilation

* limit plat
star9029 8 месяцев назад
Родитель
Сommit
9a320b00b6
2 измененных файлов с 37 добавлено и 21 удалено
  1. 20 9
      packages/f/flatbuffers/xmake.lua
  2. 17 12
      packages/m/microsoft-apsi/xmake.lua

+ 20 - 9
packages/f/flatbuffers/xmake.lua

@@ -26,8 +26,13 @@ package("flatbuffers")
 
         local configs = {"-DFLATBUFFERS_BUILD_TESTS=OFF"}
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
-        table.insert(configs, "-DFLATBUFFERS_BUILD_SHAREDLIB=" .. (package:config("shared") and "ON" or "OFF"))
-        table.insert(configs, "-DFLATBUFFERS_BUILD_FLATLIB=" .. (package:config("shared") and "OFF" or "ON"))
+        if package:is_binary() then
+            table.insert(configs, "-DFLATBUFFERS_BUILD_SHAREDLIB=OFF")
+            table.insert(configs, "-DFLATBUFFERS_BUILD_FLATLIB=OFF")
+        else
+            table.insert(configs, "-DFLATBUFFERS_BUILD_SHAREDLIB=" .. (package:config("shared") and "ON" or "OFF"))
+            table.insert(configs, "-DFLATBUFFERS_BUILD_FLATLIB=" .. (package:config("shared") and "OFF" or "ON"))
+        end
         if package:config("shared") and package:is_plat("windows") then
             table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
         end
@@ -36,6 +41,10 @@ package("flatbuffers")
         table.insert(configs, "-DFLATBUFFERS_BUILD_FLATHASH=" .. (package:is_cross() and "OFF" or "ON"))
         import("package.tools.cmake").install(package, configs)
 
+        if package:is_binary() then
+            os.tryrm(package:installdir("include"))
+        end
+
         if package:is_plat("windows") and package:is_debug() then
             os.trymv(package:installdir("lib/flatc.pdb"), package:installdir("bin"))
         end
@@ -45,11 +54,13 @@ package("flatbuffers")
         if not package:is_cross() then
             os.vrun("flatc --version")
         end
-        assert(package:check_cxxsnippets({test = [[
-            void test() {
-                flatbuffers::FlatBufferBuilder builder;
-                builder.CreateString("MyMonster");
-                flatbuffers::DetachedBuffer dtbuilder = builder.Release();
-            }
-        ]]}, {configs = {languages = "c++14"}, includes = "flatbuffers/flatbuffers.h"}))
+        if package:is_library() then
+            assert(package:check_cxxsnippets({test = [[
+                void test() {
+                    flatbuffers::FlatBufferBuilder builder;
+                    builder.CreateString("MyMonster");
+                    flatbuffers::DetachedBuffer dtbuilder = builder.Release();
+                }
+            ]]}, {configs = {languages = "c++14"}, includes = "flatbuffers/flatbuffers.h"}))
+        end
     end)

+ 17 - 12
packages/m/microsoft-apsi/xmake.lua

@@ -15,15 +15,11 @@ package("microsoft-apsi")
     add_deps("microsoft-seal", {configs = {ms_gsl = true, zstd = true, throw_tran = false}})
     add_deps("microsoft-kuku", "flatbuffers", "jsoncpp")
 
-    if on_check then
-        on_check(function (package)
-            -- TODO: To support cross-compilation, need host flatc tool and target flatbuffers library
-            -- Remove cmake try_run, replace check_cxx_source_runs to check_cxx_source_compiles
-            if not package:is_arch64() or package:is_cross() then
-                raise("package(microsoft-apsi) unsupported cross-compilation")
-            end
-        end)
-    end
+    on_check(function (package)
+        if not package:is_arch64() then
+            raise("package(microsoft-apsi) unsupported 32-bit")
+        end
+    end)
 
     on_load(function (package)
         if package:config("log4cplus") then
@@ -32,6 +28,9 @@ package("microsoft-apsi")
         if package:config("cppzmq") then
             package:add("deps", "cppzmq")
         end
+        if package:is_cross() then
+            package:add("deps", "flatbuffers~binary", {host = true, private = true, kind = "binary"})
+        end
 
         local version = package:version()
         if version then
@@ -41,12 +40,18 @@ package("microsoft-apsi")
         end
     end)
 
-    on_install("windows", "linux", "macosx", "bsd", function (package)
+    on_install("windows", "linux", "macosx", "bsd", "android", function (package)
+        if package:is_cross() then
+            io.replace("CMakeLists.txt", "get_target_property(FLATBUFFERS_FLATC_PATH flatbuffers::flatc IMPORTED_LOCATION_RELEASE)", "", {plain = true})
+            io.replace("cmake/DetectArch.cmake", "if(MSVC)", "if(WIN32)", {plain = true})
+            io.replace("cmake/DetectArch.cmake", "check_cxx_source_runs", "check_cxx_source_compiles", {plain = true})
+        end
+
         local configs = {}
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
-        if package:is_plat("windows") then
-            table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
+        if package:is_cross() then
+            table.insert(configs, "-DFLATBUFFERS_FLATC_PATH=flatc")
         end
 
         table.insert(configs, "-DAPSI_USE_LOG4CPLUS=" .. (package:config("log4cplus") and "ON" or "OFF"))