如何编写 CMakeLists.txt 以将 .mlmodel 添加到 xcode 项目

How can I write the CMakeLists.txt to add .mlmodel to xcode project

我有一个detect_model.mlmodel,是自己训练的。我想在 xcode 中使用它,但我不想手动将它添加到我的 xcode 项目中。我尝试编写 CMakeLists.txt 来管理我的 xcode 项目。但是我如何在CMake文件中写入将detect_model.mlmodel添加到我的xcode项目中并生成detect_model.h头文件?

我试过使用set(mlmodel detect_model.mlmodel)add_library(dst ${mlmodel}),但是不正确。

预期的结果是我可以使用CMake将detect_model.mlmodel添加到xcode项目中并自动生成detect_model.h

您可能需要添加调用 coremlc 的自定义规则来生成 .h abd .m 文件和 .mlmodelc 文件夹。

这就是您从终端执行此操作的方式:

mkdir output
xcrun coremlc compile YourModel.mlmodel output
xcrun coremlc generate Model.mlmodel output

您还需要添加一条规则,将 .mlmodelc 文件夹复制到应用程序包中。