diff options
author | Alexey Edelev <alexey.edelev@qt.io> | 2023-07-06 21:11:58 +0200 |
---|---|---|
committer | Alexey Edelev <alexey.edelev@qt.io> | 2023-08-04 14:36:50 +0200 |
commit | 674134f08df0aa2d5863f3844b58d62368261174 (patch) | |
tree | 18658271a41e52f127c97aede5021449e96aa118 | |
parent | ce8874fc3b0bab2066080315c8774b30c038862c (diff) |
Consider BUILD_SHARED_LIBS when adding libraries using _qt_internal_add_library
It does look safe to consider the value of BUILD_SHARED_LIBS in
_qt_internal_add_library. Current behavior might confuse users that
specify BUILD_SHARED_LIBS explicitly but get the library types
according to Qt build type.
[ChangeLog][CMake] qt6_add_library now considers the value of the
BUILD_SHARED_LIBS variable. If the variable is DEFINED it has
higher priority than the library type detecting logic in
qt6_add_library when adding the library targets.
Change-Id: I1c40e887c4e481424a596c870a8ff2784b08fcbb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | CMakeLists.txt | 34 | ||||
-rw-r--r-- | src/corelib/Qt6CoreMacros.cmake | 2 | ||||
-rw-r--r-- | src/corelib/doc/src/cmake/qt_add_library.qdoc | 5 |
3 files changed, 21 insertions, 20 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c774e297ab..5e38001cc6 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 57ff117b6d..e2b49900f7 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 66336da4b9..ed6e770516 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()}. |