diff --git a/CMakeLists.txt b/CMakeLists.txt index c774e297abb..5e38001cc67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,24 +77,24 @@ project(QtBase LANGUAGES CXX C ASM ) -# Should this Qt be static or dynamically linked? -option(BUILD_SHARED_LIBS "Build Qt statically or dynamically" ON) -set(QT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) - -# This variable is also set in Qt6CoreConfigExtras.cmake, but it's not loaded when building -# qtbase. Set it here so qt_add_plugin can compute the proper plugin flavor. -set(QT6_IS_SHARED_LIBS_BUILD ${BUILD_SHARED_LIBS}) - -# BUILD_SHARED_LIBS influences the minimum required CMake version. The value is set either by: -# a cache variable provided on the configure command line -# or set by QtAutoDetect.cmake depending on the platform -# or specified via a toolchain file that is loaded by the project() call -# or set by the option() call above -include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtCMakeVersionHelpers.cmake") -include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtPublicCMakeVersionHelpers.cmake") -qt_internal_check_and_warn_about_unsuitable_cmake_version() - if(NOT QT_BUILD_STANDALONE_TESTS) + # Should this Qt be static or dynamically linked? + option(BUILD_SHARED_LIBS "Build Qt statically or dynamically" ON) + set(QT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) + + # This variable is also set in Qt6CoreConfigExtras.cmake, but it's not loaded when building + # qtbase. Set it here so qt_add_plugin can compute the proper plugin flavor. + set(QT6_IS_SHARED_LIBS_BUILD ${BUILD_SHARED_LIBS}) + + # BUILD_SHARED_LIBS influences the minimum required CMake version. The value is set either by: + # a cache variable provided on the configure command line + # or set by QtAutoDetect.cmake depending on the platform + # or specified via a toolchain file that is loaded by the project() call + # or set by the option() call above + include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtCMakeVersionHelpers.cmake") + include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/QtPublicCMakeVersionHelpers.cmake") + qt_internal_check_and_warn_about_unsuitable_cmake_version() + ## Add some paths to check for cmake modules: list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 57ff117b6d4..e2b49900f71 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -2516,7 +2516,7 @@ function(_qt_internal_add_library target) # This in contrast to CMake which defaults to STATIC. if(NOT arg_STATIC AND NOT arg_SHARED AND NOT arg_MODULE AND NOT arg_INTERFACE AND NOT arg_OBJECT) - if(QT6_IS_SHARED_LIBS_BUILD) + if(BUILD_SHARED_LIBS OR (NOT DEFINED BUILD_SHARED_LIBS AND QT6_IS_SHARED_LIBS_BUILD)) set(type_to_create SHARED) else() set(type_to_create STATIC) diff --git a/src/corelib/doc/src/cmake/qt_add_library.qdoc b/src/corelib/doc/src/cmake/qt_add_library.qdoc index 66336da4b9e..ed6e770516c 100644 --- a/src/corelib/doc/src/cmake/qt_add_library.qdoc +++ b/src/corelib/doc/src/cmake/qt_add_library.qdoc @@ -45,8 +45,9 @@ library type created depends on how Qt was built. If Qt was built statically, a static library will be created. Otherwise, a shared library will be created. Note that this is different to how CMake's \c{add_library()} command works, where the \c BUILD_SHARED_LIBS variable controls the type of -library created. The \c{qt_add_library()} command does not consider -\c BUILD_SHARED_LIBS when deciding the library type. +library created. The \c{qt_add_library()} command considers +\c BUILD_SHARED_LIBS when deciding the library type only if the variable is set +explicitly. Any \c{sources} provided will be passed through to the internal call to \c{add_library()}.