I’m trying to compile my first app using snap. It’s a simple command line tool but relies on OpenCV. Currently, I compile it using a CMakeLists.txt which has find_package(OpenCV REQUIRED) as well as target_link_libraries. I then run the following:
$ cmake .
$ make
which produces the binary of the project.
I’d like to package everything as a snap which includes the OpenCV libraries. I went as far as downloading OpenCV from source (like I’d usually do) then including it as a part.I know the compilation process but not sure how to first compile OpenCV then link it to my app.
It’s pretty easy to use OpenCV as a build-package if you don’t want to build it from source (doing so is a snapcraft demo, actually).
However, assuming you’re building it from source because you need a newer (or older) version than what is in the archive, it should be pretty easy.
Make OpenCV its own part, and utilize the after keyword for the part that depends upon it (i.e. the one using find_package(OpenCV REQUIRED). after: [opencv] or something (more information here). That should Just Work. If it doesn’t we can investigate further .
However it won’t compile as expected. How will I tell snapcraft to produce the necessary libraries and link that to my CMakeLists.txt for the main app?
Progress…sort of? This allows me to compile the local opencv library but not sure if this is the best practice. I can always use a custom script to do the make install process then run CMake against my app but that kinda defeats the whole purpose of snapcraft right?
So it downloads OpenCV first and compiles using CMake. It then compiles the main app (img2vector) after opencv-snap. The trick in the actual app was to have install(TARGETS img2vector RUNTIME DESTINATION bin) in the CMakeLists.txt
Yeah, without install rules the cmake plugin doesn’t know what you want installed into the snap, or where to put it. It’s good to add it in your case, but you may not always have control over the source that doesn’t have install rules. In which case, you could do something like this: