Commit 4c33b305 authored by Jörg Bornemann's avatar Jörg Bornemann Committed by Brad King
Browse files

Autogen: Turn off moc path prefix generation by default

Change the default value of `CMAKE_AUTOMOC_PATH_PREFIX` to `OFF` to
restore compatibility with behavior of CMake 3.15 and below.

C++ source files that are generated by Qt's meta object compiler (moc)
include the header file that was passed as input argument to moc. This
is usually a path relative to the source directory, for example

    #include "../../source/dir/myobject.h"

That is problematic for reproducible builds as described in #18815.
To cope with that, the target property AUTOMOC_PATH_PREFIX was
introduced in CMake 3.16 by commit d018d27c (Autogen: Add moc path
prefix generation (AUTOMOC_PATH_PREFIX), 2019-09-13, v3.16.0-rc1~94^2~4).
The property is default-initialized from the variable
`CMAKE_AUTOMOC_PATH_PREFIX`, which defaults to `ON`.

If this property is ON, and myobject.h is located in an include
directory of the target, moc-generated C++ files include the file
without the "path prefix":

    #include "myobject.h"

This behavior, however, can break projects that have equally named
header files in different include directories.  As "not breaking
existing projects" trumps "have reproducible builds by default" we
change the default of `CMAKE_AUTOMOC_PATH_PREFIX` to `OFF`.

Also, it is now possible to pass `-DCMAKE_AUTOMOC_PATH_PREFIX=ON` on the
CMake command line.  Before, it was overridden in `CMakeGenericSystem`.

Fixes: #20598
Issue: #18815
parent 39c6ac51
......@@ -13,7 +13,7 @@ the ``-p`` path prefix option. ``moc`` usually generates a
relative include path in that case.
:prop_tgt:`AUTOMOC_PATH_PREFIX` is initialized from the variable
:variable:`CMAKE_AUTOMOC_PATH_PREFIX`, which is ``ON`` by default.
:variable:`CMAKE_AUTOMOC_PATH_PREFIX`, which is ``OFF`` by default.
See the :manual:`cmake-qt(7)` manual for more information on using CMake
with Qt.
......@@ -24,8 +24,7 @@ Reproducible builds
For reproducible builds is is recommended to keep headers that are ``moc``
compiled in one of the target
:command:`include directories <target_include_directories>` and set
:prop_tgt:`AUTOMOC_PATH_PREFIX` to ``ON`` (which is the default). This ensures
that
:prop_tgt:`AUTOMOC_PATH_PREFIX` to ``ON``. This ensures that:
- ``moc`` output files are identical on different build setups,
- ``moc`` output files will compile correctly when the source and/or
......
......@@ -8,4 +8,4 @@ This variable is used to initialize the :prop_tgt:`AUTOMOC_PATH_PREFIX`
property on all the targets. See that target property for additional
information.
The default value is ``ON``.
The default value is ``OFF``.
......@@ -26,7 +26,9 @@ set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
set(CMAKE_AUTOGEN_ORIGIN_DEPENDS ON)
set(CMAKE_AUTOMOC_COMPILER_PREDEFINES ON)
set(CMAKE_AUTOMOC_PATH_PREFIX ON)
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")
# basically all general purpose OSs support shared libs
......
......@@ -61,6 +61,7 @@ macro(buildMocInclude sourceDir binaryDir)
"${sourceDir}"
MocInclude
CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
"-DCMAKE_AUTOMOC_PATH_PREFIX=ON"
"-DCMAKE_AUTOGEN_VERBOSE=${CMAKE_AUTOGEN_VERBOSE}"
"-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
OUTPUT_VARIABLE output
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment