From 70c721befb52c2b4b718656a80df00f50dc689c7 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 16 Nov 2022 10:28:45 +0100 Subject: AutoMoc: Don't initialize already defined CMAKE_AUTOMOC_ variables Setting the variables CMAKE_AUTOGEN_ORIGIN_DEPENDS, CMAKE_AUTOMOC_COMPILER_PREDEFINES, and CMAKE_AUTOMOC_MACRO_NAMES on the cmake command line did not work as expected. CMakeGenericSystem.cmake initialized these variables even if they were defined by the user. This led to the confusing situation where the cache variant of a variable had one value (defined on the command line) and the non-cache variant of a variable had a different value (defined in CMakeGenericSystem.cmake). Fix this by checking whether the variables are defined before setting their default values. Fixes: #24069 --- Modules/CMakeGenericSystem.cmake | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake index e2925dc..77c1780 100644 --- a/Modules/CMakeGenericSystem.cmake +++ b/Modules/CMakeGenericSystem.cmake @@ -30,12 +30,18 @@ set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a") # LINK_LIBRARY_OVERRIDE_ target properties set(CMAKE_LINK_LIBRARY_USING_DEFAULT_SUPPORTED TRUE) -set(CMAKE_AUTOGEN_ORIGIN_DEPENDS ON) -set(CMAKE_AUTOMOC_COMPILER_PREDEFINES ON) +if(NOT DEFINED CMAKE_AUTOGEN_ORIGIN_DEPENDS) + set(CMAKE_AUTOGEN_ORIGIN_DEPENDS ON) +endif() +if(NOT DEFINED CMAKE_AUTOMOC_COMPILER_PREDEFINES) + set(CMAKE_AUTOMOC_COMPILER_PREDEFINES ON) +endif() if(NOT DEFINED CMAKE_AUTOMOC_PATH_PREFIX) set(CMAKE_AUTOMOC_PATH_PREFIX OFF) endif() -set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT") +if(NOT DEFINED CMAKE_AUTOMOC_MACRO_NAMES) + set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT") +endif() # basically all general purpose OSs support shared libs set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) -- cgit v0.12