List Archive


Thread Index


From: Michał Janiszewski <>
To: Thomas Klausner <>
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:
    cmake ../ -DBUILD_SHARED_LIBS=ON
    [ 87%] Linking CXX shared library

    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:

On Mon, Aug 14, 2017 at 3:46 PM, Thomas Klausner <> 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
> 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:
> 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.



in the main CMakeLists.txt builds shared libraries, but I can't turn
it off by running


so I don't really know how this is supposed to work. Any ideas?

Michal Janiszewski

Made by MHonArc.