do not override initial AUTOMOC_MACRO_NAMES value
The CMake documentation states that the AUTOMOC_MACRO_NAMES property of a target is initially set to CMAKE_AUTOMOC_MACRO_NAMES, so do not override it in qt_enable_autogen_tool. Instead, append the extra macro names not set by the upstream CMake CMAKE_AUTOMOC_MACRO_NAMES variable. Add a test for this. Change-Id: Ib0ef28e7fc9c5f9559150bbe73ffdeac767adc82 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
4f05ffeb41
commit
26f0eaba52
@ -39,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)
|
||||
|
@ -26,7 +26,8 @@ if (NOT QT_NO_CREATE_TARGETS)
|
||||
set_property(TARGET ${__qt_core_target} PROPERTY INTERFACE_COMPILE_FEATURES cxx_decltype)
|
||||
endif()
|
||||
|
||||
list(APPEND CMAKE_AUTOMOC_MACRO_NAMES Q_OBJECT Q_GADGET Q_GADGET_EXPORT Q_NAMESPACE Q_NAMESPACE_EXPORT)
|
||||
# note: all the other AUTOMOC_MACRO_NAMES are already set by upstream CMake
|
||||
list(APPEND CMAKE_AUTOMOC_MACRO_NAMES Q_GADGET_EXPORT Q_ENUM_NS)
|
||||
list(REMOVE_DUPLICATES CMAKE_AUTOMOC_MACRO_NAMES)
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/QtInstallPaths.cmake")
|
||||
|
@ -14,7 +14,14 @@ qt_generate_moc(main_gen_test.cpp
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc"
|
||||
TARGET QtGenerateMacroTest
|
||||
)
|
||||
list(APPEND CMAKE_AUTOMOC_MACRO_NAMES MySpecialMacro)
|
||||
add_executable(QtGenerateMacroTest main_gen_test.cpp "${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc")
|
||||
get_target_property(current_macros QtGenerateMacroTest AUTOMOC_MACRO_NAMES)
|
||||
|
||||
if(NOT "${CMAKE_AUTOMOC_MACRO_NAMES}" STREQUAL "${current_macros}")
|
||||
message(FATAL_ERROR "Expected ${CMAKE_AUTOMOC_MACRO_NAMES} but received ${current_macros}")
|
||||
endif()
|
||||
|
||||
target_include_directories(QtGenerateMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface")
|
||||
target_link_libraries(QtGenerateMacroTest PRIVATE Qt6::Core)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user