Skip to content

Commit

Permalink
CMake: Add a way to mark modules as "load the private module too"
Browse files Browse the repository at this point in the history
Add FIND_PRIVATE_MODULE argument to qt_internal_add_module. If this
argument is set for Qt6Foo, then find_package(Qt6Foo) will also
find_package(Qt6FooPrivate). This should only be necessary in
exceptional cases like Qt6Qml where Qt6QmlPrivate is used
unconditionally.

Task-number: QTBUG-87776
Change-Id: I8d6fbd0624c0008fc42294ff2d2ed36848963508
Reviewed-by: Alexandru Croitor <[email protected]>
Reviewed-by: Alexey Edelev <[email protected]>
  • Loading branch information
jobor committed Jan 28, 2025
1 parent befce75 commit 61c6e90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmake/QtModuleConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (NOT QT_NO_CREATE_TARGETS AND @INSTALL_CMAKE_NAMESPACE@@target@_FOUND)
endif()

# Find the private module counterpart.
set(__qt_@target@_always_load_private_module OFF)
set(__qt_@target@_always_load_private_module @always_load_private_module@)
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@[email protected]" OPTIONAL)
if (@INSTALL_CMAKE_NAMESPACE@@target@_FOUND
AND NOT @INSTALL_CMAKE_NAMESPACE@@target_private@_FOUND
Expand Down
17 changes: 17 additions & 0 deletions cmake/QtModuleHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ macro(qt_internal_get_internal_add_module_keywords option_args single_args multi
set(${option_args}
STATIC
EXCEPTIONS
FIND_PRIVATE_MODULE
INTERNAL_MODULE
HEADER_MODULE
DISABLE_TOOLS_EXPORT
Expand Down Expand Up @@ -131,6 +132,9 @@ endfunction()
# ignored by syncqt. The specifying this directory allows to skip the parsing of the whole
# CMAKE_CURRENT_SOURCE_DIR for the header files that needs to be synced and only parse the
# single subdirectory, that meanwhile can be outside the CMAKE_CURRENT_SOURCE_DIR tree.
#
# FIND_PRIVATE_MODULE
# A call to find_package(Qt6Foo) will imply a call to find_package(Qt6FooPrivate).
function(qt_internal_add_module target)
qt_internal_get_internal_add_module_keywords(
module_option_args
Expand Down Expand Up @@ -796,8 +800,16 @@ set(QT_ALLOW_MISSING_TOOLS_PACKAGES TRUE)")
else()
set(write_basic_module_package_args "")
endif()

if(arg_FIND_PRIVATE_MODULE)
set(write_basic_public_module_package_args FIND_PRIVATE_MODULE)
else()
set(write_basic_public_module_package_args "")
endif()

qt_internal_write_basic_module_package("${target}" "${target_private}"
${write_basic_module_package_args}
${write_basic_public_module_package_args}
CONFIG_BUILD_DIR ${config_build_dir}
CONFIG_INSTALL_DIR ${config_install_dir}
)
Expand Down Expand Up @@ -991,6 +1003,7 @@ endfunction()
# Otherwise write its public counterpart.
function(qt_internal_write_basic_module_package target target_private)
set(no_value_options
FIND_PRIVATE_MODULE
IS_STATIC_LIB
PRIVATE
)
Expand All @@ -1003,12 +1016,16 @@ function(qt_internal_write_basic_module_package target target_private)
"${no_value_options}" "${single_value_options}" "${multi_value_options}"
)

set(always_load_private_module OFF)
if(arg_PRIVATE)
set(package_name "${INSTALL_CMAKE_NAMESPACE}${target_private}")
set(module_config_input_file "QtModuleConfigPrivate.cmake.in")
else()
set(package_name "${INSTALL_CMAKE_NAMESPACE}${target}")
set(module_config_input_file "QtModuleConfig.cmake.in")
if(arg_FIND_PRIVATE_MODULE)
set(always_load_private_module ON)
endif()
endif()

if(arg_IS_STATIC_LIB AND NOT arg_PRIVATE AND CMAKE_VERSION VERSION_LESS "3.26")
Expand Down

0 comments on commit 61c6e90

Please sign in to comment.