List Archive

Thread

Thread Index

Message

From: Thomas Klausner <tk%giga.or.at@localhost>
To: Michał Janiszewski <janisozaur%gmail.com@localhost>
Subject: Re: vcpkg support/static builds
Date: Tue, 29 Aug 2017 10:28:49 +0200

I've switched to that now.

What I don't like is that there seems to be no sane way to build
shared libraries by default using BUILD_SHARED_LIBS -- if it's not
defined, it defaults to "OFF" for me.

 Thomas

On Mon, Aug 14, 2017 at 04:46:27PM +0200, Michał Janiszewski wrote:
> You don't need to expose it as an option explicitly, as it appears CMake
> already does it internally – like CMAKE_BUILD_TYPE and such.
> The code previously was:
>     add_library(myLib SHARED ${MYLIB_SOURCES})
> and only "SHARED" had to be dropped:
>     add_library(myLib ${MYLIB_SOURCES})
> 
> Now when building, it will pick up whatever current BUILD_SHARED_LIBS is.
> There was no need to add anything else.
> 
> Compare jobs:
> [a] https://travis-ci.org/OpenRCT2/OpenRCT2/jobs/264273471
>     cmake ../ -DBUILD_SHARED_LIBS=ON
>     [ 87%] Linking CXX shared library libopenrct2.so
> 
> [b] https://travis-ci.org/OpenRCT2/OpenRCT2/jobs/264273472
>     cmake ../ -DBUILD_SHARED_LIBS=off
>     [ 87%] Linking CXX static library libopenrct2.a
> 
> How should it best be handled is a bit unclear, have a look at this
> unanswered call to update the docs:
> http://cmake.3232098.n2.nabble.com/Add-BUILD-SHARED-LIBS-as-an-option-td7595236.html
> 
> On Mon, Aug 14, 2017 at 3:46 PM, Thomas Klausner <tk%giga.or.at@localhost> 
> wrote:
> 
> > On Mon, Aug 14, 2017 at 01:02:06PM +0200, Michał Janiszewski wrote:
> > > thanks for the update.
> > > Since I posted the previous message, I've learned about CMake-3.0+
> > standard
> > > option "BUILD_SHARED_LIBS":
> > > https://cmake.org/cmake/help/v3.0/variable/BUILD_SHARED_LIBS.html
> > > This allows user to set upon configuration whether they want a shared or
> > > static library, but only for `add_library` targets. All other things
> > retain
> > > their linking mode.
> > > See it getting used here:
> > > https://github.com/OpenRCT2/OpenRCT2/pull/6145/files
> > > Seeing how both your static and shared paths are the same, perhaps you
> > may
> > > want to investigate using said option.
> >
> > I've looked at the documentation and the example you pasted, but it's
> > not clear to me how to use it.
> >
> > Just removing the type is not enough.
> >
> > Removing it and adding
> >
> > OPTION(BUILD_SHARED_LIBS "build shared libraries" ON)
> >
> > in the main CMakeLists.txt file just builds static libraries.
> >
> > Using
> >
> > SET(BUILD_SHARED_LIBS ON)
> >
> > in the main CMakeLists.txt builds shared libraries, but I can't turn
> > it off by running
> >
> > cmake -DBUILD_SHARED_LIBS:BOOL=OFF ..
> >
> > so I don't really know how this is supposed to work. Any ideas?
> >  Thomas
> >
> 
> 
> 
> -- 
> Michal Janiszewski

Made by MHonArc.