Skip to content

Commit

Permalink
CMake: Add a way to use system/bundled 3rdparty libs in bulk
Browse files Browse the repository at this point in the history
[ChangeLog][CMake] Added the configure feature 'force-system-libs'.
Enabling this feature enables every 'system-foolib' feature, and the
system-provided 3rdparty library foo will be used. If the library is not
found, an error is yielded. Also added the analogous
'force-bundled-libs' feature that enforces the usage of bundled 3rdparty
libs.

[ChangeLog][CMake] The configure script gained the options
-force-system-libs and -force-bundled-libs that control the same-named
configure features.

Since we now need a way to mark a feature as "controlling the usage of a
system 3rdparty library", we added the SYSTEM_LIBRARY feature to the
qt_feature command. Patches that add this argument to qt_feature calls
in other repositories follow.

Fixes: QTBUG-96910
Change-Id: I5c411409ea5f3f6425b6bed6fa00d10eddbc366c
Reviewed-by: Alexandru Croitor <[email protected]>
  • Loading branch information
jobor committed Jun 18, 2024
1 parent b1b3af0 commit 08c6de0
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 15 deletions.
51 changes: 47 additions & 4 deletions cmake/QtFeature.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,56 @@ function(qt_feature feature)
qt_feature_normalize_name("${feature}" feature)
set_property(GLOBAL PROPERTY QT_FEATURE_ORIGINAL_NAME_${feature} "${original_name}")

set(no_value_options
PRIVATE
PUBLIC
SYSTEM_LIBRARY
)
set(single_value_options
LABEL
PURPOSE
SECTION
)
set(multi_value_options
AUTODETECT
CONDITION
ENABLE
DISABLE
EMIT_IF
)
cmake_parse_arguments(PARSE_ARGV 1 arg
"PRIVATE;PUBLIC"
"LABEL;PURPOSE;SECTION"
"AUTODETECT;CONDITION;ENABLE;DISABLE;EMIT_IF")
"${no_value_options}" "${single_value_options}" "${multi_value_options}"
)
_qt_internal_validate_all_args_are_parsed(arg)

set(_QT_FEATURE_DEFINITION_${feature} ${ARGN} PARENT_SCOPE)
if(arg_SYSTEM_LIBRARY)
# Enable SYSTEM_LIBRARY features if the 'force-system-libs' feature is enabled.
if(DEFINED arg_ENABLE)
list(PREPEND arg_ENABLE OR)
endif()
list(PREPEND arg_ENABLE QT_FEATURE_force_system_libs)

# Disable SYSTEM_LIBRARY features if the 'force-bundled-libs' feature is enabled.
if(DEFINED arg_DISABLE)
list(PREPEND arg_DISABLE OR)
endif()
list(PREPEND arg_DISABLE QT_FEATURE_force_bundled_libs)

qt_remove_args(forward_args
ARGS_TO_REMOVE ENABLE DISABLE
ALL_ARGS ${no_value_options} ${single_value_options} ${multi_value_options}
ARGS ${ARGN}
)

list(APPEND forward_args
ENABLE ${arg_ENABLE}
DISABLE ${arg_DISABLE}
)
else()
set(forward_args ${ARGN})
endif()

set(_QT_FEATURE_DEFINITION_${feature} ${forward_args} PARENT_SCOPE)

# Register feature for future use:
if (arg_PUBLIC)
Expand Down
2 changes: 2 additions & 0 deletions cmake/configure-cmake-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,5 @@ The following table describes the mapping of configure options to CMake argument
| -disable-deprecated-up-to <hex_version> | -DQT_DISABLE_DEPRECATED_UP_TO=<hex_version> | |
| -mimetype-database-compression <type> | -DINPUT_mimetype_database_compression=<type> | Sets the compression type for mime type database. Supported |
| | | types: gzip, zstd, none. |
| -force-bundled-libs | -DFEATURE_force_bundled_libs=ON | |
| -force-system-libs | -DFEATURE_force_system_libs=ON | |
3 changes: 3 additions & 0 deletions config_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ Component selection:
Qt comes with bundled copies of some 3rd party libraries. These are used
by default if auto-detection of the respective system library fails.

