[CMake] find_package() for static only / shared only

Mario Emmenlauer mario at emmenlauer.de
Wed Mar 21 05:55:38 EDT 2018


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/


More information about the CMake mailing list