List Archive

Thread

Thread Index

Message

From: Michał Janiszewski <janisozaur%gmail.com@localhost>
To: Thomas Klausner <tk%giga.or.at@localhost>
Subject: Re: vcpkg support/static builds
Date: Mon, 14 Aug 2017 16:46:27 +0200

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.