cmake ios framework
2019/5/5
如果你開發了一套c++**,要在android和iphone兩種手機上執行,就要在分別編譯android和iphone兩個平台下的動態庫。
android開發目前是用 android studio(sdk/ndk), iphone開發是用xcode.
當你增加或減少乙個源**檔案後,要在android studio和xcode內分別新增這個源**。
隨著時間的推移,原始檔變來變去,你會煩不勝煩。
我準備的演示**目錄如下:
**目錄
描述tvm_model
能生成 android 和 iphone兩個平台的庫.
tvm_model.cc(功能實現函式)
cmakelists.txt : cmake 需要的專案檔案
android 平台: cmake生成的檔案是libtvm_model.so
ios 平台: cmake生成的檔案是 tvm_model.framework
tvm_demo_android
tvm_demo_ios
用以下命令,確認你是否安裝了cmake:
cmake --version
在我的mac機器上,輸出是:
cmake version 3.13.1
根據cmake官方文件framework,resource,製作的cmakelists.txt內容如下:
用以下命令編譯出庫檔案:cmake_minimum_required(version 3.11)
project(tvm_model)
add_library(tvm_model shared
tvm_model.cc
tvm_model.hpp
)set(resource_files
readme.md
)set_target_properties(tvm_model properties
framework true
framework_version a
macosx_framework_identifier cn.tvm.tvm_model
# macosx_framework_info_plist info.plist
# "current version" in semantic format in mach-o binary file
version 1.0.0
# "compatibility version" in semantic format in mach-o binary file
soversion 1.0.0
public_header tvm_model.hpp
xcode_attribute_code_sign_identity "iphone developer"
resource "$"
)
我們期望 readme.md 被複製到 tvm_model.framework的resources目錄下,但是很上面的make命令生成的tvm_model.framework,卻沒有包含 readme.md.cd ./tvm_demo1/src/tvm_model
mkdir build
cd build
cmake ..
make
參照cmake 打包 ios sdk, 我們可以把 readme.md, 複製到 tvm_model.framework 目錄.
然後,做乙個build.sh,以便能反覆編譯(只編譯模擬器版本):cmake_minimum_required(version 3.14)
project (tvm_model c cxx)
# includes
include_directories($)
set(resource_files1
readme.md
)add_library(tvm_model shared
tvm_model_c.cc
tvm_model_c.hpp
tvm_model.mm
tvm_model.h
)# debug symbols set in xcode project
set_xcode_property(tvm_model gcc_generate_debugging_symbols yes "all")
set(header_files1
tvm_model_c.hpp
tvm_model.h
)set(resource_files1
readme.md
)set_target_properties(tvm_model properties
framework true
framework_version a
macosx_framework_identifier cn.tvm.tvm_model
# macosx_framework_info_plist info.plist
# "current version" in semantic format in mach-o binary file
version 1.0.0
# "compatibility version" in semantic format in mach-o binary file
soversion 1.0.0
public_header "$"
resource "$"
# xcode_attribute_code_sign_identity "iphone developer"
)
#!/bin/bash
[ -d "build" ] && rm -r build/
mkdir build
cd build
cmake .. -g xcode -dcmake_toolchain_file=../ios.toolchain.cmake -dplatform=simulator64
cmake --build . --config debug
cmake --build . --config release
cd ..
cmake 生成 動態庫
一,目錄結構 cmakelists.txt include shared hello.h src hello.cpp main.cpp link cmakelists.txt contains the cmake commands you wish to run link include share...
CMake生成版本號
cmake生成版本號 金慶的專欄 原來的cmake需要用shell指令碼生成svn版本號,再作為cmake引數傳入。cmake呼叫指令碼示例 bin sh cmake.sh servercoderoot code server coderevnum svn info grep revision aw...
使用cmake來生成makefile
cmake 提供了比 autoconfig 更簡潔的語法 在 linux 平台下使用 cmake 生成 makefile 並編譯的流程如下 編寫cmakelists.txt。執行命令 cmake path 或者 ccmake path 生成makefile path是cmakelists.txt所在...