[CMake] add_library without source code

Ingolf Steinbach ingolf.steinbach at googlemail.com
Thu Jul 29 03:26:52 EDT 2010


2010/7/28 Michael Wild <themiwi at gmail.com>:
> So, these external libraries should be compiled using ExternalProject_Add (refer to the docs). [...]

Ok. I cannot check right now but your proposed way probably solves that problem.

> If I didn't understand your scenario correctly, please provide some more detail and what you would CMake expect to do. Also, what would you do in "manual mode", i.e. if you did it by just using command line operations.

So let's turn to another situation:

Our product comes in different configurations (for instance to support
different display devices or communication protocols). Due to
restrictions with respect to the size of the code, each configuration
only contains those modules which are needed for that configuration.
So there are the following Modules

B - basic functionality; used in all configurations
C1 - communication module, type 1
C2 - communication module, type 2
C3 - communication module, type 3
Da - display module, type a
Db - display module, type b

Each configuration consists of A and one of C* and D*.

My approach would be to have the following structure

top_level
 +- C
 |   +- include (external interface of each of the C* modules)
 |   +- C1 (static library with implementation of C1)
 |   +- C2 (static library with implementation of C1)
 |   +- C3 (static library with implementation of C1)
 +- D
 |   +- include (external interface of each of the D* modules)
 |   +- Da (static library with implementation of Da)
 |   +- Db (static library with implementation of Da)
 +- B  (static library with implementation of basic functionality)
 +- config
     +- 1a (executable B, C1, Da)
     +- 1b (executable B, C1, Db)
     +- 2a (executable B, C2, Da)
     +- 2b (executable B, C2, Db)
     +- 3a (executable B, C3, Da)
     +- 3b (executable B, C3, Db)

There would not have to be a single source file in the subdirectories
of config -- the executables are created by just linking the static
libraries B and one of C* and one of D*.

In my opinion, the requirement to have at least one source file may
ease the implementation within CMake but looks artificial from a user
point of view.

Kind regards
Ingolf


More information about the CMake mailing list