[CMake] find_package() for static only / shared only
CHEVRIER, Marc
marc.chevrier at sap.com
Thu Mar 22 07:22:15 EDT 2018
Yes. Seems OK.
For Windows, if libraries are all your owns, you can manage this by relaying on a specific prefix for static libraries.
A commonly adopted naming is to add prefix "lib" for static libraries.
Now, if you add to rely on external libraries, I don't see any general solution.
On 22/03/2018 12:15, "Mario Emmenlauer" <mario at emmenlauer.de> wrote:
Dear Marc,
this is a pretty neat idea! Let me quickly recapitulate: the
library prefixes and suffixes for multiple platforms are:
| static | shared
| prefix | suffix | prefix | suffix
---------------------------------------------------------------------
Linux | lib | .a | lib | .so
MacOSX | lib | .a | lib | .dylib
MinGW | lib | .a | lib | .dll.a/.dll
MSVC | - | .lib | - | .lib/.dll
Is that about correct? So it should work mostly everywhere with the note-
worthy exception of MSVC, where the shared import library is not easily
discriminated from the static library.
Is there a good solution for MSVC too?
All the best,
Mario
On 22.03.2018 09:41, CHEVRIER, Marc wrote:
> Another possibility is to customize the variable CMAKE_FIND_LIBRARY_SUFFIXES.
> For example, on linux:
> * shared only: set (CMAKE_FIND_LIBRARY_SUFFIXES ".so")
> * static only: set (CMAKE_FIND_LIBRARY_SUFFIXES ".a")
>
> On Windows, it is more problematic because static and "import" shared libraries have same extension: ".lib".
> But, if, by chance, you have different prefixes to distinguish them, you can rely on variable CMAKE_FIND_LIBRARY_PREFIXES to manage that.
>
>
> On 21/03/2018 10:56, "CMake on behalf of Mario Emmenlauer" <cmake-bounces at cmake.org on behalf of mario at emmenlauer.de> wrote:
>
>
> I've googled this issue for a while now but found only few
> references (1,2) and no solution. I'd like to enforce that
> find_package() will only accept static or shared libraries.
> I would then set this option based on BUILD_SHARED_LIBS=(ON|OFF).
>
> I.e. I'd love to have something like:
> if(BUILD_SHARED_LIBS)
> BUILD_TYPE="SHARED"
> else()
> BUILD_TYPE="STATIC"
> endif()
> find_package(XXX ${BUILD_TYPE})
> find_package(YYY ${BUILD_TYPE})
> find_package(ZZZ ${BUILD_TYPE})
> ...
>
>
> It seems that this does not exist? I could also not find a
> good workaround. The best I can find is to use 'NAMES' and
> add the static or shared library names manually.
>
> This is not very suitable, because I have a project with more
> than 30 dependencies. The project should either build (fully)
> static or (fully) shared. I can not easily maintain lists of
> 30 static and shared library names on several platforms.
>
> Is there a solution or good workaround?
>
> All the best,
>
> Mario Emmenlauer
>
>
> (1) https://cmake.org/pipermail/cmake/2012-September/052059.html
> (2) https://cmake.org/pipermail/cmake/2010-December/041326.html
>
>
> --
> BioDataAnalysis GmbH, Mario Emmenlauer Tel. Buero: +49-89-74677203
> Balanstr. 43 mailto: memmenlauer * biodataanalysis.de
> D-81669 München http://www.biodataanalysis.de/
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>
>
Viele Gruesse,
Mario Emmenlauer
--
BioDataAnalysis GmbH, Mario Emmenlauer Tel. Buero: +49-89-74677203
Balanstr. 43 mailto: memmenlauer * biodataanalysis.de
D-81669 München http://www.biodataanalysis.de/
More information about the CMake
mailing list