Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export libraries with components in CMAKE?

I have tried finding this information on the official CMAKE wiki as well as searching SO (currently waiting for boost to download so I can wade through the source looking for how they do it). I was hoping someone here may be able to help with how this is done, or point me in the right direction to the answers!

I have a project that has several components. Right now, the project has subdirectories for libraries, and for applications. I am attempting to refactor the project and have applications in individual repositories and have the libraries exported.

How do other projects make it possible to use the following command (specifically, specifying which components):

FIND_PACKAGE (Boost REQUIRED COMPONENTS system date_time filesystem)

I would like to use the same system for my own project:

FIND_PACKAGE (Project REQUIRED COMPONENTS view gui execution analysis)

Any help you could provide would be greatly appreciated.

like image 229
adairdavid Avatar asked Nov 13 '22 00:11

adairdavid


1 Answers

A good guide on how to write finders you may find in CMake documentation (old CMake packages for popular distros had /usr/share/cmake/Modules/readme.txt file, but it seems nowadays it's absent or doesn't have any helpful info anymore ;-). Particularly it explains how to write a correct module w/ supporting "standard" syntax (REQUIRE, COMPONENTS & etc) using find_package_handle_standard_args. This is applicable for non-CMake-based packages and turns the find_package into module mode.

For CMake-based projects, there is a better (native) way to export targets (aka config mode of the find_package). The modern CMake can help you to generate the needed *.cmake files, and your project ought to install() 'em into a proper location. So, dependent projects could use find_package() to import your targets (libraries or executables).

like image 125
zaufi Avatar answered Nov 15 '22 04:11

zaufi