Search code examples
qtcmakestatic-linking

Detect static Qt in cmake


How can I detect if the used version of Qt is statically built in a cmake project?

My goal is to make my project files independent from the version of Qt that is used to build it, and there are a few places where I need to differ between dynamic and static builds.


Solution

  • It works like for every other library in cmake, see here:

    find_package(Qt5 COMPONENTS Core REQUIRED)
    get_target_property(MY_QT_TARGET_TYPE Qt5::Core TYPE)
    if(MY_QT_TARGET_TYPE STREQUAL STATIC_LIBRARY)
        message("Qt was built as a static library!")
    endif()