From abe71c9c079496854c57f822344956c8e3f2ea3f Mon Sep 17 00:00:00 2001 From: Funda Wang Date: Sun, 2 Mar 2025 01:02:07 +0800 Subject: [PATCH] adopt to new cmake macro --- ....2.4-third_party-port-to-newer-cmake.patch | 30 +++++++++++++ ...p-force-build-gglm-as-static-library.patch | 10 +++++ chatglm-cpp-ggml-install-into-libdir.patch | 42 +++++++++++++++++++ chatglm.cpp.spec | 33 +++++++-------- 4 files changed, 97 insertions(+), 18 deletions(-) create mode 100644 chatglm-cpp-0.2.4-third_party-port-to-newer-cmake.patch create mode 100644 chatglm-cpp-force-build-gglm-as-static-library.patch create mode 100644 chatglm-cpp-ggml-install-into-libdir.patch diff --git a/chatglm-cpp-0.2.4-third_party-port-to-newer-cmake.patch b/chatglm-cpp-0.2.4-third_party-port-to-newer-cmake.patch new file mode 100644 index 0000000..1f2292a --- /dev/null +++ b/chatglm-cpp-0.2.4-third_party-port-to-newer-cmake.patch @@ -0,0 +1,30 @@ +--- chatglm-cpp-0.2.4/third_party/ggml/CMakeLists.txt.orig 2025-03-02 00:51:54.194013600 +0800 ++++ chatglm-cpp-0.2.4/third_party/ggml/CMakeLists.txt 2025-03-02 00:52:08.654385400 +0800 +@@ -1,4 +1,4 @@ +-cmake_minimum_required (VERSION 3.0) ++cmake_minimum_required (VERSION 3.0...${CMAKE_VERSION}) + project(ggml VERSION 0.1.0) + + set(CMAKE_EXPORT_COMPILE_COMMANDS "on") +--- chatglm-cpp-0.2.4/third_party/pybind11/CMakeLists.txt.orig 2025-03-02 00:59:58.628792100 +0800 ++++ chatglm-cpp-0.2.4/third_party/pybind11/CMakeLists.txt 2025-03-02 01:00:10.782223100 +0800 +@@ -5,7 +5,7 @@ + # All rights reserved. Use of this source code is governed by a + # BSD-style license that can be found in the LICENSE file. + +-cmake_minimum_required(VERSION 3.5) ++cmake_minimum_required(VERSION 3.5...${CMAKE_VERSION}) + + # The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with + # some versions of VS that have a patched CMake 3.11. This forces us to emulate +--- chatglm-cpp-0.2.4/third_party/sentencepiece/CMakeLists.txt.orig 2025-03-02 00:59:30.568185600 +0800 ++++ chatglm-cpp-0.2.4/third_party/sentencepiece/CMakeLists.txt 2025-03-02 00:59:44.723732500 +0800 +@@ -12,7 +12,7 @@ + # See the License for the specific language governing permissions and + # limitations under the License.! + +-cmake_minimum_required(VERSION 3.1 FATAL_ERROR) ++cmake_minimum_required(VERSION 3.1...${CMAKE_VERSION} FATAL_ERROR) + file(STRINGS "VERSION.txt" SPM_VERSION) + message(STATUS "VERSION: ${SPM_VERSION}") + diff --git a/chatglm-cpp-force-build-gglm-as-static-library.patch b/chatglm-cpp-force-build-gglm-as-static-library.patch new file mode 100644 index 0000000..0226d16 --- /dev/null +++ b/chatglm-cpp-force-build-gglm-as-static-library.patch @@ -0,0 +1,10 @@ +--- chatglm-cpp-0.2.4/third_party/ggml/src/CMakeLists.txt.orig 2024-12-01 17:10:14.493165000 +0800 ++++ chatglm-cpp-0.2.4/third_party/ggml/src/CMakeLists.txt 2024-12-01 17:10:35.548291900 +0800 +@@ -255,6 +255,7 @@ + endif() + + add_library(${TARGET} ++ STATIC + ggml.c + ../include/ggml/ggml.h + ${GGML_CUDA_SOURCES} diff --git a/chatglm-cpp-ggml-install-into-libdir.patch b/chatglm-cpp-ggml-install-into-libdir.patch new file mode 100644 index 0000000..1f71437 --- /dev/null +++ b/chatglm-cpp-ggml-install-into-libdir.patch @@ -0,0 +1,42 @@ +--- chatglm-cpp-0.2.4/third_party/ggml/CMakeLists.txt.orig 2024-12-01 17:59:51.001662500 +0800 ++++ chatglm-cpp-0.2.4/third_party/ggml/CMakeLists.txt 2024-12-01 18:00:15.806717700 +0800 +@@ -13,6 +13,10 @@ + set(GGML_STANDALONE OFF) + endif() + ++if (UNIX) ++ include(GNUInstallDirs) ++endif() ++ + # options + + option(GGML_ALL_WARNINGS "ggml: enable all compiler warnings" ON) +@@ -107,4 +107,4 @@ + ${CMAKE_CURRENT_BINARY_DIR}/ggml.pc + @ONLY) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ggml.pc +- DESTINATION share/pkgconfig) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +--- chatglm-cpp-0.2.4/third_party/ggml/ggml.pc.in.orig 2024-12-01 17:18:58.848129300 +0800 ++++ chatglm-cpp-0.2.4/third_party/ggml/ggml.pc.in 2024-12-01 17:24:32.151359800 +0800 +@@ -1,7 +1,7 @@ + prefix=@CMAKE_INSTALL_PREFIX@ + exec_prefix=${prefix} + includedir=${prefix}/include +-libdir=${prefix}/lib ++libdir=@CMAKE_INSTALL_FULL_LIBDIR@ + + Name: ggml + Description: The GGML Tensor Library for Machine Learning +--- chatglm-cpp-0.2.4/third_party/ggml/src/CMakeLists.txt.orig 2024-12-01 17:10:14.493165000 +0800 ++++ chatglm-cpp-0.2.4/third_party/ggml/src/CMakeLists.txt 2024-12-01 17:25:19.532886400 +0800 +@@ -319,7 +320,7 @@ + PUBLIC_HEADER "${GGML_PUBLIC_HEADERS}") + + install(TARGETS ${TARGET} +- LIBRARY DESTINATION lib +- ARCHIVE DESTINATION lib/static ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION include/ggml + ) diff --git a/chatglm.cpp.spec b/chatglm.cpp.spec index 32cc5b4..72980ee 100644 --- a/chatglm.cpp.spec +++ b/chatglm.cpp.spec @@ -2,16 +2,17 @@ Name: chatglm-cpp Version: 0.2.4 -Release: 5 +Release: 6 License: MIT Summary: Port of Chinese lagre model ChatGLM-6B & ChatGLM2-6B implemented based on C/C++ URL: https://github.com/li-plus/chatglm.cpp Source0: https://github.com/li-plus/chatglm.cpp/releases/download/0.2.4/chatglm-cpp-%{version}.tar.gz -%ifarch loongarch64 Patch0: 0001-Fix-build-error-for-loongarch64.patch -%endif +Patch1: chatglm-cpp-force-build-gglm-as-static-library.patch +Patch2: chatglm-cpp-ggml-install-into-libdir.patch +Patch3: chatglm-cpp-0.2.4-third_party-port-to-newer-cmake.patch BuildRequires: gcc,gcc-c++,cmake Requires: sentencepiece @@ -24,33 +25,29 @@ it can be used for model dialogue based on local laptops. %autosetup -b 0 -n %{name}-%{version} -p1 %build -mkdir chatglm_builddir -pushd chatglm_builddir -cmake .. -%make_build -popd +%cmake +%cmake_build %install -pushd chatglm_builddir -%make_install -install bin/main %{buildroot}%{_prefix}/local/bin/chatglm_cpp_main -install lib/libchatglm.a %{buildroot}%{_prefix}/local/bin/libchatglm.a -install ../chatglm_cpp/convert.py %{buildroot}%{_prefix}/local/bin/chatglm_convert.py -mv %{buildroot}%{_prefix}/local/* %{buildroot}%{_prefix} +%cmake_install +install %{__cmake_builddir}/bin/main %{buildroot}%{_bindir}/chatglm_cpp_main +install %{__cmake_builddir}/lib/libchatglm.a %{buildroot}%{_libdir}/libchatglm.a +install chatglm_cpp/convert.py %{buildroot}%{_bindir}/chatglm_convert.py #Remove files from package sentencepiece. find %{buildroot}%{_prefix} -type f -name "*sentencepiece*" -exec rm -f {} + rm %{buildroot}%{_bindir}/spm_* -f -popd %files %{_bindir}/* -%{_libdir}/* +%{_libdir}/*.a %{_includedir}/* -%{_datadir}/pkgconfig/ggml.pc -/usr/lib/static/libggml.a +%{_libdir}/pkgconfig/ggml.pc %changelog +* Thu Nov 21 2024 Funda Wang - 0.2.4-6 +- adopt to new cmake macro + * Fri May 17 2024 zhangzikang - 0.2.4-5 - Fix build error for loongarch64 -- Gitee