MantisBT - CMake
View Issue Details
0014979CMake(No Category)public2014-06-17 20:002015-11-02 09:13
Nico Schlömer 
Stephen Kelly 
lowfeaturehave not tried
closedduplicate 
 
 
0014979: build both static and dynamic with cmake arguments
Right now, to build both the static and the dynamic version of a library, two `add_library` calls have to be present in the respective CMakeLists.txt file, e.g.,
```
add_library(MyLib SHARED source1.c source2.c)
add_library(MyLibStatic STATIC source1.c source2.c)
```
To control this from the command line, one has the switch `BUILD_SHARED_LIBS` which is set to either on or off.

In Debian -- and possibly other distributors too --, you would like to build *both* shared and dynamic versions of all libraries, and that without modifying the software sources. The first option (patch the software to contain both `add_library(... SHARED ...)` and `add_library(... STATIC ...)`) is hence not an option.

It seems that configuring the software twice, with BUILD_SHARED_LIBS set to ON and OFF, respectively, is the only option.

Is this what CMake developers would recommend, too, or would there be a smarter way of handling things?
No tags attached.
duplicate of 0004222closed Bill Hoffman ADD_LIBRARY should support simultaneous STATIC | SHARED builds 
Issue History
2014-06-17 20:00Nico SchlömerNew Issue
2014-06-19 11:51Brad KingNote Added: 0036225
2014-06-19 16:17Nico SchlömerNote Added: 0036230
2014-06-23 10:16Brad KingNote Added: 0036232
2015-04-13 13:53Stephen KellyRelationship addedduplicate of 0004222
2015-04-13 13:53Stephen KellyStatusnew => resolved
2015-04-13 13:53Stephen KellyResolutionopen => duplicate
2015-04-13 13:53Stephen KellyAssigned To => Stephen Kelly
2015-11-02 09:13Robert MaynardNote Added: 0039768
2015-11-02 09:13Robert MaynardStatusresolved => closed

Notes
(0036225)
Brad King   
2014-06-19 11:51   
Switching on BUILD_SHARED_LIBS is the only general-purpose option. Even that will only work if the project code was written without explicit SHARED or STATIC options to its add_library calls. Otherwise there is no way to do this except with support from the project code.
(0036230)
Nico Schlömer   
2014-06-19 16:17   
Hm right; BUILD_SHARED_LIBS is only meaningful if SHARED or STATIC aren't explicitly set. I suppose the rationale behind this is:
```
The code author, not the builder (distributor) decides if shared and/or static make sense for the project.
```
Is this correct? If so, could you give a little more background on this?
(0036232)
Brad King   
2014-06-23 10:16   
Re 0014979:0036230: That is correct.

Some projects support BUILD_SHARED_LIBS. Some explicitly specify the type of every library. Some only support one type. Some add both types themselves. CMake does not mandate any convention.
(0039768)
Robert Maynard   
2015-11-02 09:13   
Closing resolved issues that have not been updated in more than 4 months.