cmakecoremlmlmodel

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


I have a detect_model.mlmodel which is trained by myself. I want to use it in xcode, but I don't wanna to add it into my xcode project manually. I have tried to write CMakeLists.txt to manage my xcode project. But how can I write in the CMake file to add detect_model.mlmodel into my xcode project and generate the detect_model.h header file?

I have tried to use set(mlmodel detect_model.mlmodel) and add_library(dst ${mlmodel}), but it is not correct.

The expected result is that I can use CMake to add detect_model.mlmodel into xcode project and generate the detect_model.h automatically.


Solution

  • You will probably need to add a custom rule that calls coremlc to generate the .h abd .m files and the .mlmodelc folder.

    This is how you'd do it from Terminal:

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

    You also need to add a rule to copy the .mlmodelc folder into the app bundle.