Explorar o código

Add OpenCC (#474)

* Add OpenCC

* update opencc

* build opencc for mingw

* opencc: try fix ci errors

* opencc: try fix ci errors

* opencc: try fix ci errors

* opencc: try fix ci errors

* opencc: fix static build

* opencc: try using abs path for opencc_dict

* opencc(archlinux) requires python

* opencc: try disable build on mingw@macosx

* opencc: adjust link order and depends on python

* opencc: code review

* opencc: try fix ci
Shiwei Wang %!s(int64=4) %!d(string=hai) anos
pai
achega
1b19d8b8a7
Modificáronse 2 ficheiros con 85 adicións e 0 borrados
  1. 53 0
      packages/o/opencc/patches/1.1.2/fix-static.patch
  2. 32 0
      packages/o/opencc/xmake.lua

+ 53 - 0
packages/o/opencc/patches/1.1.2/fix-static.patch

@@ -0,0 +1,53 @@
+diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt
+index e9b921f..b55e7b4 100644
+--- a/data/CMakeLists.txt
++++ b/data/CMakeLists.txt
+@@ -1,6 +1,7 @@
+ find_package(PythonInterp REQUIRED)
+ 
+ set(OPENCC_DICT_BIN opencc_dict)
++set(OPENCC_DICT_EXECUTABLE "$<TARGET_FILE:${OPENCC_DICT_BIN}>")
+ set(DICT_MERGE_BIN "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/merge.py")
+ set(DICT_REVERSE_BIN "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/reverse.py")
+ set(DICT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dictionary)
+@@ -136,7 +137,7 @@ foreach(DICT ${DICTS})
+     COMMENT
+       "Building ${DICT}.ocd2"
+     COMMAND
+-      ${OPENCC_DICT_BIN}
++      ${OPENCC_DICT_EXECUTABLE}
+         --input ${DICT_${DICT}_INPUT}
+         --output ${DICT}.ocd2
+         --from text
+diff --git a/deps/marisa-0.2.6/CMakeLists.txt b/deps/marisa-0.2.6/CMakeLists.txt
+index 305f273..1472532 100644
+--- a/deps/marisa-0.2.6/CMakeLists.txt
++++ b/deps/marisa-0.2.6/CMakeLists.txt
+@@ -17,3 +17,10 @@ set(
+ add_library(marisa STATIC ${LIBMARISA_SOURCES})
+ set_target_properties(marisa PROPERTIES POSITION_INDEPENDENT_CODE ON)
+ source_group(marisa FILES ${LIBMARISA_SOURCES})
++
++if (NOT BUILD_SHARED_LIBS)
++  install(TARGETS marisa
++    RUNTIME DESTINATION bin
++    LIBRARY DESTINATION lib
++    ARCHIVE DESTINATION lib)
++endif()
+diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
+index 8ec1177..2bc2900 100644
+--- a/src/CMakeLists.txt
++++ b/src/CMakeLists.txt
+@@ -104,7 +104,11 @@ endif()
+ add_library(libopencc ${LIBOPENCC_SOURCES} ${LIBOPENCC_HEADERS})
+ set_target_properties(libopencc PROPERTIES POSITION_INDEPENDENT_CODE ON)
+ source_group(libopencc FILES ${LIBOPENCC_SOURCES} ${LIBOPENCC_HEADERS})
+-target_link_libraries(libopencc marisa)
++if (NOT BUILD_SHARED_LIBS)
++  target_link_libraries(libopencc PUBLIC marisa)
++else()
++  target_link_libraries(libopencc marisa)
++endif()
+ 
+ GENERATE_EXPORT_HEADER(
+   libopencc

+ 32 - 0
packages/o/opencc/xmake.lua

@@ -0,0 +1,32 @@
+package("opencc")
+
+    set_homepage("https://github.com/BYVoid/OpenCC")
+    set_description("Conversion between Traditional and Simplified Chinese.")
+
+    set_urls("https://github.com/BYVoid/OpenCC/archive/ver.$(version).zip")
+    add_versions("1.1.2", "b4a53564d0de446bf28c8539a8a17005a3e2b1877647b68003039e77f8f7d9c2")
+
+    add_patches("1.1.2", path.join(os.scriptdir(), "patches", "1.1.2", "fix-static.patch"), "a51b58d5d092a057461bc8c7661546cde5c39af3c1f4438abc1d89e1a1df7122")
+
+    add_deps("cmake", {kind = "binary"})
+    if not is_plat("bsd") then
+        add_deps("python 3.x", {kind = "binary"})
+    end
+
+    on_load(function (package)
+        if package:is_plat("linux", "mingw") and not package:config("shared") then
+            package:add("links", "opencc", "marisa")
+        end
+        package:addenv("PATH", "bin")
+    end)
+
+    on_install("windows", "mingw@windows,msys", "linux", "macosx", "bsd", function (package)
+        local configs = {"-DBUILD_DOCUMENTATION=OFF", "-DENABLE_GTEST=OFF"}
+        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"))
+        import("package.tools.cmake").install(package, configs)
+    end)
+
+    on_test("windows", "mingw@windows,msys", "linux", "macosx", "bsd", function (package)
+        assert(package:has_cfuncs("opencc_open", {includes = "opencc/opencc.h"}))
+    end)