cmake: Unify the set flags between AUTOMOC and qt_wrap_cpp

For AUTOMOC, we were missing the compiler flavor flag, as well as the
WIN32 define. While the latter has not caused any known issues yet, the
former is rather problematic for implementing __has_include in moc.

Note that this only applies in the case where the AUTOMOC flags are set
by us in a qt_ function like qt_add_excutable. Plain add_executable
won't benefit from it, but we already mention that Qt targets should not
use plain CMake functions.

This change is (indirectly) tested by the commit adding __has_include
support for moc.

Task-number: QTBUG-136097
Change-Id: Ie2beb08a44a3a67e3bc363d9c1ba93b7d6a49133
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit 246b43d581a17dd9578553b0569b7fb2f2da8e85)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 806e4e619c991f8827db0b96bb5042722626342d)
(cherry picked from commit 3acde30a3e72f8fece3c51c6e893894809e02893)
This commit is contained in:
Fabian Kosmale
2025-06-16 15:40:54 +00:00
committed by Qt Cherry-pick Bot
parent 376a45225f
commit 07a2b4e032
4 changed files with 29 additions and 9 deletions
+3
View File
@@ -166,6 +166,9 @@ function(qt_manual_moc result)
set(metatypes_byproducts "${outfile}.json")
endif()
_qt_internal_get_moc_compiler_flavor_flags(flavor_flags)
list(APPEND moc_parameters ${flavor_flags})
if (TARGET Qt::Platform)
get_target_property(_abi_tag Qt::Platform qt_libcpp_abi_tag)
if (_abi_tag)
+12
View File
@@ -869,3 +869,15 @@ function(qt_set01 result)
set("${result}" 0 PARENT_SCOPE)
endif()
endfunction()
function(_qt_internal_get_moc_compiler_flavor_flags out_var)
set(flags "")
if(WIN32)
list(APPEND flags -DWIN32)
endif()
if(MSVC)
list(APPEND flags --compiler-flavor=msvc)
endif()
set(${out_var} "${flags}" PARENT_SCOPE)
endfunction()
+3 -1
View File
@@ -194,9 +194,11 @@ function(qt_internal_extend_target target)
${private_visibility_option} ${arg_LINK_OPTIONS})
if(NOT is_interface_lib)
_qt_internal_get_moc_compiler_flavor_flags(flavor_flags)
set_property(TARGET "${target}" APPEND PROPERTY
AUTOMOC_MOC_OPTIONS "${arg_MOC_OPTIONS}"
AUTOMOC_MOC_OPTIONS "${arg_MOC_OPTIONS}" ${flavor_flags}
)
# Plugin types associated to a module
if(NOT "x${arg_PLUGIN_TYPES}" STREQUAL "x")
qt_internal_add_plugin_types("${target}" "${arg_PLUGIN_TYPES}")
+11 -8
View File
@@ -67,12 +67,8 @@ macro(_qt_internal_get_moc_flags _moc_flags)
set(${_moc_flags} ${${_moc_flags}} "-D${_current}")
endforeach()
if(WIN32)
set(${_moc_flags} ${${_moc_flags}} -DWIN32)
endif()
if (MSVC)
set(${_moc_flags} ${${_moc_flags}} --compiler-flavor=msvc)
endif()
_qt_internal_get_moc_compiler_flavor_flags(flavor_flags)
set(${_moc_flags} ${${_moc_flags}} ${flavor_flags})
endmacro()
# helper macro to set up a moc rule
@@ -96,6 +92,9 @@ function(_qt_internal_create_moc_command infile outfile moc_flags moc_options
set(${out_json_file} "${extra_output_files}" PARENT_SCOPE)
endif()
_qt_internal_get_moc_compiler_flavor_flags(flavor_flags)
list(APPEND _moc_parameters ${flavor_flags})
if(moc_target)
set(_moc_parameters_file ${_moc_parameters_file}$<$<BOOL:$<CONFIG>>:_$<CONFIG>>)
set(targetincludes "$<TARGET_PROPERTY:${moc_target},INCLUDE_DIRECTORIES>")
@@ -839,12 +838,16 @@ function(qt6_finalize_target target)
endif()
endif()
get_target_property(is_immediately_finalized "${target}" _qt_is_immediately_finalized)
get_target_property(uses_automoc ${target} AUTOMOC)
if(uses_automoc)
_qt_internal_get_moc_compiler_flavor_flags(flavor_flags)
set_property(TARGET "${target}" APPEND PROPERTY AUTOMOC_MOC_OPTIONS ${flavor_flags})
endif()
if(target_type STREQUAL "SHARED_LIBRARY" OR
target_type STREQUAL "STATIC_LIBRARY" OR
target_type STREQUAL "MODULE_LIBRARY" OR
target_type STREQUAL "OBJECT_LIBRARY")
get_target_property(is_immediately_finalized "${target}" _qt_is_immediately_finalized)
get_target_property(uses_automoc ${target} AUTOMOC)
if(uses_automoc AND NOT is_immediately_finalized)
qt6_extract_metatypes(${target})
endif()