-force-bundled-libs .. Only use bundled 3rd party libraries [no]
-force-system-libs ... Do not use bundled 3rd party libraries [no]

Core options:

-doubleconversion .... Select used double conversion library [system/qt/no]
Expand Down
15 changes: 14 additions & 1 deletion configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,15 @@ qt_feature("alloca" PRIVATE
LABEL "alloca()"
CONDITION QT_FEATURE_alloca_h OR QT_FEATURE_alloca_malloc_h OR TEST_alloca_stdlib_h
)
qt_feature("system-zlib" PRIVATE
qt_feature("force-system-libs" PRIVATE
LABEL "Force the usage of system libraries"
AUTODETECT OFF
)
qt_feature("force-bundled-libs" PRIVATE
LABEL "Force the usage of bundled libraries"
AUTODETECT OFF
)
qt_feature("system-zlib" PRIVATE SYSTEM_LIBRARY
LABEL "Using system zlib"
CONDITION WrapSystemZLIB_FOUND
)
Expand Down Expand Up @@ -1427,6 +1435,11 @@ qt_configure_add_report_entry(
MESSAGE "Building Qt with C++20 is not supported with MSVC 2019."
CONDITION QT_FEATURE_cxx20 AND MSVC AND MSVC_VERSION LESS "1930"
)
qt_configure_add_report_entry(
TYPE ERROR
MESSAGE "You cannot force both system and bundled libraries."
CONDITION QT_FEATURE_force_bundled_libs AND QT_FEATURE_force_system_libs
)
if(WASM)
qt_extra_definition("QT_EMCC_VERSION" "\"${EMCC_VERSION}\"" PUBLIC)
endif()
Expand Down
2 changes: 2 additions & 0 deletions qt_cmdline.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ qt_commandline_option(f16c TYPE boolean)
qt_commandline_option(force-asserts TYPE boolean NAME force_asserts)
qt_commandline_option(force-debug-info TYPE boolean NAME force_debug_info)
qt_commandline_option(force-pkg-config TYPE void NAME pkg-config)
qt_commandline_option(force-bundled-libs TYPE boolean)
qt_commandline_option(force-system-libs TYPE boolean)
qt_commandline_option(framework TYPE boolean)
qt_commandline_option(gc-binaries TYPE boolean NAME gc_binaries)
qt_commandline_option(gdb-index TYPE boolean NAME enable_gdb_index)
Expand Down
6 changes: 3 additions & 3 deletions src/corelib/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ qt_feature("doubleconversion" PRIVATE
LABEL "DoubleConversion"
)
qt_feature_definition("doubleconversion" "QT_NO_DOUBLECONVERSION" NEGATE VALUE "1")
qt_feature("system-doubleconversion" PRIVATE
qt_feature("system-doubleconversion" PRIVATE SYSTEM_LIBRARY
LABEL " Using system DoubleConversion"
CONDITION QT_FEATURE_doubleconversion AND WrapSystemDoubleConversion_FOUND
ENABLE INPUT_doubleconversion STREQUAL 'system'
Expand Down Expand Up @@ -575,7 +575,7 @@ qt_feature("journald" PRIVATE
CONDITION Libsystemd_FOUND
)
# Used by QCryptographicHash for the BLAKE2 hashing algorithms
qt_feature("system-libb2" PRIVATE
qt_feature("system-libb2" PRIVATE SYSTEM_LIBRARY
LABEL "Using system libb2"
CONDITION Libb2_FOUND
ENABLE INPUT_libb2 STREQUAL 'system'
Expand Down Expand Up @@ -615,7 +615,7 @@ qt_feature("pcre2"
DISABLE INPUT_pcre STREQUAL 'no'
)
qt_feature_config("pcre2" QMAKE_PRIVATE_CONFIG)
qt_feature("system-pcre2" PRIVATE
qt_feature("system-pcre2" PRIVATE SYSTEM_LIBRARY
LABEL " Using system PCRE2"
CONDITION WrapSystemPCRE2_FOUND
ENABLE INPUT_pcre STREQUAL 'system'
Expand Down
12 changes: 6 additions & 6 deletions src/gui/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ qt_feature("freetype" PUBLIC PRIVATE
PURPOSE "Supports the FreeType 2 font engine (and its supported font formats)."
)
qt_feature_definition("freetype" "QT_NO_FREETYPE" NEGATE VALUE "1")
qt_feature("system-freetype" PRIVATE
qt_feature("system-freetype" PRIVATE SYSTEM_LIBRARY
LABEL " Using system FreeType"
AUTODETECT NOT MSVC
CONDITION QT_FEATURE_freetype AND WrapSystemFreetype_FOUND
Expand All @@ -704,7 +704,7 @@ qt_feature("harfbuzz" PUBLIC PRIVATE
LABEL "HarfBuzz"
)
qt_feature_definition("harfbuzz" "QT_NO_HARFBUZZ" NEGATE VALUE "1")
qt_feature("system-harfbuzz" PRIVATE
qt_feature("system-harfbuzz" PRIVATE SYSTEM_LIBRARY
LABEL " Using system HarfBuzz"
AUTODETECT NOT APPLE AND NOT WIN32
CONDITION QT_FEATURE_harfbuzz AND WrapSystemHarfbuzz_FOUND
Expand Down Expand Up @@ -904,7 +904,7 @@ qt_feature("jpeg" PRIVATE
DISABLE INPUT_libjpeg STREQUAL 'no'
)
qt_feature_definition("jpeg" "QT_NO_IMAGEFORMAT_JPEG" NEGATE VALUE "1")
qt_feature("system-jpeg" PRIVATE
qt_feature("system-jpeg" PRIVATE SYSTEM_LIBRARY
LABEL " Using system libjpeg"
CONDITION QT_FEATURE_jpeg AND JPEG_FOUND
ENABLE INPUT_libjpeg STREQUAL 'system'
Expand All @@ -915,7 +915,7 @@ qt_feature("png" PRIVATE
DISABLE INPUT_libpng STREQUAL 'no'
)
qt_feature_definition("png" "QT_NO_IMAGEFORMAT_PNG" NEGATE)
qt_feature("system-png" PRIVATE
qt_feature("system-png" PRIVATE SYSTEM_LIBRARY
LABEL " Using system libpng"
AUTODETECT QT_FEATURE_system_zlib
CONDITION QT_FEATURE_png AND WrapSystemPNG_FOUND
Expand Down Expand Up @@ -982,7 +982,7 @@ qt_feature("xcb-sm" PRIVATE
CONDITION QT_FEATURE_sessionmanager AND X11_SM_FOUND
EMIT_IF QT_FEATURE_xcb
)
qt_feature("system-xcb-xinput" PRIVATE
qt_feature("system-xcb-xinput" PRIVATE SYSTEM_LIBRARY
LABEL "Using system-provided xcb-xinput"
AUTODETECT OFF
CONDITION XCB_XINPUT_FOUND
Expand Down Expand Up @@ -1016,7 +1016,7 @@ qt_feature("textmarkdownreader" PUBLIC
ENABLE INPUT_libmd4c STREQUAL 'system' OR INPUT_libmd4c STREQUAL 'qt' OR INPUT_libmd4c STREQUAL 'yes'
DISABLE INPUT_libmd4c STREQUAL 'no'
)
qt_feature("system-textmarkdownreader" PUBLIC
qt_feature("system-textmarkdownreader" PUBLIC SYSTEM_LIBRARY
SECTION "Kernel"
LABEL " Using system libmd4c"
CONDITION QT_FEATURE_textmarkdownreader AND WrapSystemMd4c_FOUND
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/sqldrivers/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ qt_feature("sql-sqlite" PRIVATE
LABEL "SQLite"
CONDITION QT_FEATURE_datestring
)
qt_feature("system-sqlite" PRIVATE
qt_feature("system-sqlite" PRIVATE SYSTEM_LIBRARY
LABEL " Using system provided SQLite"
AUTODETECT OFF
CONDITION QT_FEATURE_sql_sqlite AND SQLite3_FOUND
Expand Down

0 comments on commit 08c6de0

Please sign in to comment.