diff options
Diffstat (limited to 'cmake/QtAutogenHelpers.cmake')
-rw-r--r-- | cmake/QtAutogenHelpers.cmake | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/cmake/QtAutogenHelpers.cmake b/cmake/QtAutogenHelpers.cmake index a583af568f..029a709e90 100644 --- a/cmake/QtAutogenHelpers.cmake +++ b/cmake/QtAutogenHelpers.cmake @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + # Initial autogen setup for a target to specify certain CMake properties which are common # to all autogen tools. Also enable AUTOMOC by default. function(qt_autogen_tools_initial_setup target) @@ -36,8 +39,7 @@ function(qt_enable_autogen_tool target tool enable) # that the moc scanner has to look for. Inform the CMake moc scanner about it. if(tool STREQUAL "moc" AND enable) set_target_properties("${target}" PROPERTIES - AUTOMOC_MACRO_NAMES "Q_OBJECT;Q_GADGET;Q_GADGET_EXPORT;Q_NAMESPACE;Q_NAMESPACE_EXPORT;Q_ENUM_NS") - + AUTOMOC_MACRO_NAMES "${CMAKE_AUTOMOC_MACRO_NAMES};Q_ENUM_NS;Q_GADGET_EXPORT") if (TARGET Qt::Platform) get_target_property(_abi_tag Qt::Platform qt_libcpp_abi_tag) if (_abi_tag) @@ -58,7 +60,8 @@ endfunction() # This function adds or removes additional AUTOGEN tools to a target: AUTOMOC/UIC/RCC function(qt_autogen_tools target) - qt_parse_all_arguments(arg "qt_autogen_tools" "" "" "${__default_private_args}" ${ARGN}) + cmake_parse_arguments(PARSE_ARGV 1 arg "" "" "${__default_private_args}") + _qt_internal_validate_all_args_are_parsed(arg) if(arg_ENABLE_AUTOGEN_TOOLS) foreach(tool ${arg_ENABLE_AUTOGEN_TOOLS}) @@ -75,14 +78,23 @@ endfunction() # Complete manual moc invocation with full control. # Use AUTOMOC whenever possible. -# INCLUDE_DIRECTORIES specifies a list of include directories used by 'moc'. -# INCLUDE_DIRECTORY_TARGETS specifies a list of targets to extract the INTERFACE_INCLUDE_DIRECTORIES -# property and use it as the 'moc' include directories. +# Multi-value Arguments: +# INCLUDE_DIRECTORIES +# Specifies a list of include directories used by 'moc'. +# INCLUDE_DIRECTORY_TARGETS +# Specifies a list of targets to extract the INTERFACE_INCLUDE_DIRECTORIES +# property and use it as the 'moc' include directories.(Deprecated use TARGETS instead) +# DEFINITIONS +# List of the definitions that should be added to the moc command line arguments. +# Supports the syntax both with and without the prepending '-D'. +# TARGETS +# The list of targets that will be used to collect the INTERFACE_INCLUDE_DIRECTORIES, +# INCLUDE_DIRECTORIES, and COMPILE_DEFINITIONS properties. function(qt_manual_moc result) cmake_parse_arguments(arg "" "OUTPUT_MOC_JSON_FILES" - "FLAGS;INCLUDE_DIRECTORIES;INCLUDE_DIRECTORY_TARGETS" + "FLAGS;INCLUDE_DIRECTORIES;INCLUDE_DIRECTORY_TARGETS;DEFINITIONS;TARGETS" ${ARGN}) set(moc_files) set(metatypes_json_list) @@ -91,7 +103,7 @@ function(qt_manual_moc result) "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" outfile) list(APPEND moc_files "${outfile}") - set(moc_parameters_file "${outfile}_parameters$<$<BOOL:$<CONFIGURATION>>:_$<CONFIGURATION>>") + set(moc_parameters_file "${outfile}_parameters$<$<BOOL:$<CONFIG>>:_$<CONFIG>>") set(moc_parameters ${arg_FLAGS} -o "${outfile}" "${infile}") foreach(dir IN ITEMS ${arg_INCLUDE_DIRECTORIES}) @@ -99,7 +111,7 @@ function(qt_manual_moc result) "-I\n${dir}") endforeach() - foreach(dep IN ITEMS ${arg_INCLUDE_DIRECTORY_TARGETS}) + foreach(dep IN LISTS arg_INCLUDE_DIRECTORY_TARGETS arg_TARGETS) set(include_expr "$<TARGET_PROPERTY:${dep},INTERFACE_INCLUDE_DIRECTORIES>") list(APPEND moc_parameters "$<$<BOOL:${include_expr}>:-I\n$<JOIN:${include_expr},\n-I\n>>") @@ -125,6 +137,30 @@ function(qt_manual_moc result) endif() endforeach() + foreach(dep IN LISTS arg_TARGETS) + set(include_property_expr + "$<TARGET_GENEX_EVAL:${dep},$<TARGET_PROPERTY:${dep},INCLUDE_DIRECTORIES>>") + list(APPEND moc_parameters + "$<$<BOOL:${include_property_expr}>:-I\n$<JOIN:${include_property_expr},\n-I\n>>") + + set(defines_property_expr + "$<TARGET_GENEX_EVAL:${dep},$<TARGET_PROPERTY:${dep},COMPILE_DEFINITIONS>>") + set(defines_with_d "$<FILTER:${defines_property_expr},INCLUDE,^-D>") + set(defines_without_d "$<FILTER:${defines_property_expr},EXCLUDE,^-D>") + list(APPEND moc_parameters + "$<$<BOOL:${defines_with_d}>:$<JOIN:${defines_with_d},\n>>") + list(APPEND moc_parameters + "$<$<BOOL:${defines_without_d}>:-D\n$<JOIN:${defines_without_d},\n-D\n>>") + endforeach() + + foreach(def IN LISTS arg_DEFINITIONS) + if(NOT def MATCHES "^-D") + list(APPEND moc_parameters "-D\n${def}") + else() + list(APPEND moc_parameters "${def}") + endif() + endforeach() + set(metatypes_byproducts) if (arg_OUTPUT_MOC_JSON_FILES) set(moc_json_file "${outfile}.json") |