[CMake] How do I build conditionally required libraries?

Gagnon, Joseph - 0553 - MITLL Joseph.Gagnon at ll.mit.edu
Thu Aug 20 09:14:57 EDT 2015


Please refer to this structure in the description below.

 

project_root

       CMakeLists.txt

       build

              Debug

              Release

       src

              CMakeLists.txt

              COTS   <- Third party packages used by various components

                     COTS_Package_A

                     ...

              Marshalling

                     CMakeLists.txt

                     intf   <- contains pure virtual class representing
interface

                               implemented by Marshaller A, B and C

                     Utility       <- used only by Marshaller A and B

                                     requires COTS_Package_A (include
paths/libraries)

                           CMakeLists.txt

                           Utility source files, etc.

                     Marshaller A

                           CMakeLists.txt

                           Marshaller_A source files, etc.

                     Marshaller B

                           CMakeLists.txt

                           ...

                     Marshaller C

                           CMakeLists.txt

                           ...

              ... (other plug-ins)

                                

Description

                                

The project depicted above is intended to build various "plug-ins" (e.g.
marshallers) that will be used by another larger application. Using the
marshaller example, for a given installation of the application, only one of
the marshaller implementations will be used. The plan is that only the
selected implementation is built and provided as a shared library, along
with other components it depends on (e.g. COTS_Package_A) to the larger
application being installed. For the other implementations that were not
chosen, nothing related to them (code, required 3rd party packages, etc.)
should be included.

 

For a scenario, let's assume that Marshaller A is chosen. It requires the
Utility package, which in itself requires COTS_Package_A (Marshaller C
doesn't have these requirements, but Marshaller B does). So, when Marshaller
A is built, I also need to build Utility (along with its dependency on COTS
A).

 

I am assuming that each implementation should be built as EXCLUDE_FROM_ALL
so that they aren't all automatically built when make is run and instead
must be explicitly built (manually or by some other means) by running make
with the specific target.

 

Problem

 

I have not been able to figure out how to make this kind of behavior occur
using CMake. I have tried add_custom_target and add_dependencies to build
the Utility package when Marshaller A (or B) is being built, but have had no
luck. At first I thought I had it because when I ran make, the make build
messages seemed to indicate success. However, I knew it was not actually
doing the build because I deliberately left out the include_directories call
(for COTS A) in the Utility CMakeLists.txt to force compilation errors and
no errors were reported when the target build was performed. Obviously
something is not right.

 

If anyone has run into this type of scenario and has figured out a way to do
this with CMake, I would really appreciate any information you could
provide. I'm still new at using CMake and have not used, not do I understand
(yet) many of its functions and more advanced techniques.

 

Thank you,

Joe Gagnon

 

Engineer II

Group 53 - Secure Resilient Systems and Technology

MIT Lincoln Laboratory

Lexington, MA

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150820/43de7b7d/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5625 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150820/43de7b7d/attachment-0001.bin>


More information about the CMake mailing list