質問

My problem: I have a library project which I want to distribute in binary form. I want my clients to be able to integrate this library with their projects as comfortably as possible. Also, I would prefer if they did not have to deal with a complex installation process. I assume them to be able to use CMake at a beginners level (which means adding header and source files, find_package() and add_executable()).

In best case, I'd imagine the workflow with my package to look like this:

  • Download the package with headers and binaries only. No source, no CMake, make, make install!
  • Extract the package.
  • Move the content to special directory where other packages are. (This directory can be in environment variable or anything like that.)
  • find_package() works.

It should be like this in both Windows 7 and newest Ubuntu.

For me, I've been learning CMake for the last 2 days and I find the documentation extremely hard-to-understand (I never had such trouble with learning things like Qt, qtcreator, sdl, pulse audio, git, OpenGL, ...) and that's why I'm asking.

Resolution:

Use packaging system of cmake.

Notes:

  • Of course I found this solution before asking, but I made an error (used *Targets.cmake file for build tree in install tree) and thought it's not usable for my purposes.
  • I used the package system and it wasn't working well, see related problems.

Related problems:

EDIT:

  • Changed "find_library" references to "find_package" as I mistook these two during writing.
  • Added resolution and related problems sections.
役に立ちましたか?

解決

Take a look at CMake packages.

This will allow pretty much exactly the user workflow that you described. The idea here is that when you build your project, CMake will write a configuration file for you to ship with the binaries. Your users can then load that config file in their CMake project (using find_package) and will be able to link to your binaries with a minimum of effort (usually a simple target_link_libraries call does the job).

This approach is to be preferred over the classic find_library approach, which potentially requires a lot more steps on the user's side to get things up and running.

As for your troubles regarding learning CMake: I feel your pain. CMake is not particularly easy to learn by nature. On top of that a lot of the documentation available on the web is severely outdated. I'd recommend starting with the updated CMake reference manual which has been restructured for the upcoming CMake 3.0 release. It's still a lot of content to dig through, so don't expect perfect results too quickly, but it's a good place to start.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top