使用OHOS SDK构建zziplib
参照OHOS IDE和SDK的安装方法配置好开发环境。
从gitee下载源码,当前最新的提交记录ID为6699e0fe8a0307b16dcc055eda04452e13abe63a
。
执行如下命令:
git clone https://gitee.com/mirrors/zziplib.git
进入源码所在的目录,创建批处理文件ohos_build.cmd
,内容如下:
@echo off
setlocal
set OHOS_SDK_HOME=D:\Tools\Huawei\OHOS\SDK\9
set CMAKE_HOME=D:\Tools\cmake-3.26.0-windows-x86_64
set PATH=%CMAKE_HOME%\bin;%PATH%
cmake --version
ninja --version
set SRC_ROOT=%CD%
set BUILD_ROOT=%SRC_ROOT%\build-ohos
set BUILD_TARGET=libzzip
cmake -G "Ninja Multi-Config" ^
-S %SRC_ROOT% ^
-B %BUILD_ROOT% ^
-DCMAKE_TOOLCHAIN_FILE=%OHOS_SDK_HOME%\native\build\cmake\ohos.toolchain.cmake ^
-DCMAKE_CXX_FLAGS="-Wno-unused-command-line-argument" ^
-DCMAKE_C_FLAGS="-Wno-unused-command-line-argument" ^
-DBUILD_STATIC_LIBS=ON ^
-DMSVC_STATIC_RUNTIME=ON ^
-DZZIPMMAPPED=OFF ^
-DZZIPFSEEKO=OFF ^
-DZZIPWRAP=OFF ^
-DZZIPSDL=OFF ^
-DZZIPBINS=OFF ^
-DZZIPTEST=OFF ^
-DZZIPDOCS=OFF ^
-DZZIPLIB_OPTIONS="-DZZIP_COMPAT=OFF;-DZZIP_PKGCONFIG=OFF"
cmake --build %BUILD_ROOT% --target %BUILD_TARGET% --config release --parallel
为了顺利通过编译,需要给现有的CMakeLists.txt
打个补丁,内容如下:
diff --git a/zzip/CMakeLists.txt b/zzip/CMakeLists.txt
index c294c1f..aa4bd34 100644
--- a/zzip/CMakeLists.txt
+++ b/zzip/CMakeLists.txt
@@ -35,6 +35,11 @@ else()
option(ZZIP_LIBLATEST "Ensure libname.lib links to libname-REL.lib" OFF)
endif()
+if(OHOS)
+set(ZZIP_COMPAT OFF)
+set(ZZIP_PKGCONFIG OFF)
+endif()
+
# used in zzip/_config.h
set(ZZIP_PACKAGE "${PROJECT_NAME}lib")
set(ZZIP_VERSION "${PROJECT_VERSION}")
@@ -359,7 +364,7 @@ if(ZZIP_LIBTOOL)
${outdir}/${lib}${libname}${librelease}${dll}.12
DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(ZZIPMMAPPED)
- endif(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG)
+ endif(BUILD_SHARED_LIBS AND CMAKE_SHARED_LIBRARY_SONAME_C_FLAG)
endif(ZZIP_LIBTOOL)
if(ZZIP_LIBLATEST)
进入CMD,在源码所在的目录下,执行如下命令:
call ohos_build.cmd
等待项目编译结束。
CMakeLists.txt
有编码错误,导致配置项目的时候存在告警,不过不影响项目的编译。
D:\workspace\CODE\zziplib>call ohos_build.cmd
cmake version 3.26.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
1.11.1
-- found sizeof(off_t/32)=8 and sizeof(off_t/64)=8
CMake Warning (dev) in zzip/CMakeLists.txt:
A logical block opening on the line
D:/workspace/CODE/zziplib/zzip/CMakeLists.txt:336 (if)
closes on the line
D:/workspace/CODE/zziplib/zzip/CMakeLists.txt:367 (endif)
with mis-matching arguments.
This warning is for project developers. Use -Wno-dev to suppress it.
本文来自博客园,作者:jackieathome,转载请注明原文链接:https://www.cnblogs.com/jackieathome/p/17937813