Boost logo

Boost :

Subject: Re: [boost] CMake - one more time
From: Klaim - Joël Lamotte (mjklaim_at_[hidden])
Date: 2016-04-23 06:40:43


On 23 April 2016 at 02:36, Paul Fultz II <pfultz2_at_[hidden]> wrote:

>
> > On Apr 22, 2016, at 5:41 PM, Robert Ramey <ramey_at_[hidden]> wrote:
> >
> > On 4/22/16 2:56 PM, Raffi Enficiaud wrote:
> >> Certainly, CMake can do everything with the appropriate effort. But so
> >> far, although I am a CMake user, I do not know how to do this:
> >>
> >> - having the same target name with different target properties: like
> >> set(PROJECT_SRC ....)
> >> add_library(myproject SHARED ${PROJECT_SRC})
> >> add_library(myproject STATIC ${PROJECT_SRC})
> >>
> >> how do you do that? how do you refer to the appropriate variant?
> >
> > I know it's beside the point of your post, but I can't resist.
> >
> > I do this in the following way.
> >
> > a) I set up a cached boolean variable USE_STATIC
> > b) I use the CMake script
> >
> > if(USE_STATIC)
> > add_library(myproject STATIC ${PROJECT_SRC})
> > else()
> > add_library(myproject SHARED ${PROJECT_SRC})
> > elseif()
>
> This is not necessary at all. Cmake provides the `BUILD_SHARED_LIBS`
> variable that can be set to do this same purpose:
>
> https://cmake.org/cmake/help/v3.5/variable/BUILD_SHARED_LIBS.html
>
>
It forces all the targets defined after setting it to use the defined
linking mode.
Most repositories of tools (outside boost at least) provide several
libraries or executables targets.
In my experience I end up using different linking modes for different
libraries which are in the same
repository. Or the target still need to be built and distributed in several
linking modes.
Therefore, I can never use BUILD_SHARED_LIBS because it is not
fined-grained enough.

In my opinion, having multiple targets, one for each linking mode that make
sense for the library usage, works better.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk