Commit dca5df16 authored by Sebastian Holtermann's avatar Sebastian Holtermann

Autogen: Process GENERATED files. Add CMP0071.

This lets AUTOMOC and AUTOUIC process GENERATED files which
used to be ignored before.
A new policy CMP0071 ensures that the old behavior of ignoring
GENERATED files is enabled when the CMake compatibility version
CMAKE_MINIMUM_REQUIRED is < 3.10.

Closes #16186
parent ec049641
......@@ -57,6 +57,7 @@ Policies Introduced by CMake 3.10
.. toctree::
:maxdepth: 1
CMP0071: Let AUTOMOC and AUTOUIC process GENERATED files. </policy/CMP0071>
CMP0070: Define file(GENERATE) behavior for relative paths. </policy/CMP0070>
Policies Introduced by CMake 3.9
......
CMP0071
-------
Let :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` process
:prop_sf:`GENERATED` files.
CMake 3.10 and newer process regular *and* :prop_sf:`GENERATED` source files
in :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`.
In CMake 3.9 and lower, only regular source files were processed in
:prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`,
:prop_sf:`GENERATED` source files were ignored.
This policy affects how :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` process
source files that are :prop_sf:`GENERATED`.
The ``OLD`` behavior for this policy is to *ignore* :prop_sf:`GENERATED`
source files in :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`.
The ``NEW`` behavior for this policy is to process :prop_sf:`GENERATED`
source files in :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` just like regular
source files.
.. note::
To exclude source files from :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`
processing, the boolean source file properties
:prop_sf:`SKIP_AUTOMOC`, :prop_sf:`SKIP_AUTOUIC` and :prop_sf:`SKIP_AUTOGEN`
can be set accordingly.
This policy was introduced in CMake version 3.10. CMake version
|release| warns when the policy is not set and uses ``OLD`` behavior.
Use the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW``
explicitly.
.. include:: DEPRECATED.txt
autogen-generated-files
-----------------------
* When using :prop_tgt:`AUTOMOC` or :prop_tgt:`AUTOUIC`,
source files that are :prop_sf:`GENERATED` will be processed as well.
They were ignored by :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`
in earlier releases.
See policy :policy:`CMP0071`.
......@@ -209,7 +209,9 @@ class cmMakefile;
cmPolicies::WARN) \
SELECT(POLICY, CMP0070, \
"Define file(GENERATE) behavior for relative paths.", 3, 10, 0, \
cmPolicies::WARN)
cmPolicies::WARN) \
SELECT(POLICY, CMP0071, "Let AUTOMOC and AUTOUIC process GENERATED files.", \
3, 10, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \
......
......@@ -11,6 +11,7 @@
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmOutputConverter.h"
#include "cmPolicies.h"
#include "cmSourceFile.h"
#include "cmSourceGroup.h"
#include "cmState.h"
......@@ -28,6 +29,7 @@
#include <algorithm>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
......@@ -290,6 +292,8 @@ static void AcquireScanFiles(cmGeneratorTarget const* target,
{
const bool mocTarget = target->GetPropertyAsBool("AUTOMOC");
const bool uicTarget = target->GetPropertyAsBool("AUTOUIC");
const cmPolicies::PolicyStatus CMP0071_status =
target->Makefile->GetPolicyStatus(cmPolicies::CMP0071);
std::vector<cmSourceFile*> srcFiles;
target->GetConfigCommonSourceFiles(srcFiles);
......@@ -298,24 +302,46 @@ static void AcquireScanFiles(cmGeneratorTarget const* target,
cmSourceFile* sf = *fileIt;
const cmSystemTools::FileFormat fileType =
cmSystemTools::GetFileFormat(sf->GetExtension().c_str());
if (!(fileType == cmSystemTools::CXX_FILE_FORMAT) &&
!(fileType == cmSystemTools::HEADER_FILE_FORMAT)) {
continue;
}
if (PropertyEnabled(sf, "GENERATED") &&
!target->GetPropertyAsBool("__UNDOCUMENTED_AUTOGEN_GENERATED_FILES")) {
// FIXME: Add a policy whose NEW behavior allows generated files.
// The implementation already works. We disable it here to avoid
// changing behavior for existing projects that do not expect it.
continue;
}
const std::string absFile =
cmsys::SystemTools::GetRealPath(sf->GetFullPath());
// Skip flags
const bool skipAll = PropertyEnabled(sf, "SKIP_AUTOGEN");
const bool mocSkip = skipAll || PropertyEnabled(sf, "SKIP_AUTOMOC");
const bool uicSkip = skipAll || PropertyEnabled(sf, "SKIP_AUTOUIC");
const bool accept = (mocTarget && !mocSkip) || (uicTarget && !uicSkip);
// For GENERATED files check status of policy CMP0071
if (accept && PropertyEnabled(sf, "GENERATED")) {
bool policyAccept = false;
switch (CMP0071_status) {
case cmPolicies::WARN: {
std::ostringstream ost;
ost << cmPolicies::GetPolicyWarning(cmPolicies::CMP0071) << "\n";
ost << "AUTOMOC/AUTOUIC: Ignoring GENERATED source file:\n";
ost << " " << cmQtAutoGeneratorCommon::Quoted(absFile) << "\n";
target->Makefile->IssueMessage(cmake::AUTHOR_WARNING, ost.str());
}
CM_FALLTHROUGH;
case cmPolicies::OLD:
// Ignore GENERATED file
break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
// Process GENERATED file
policyAccept = true;
break;
}
if (!policyAccept) {
continue;
}
}
// Add file name to skip lists.
// Do this even when the file is not added to the sources/headers lists
// because the file name may be extracted from an other file when
......@@ -327,7 +353,7 @@ static void AcquireScanFiles(cmGeneratorTarget const* target,
uicSkipList.push_back(absFile);
}
if ((mocTarget && !mocSkip) || (uicTarget && !uicSkip)) {
if (accept) {
// Add file name to sources or headers list
switch (fileType) {
case cmSystemTools::CXX_FILE_FORMAT:
......
cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0071 NEW)
project(QtAutogen)
# Tell find_package(Qt5) where to find Qt.
......@@ -304,11 +304,16 @@ add_subdirectory(mocDepends)
# -- Test
# Tests various include moc patterns
add_subdirectory(mocIncludeStrict)
if(ALLOW_WRAP_CPP)
add_subdirectory(mocIncludeStrict)
add_subdirectory(mocIncludeRelaxed)
endif()
# -- Test
# Tests various include moc patterns
add_subdirectory(mocIncludeRelaxed)
# Tests policy 0071
if(ALLOW_WRAP_CPP)
add_subdirectory(mocCMP0071)
endif()
# -- Test
# Tests Q_PLUGIN_METADATA json file change detection
......
cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.9)
# -- Test: AUTOMOC AUTORCC AUTOUIC
add_definitions(-DFOO -DSomeDefine="Barx")
......
cmake_minimum_required(VERSION 3.9)
project(mocCMP0071 CXX)
add_subdirectory(OLD)
add_subdirectory(NEW)
cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0071 NEW)
# *Generate* files
set(CSD ${CMAKE_CURRENT_SOURCE_DIR})
set(CBD ${CMAKE_CURRENT_BINARY_DIR})
add_custom_command(
OUTPUT ${CBD}/Obj_p.h ${CBD}/Obj.hpp ${CBD}/Obj.cpp ${CBD}/main.cpp
COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj_p.h ${CBD}/Obj_p.h
COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj.hpp ${CBD}/Obj.hpp
COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj.cpp ${CBD}/Obj.cpp
COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../main.cpp ${CBD}/main.cpp)
add_executable(mocCMP0071New ${CBD}/Obj.cpp ${CBD}/main.cpp)
target_link_libraries(mocCMP0071New ${QT_LIBRARIES})
set_target_properties(mocCMP0071New PROPERTIES AUTOMOC ON)
cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0071 OLD)
# *Generate* files
set(CSD ${CMAKE_CURRENT_SOURCE_DIR})
set(CBD ${CMAKE_CURRENT_BINARY_DIR})
add_custom_command(
OUTPUT ${CBD}/Obj_p.h ${CBD}/Obj.hpp ${CBD}/Obj.cpp ${CBD}/main.cpp
COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj_p.h ${CBD}/Obj_p.h
COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj.hpp ${CBD}/Obj.hpp
COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../Obj.cpp ${CBD}/Obj.cpp
COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/../main.cpp ${CBD}/main.cpp)
# Generate moc files externally
qtx_wrap_cpp(mocCMP0071OldMoc ${CBD}/Obj.hpp ${CBD}/Obj_p.h)
add_executable(mocCMP0071Old ${CBD}/Obj.cpp ${CBD}/main.cpp ${mocCMP0071OldMoc})
target_link_libraries(mocCMP0071Old ${QT_LIBRARIES})
set_target_properties(mocCMP0071Old PROPERTIES AUTOMOC ON)
#include "Obj.hpp"
#include "Obj_p.h"
ObjPrivate::ObjPrivate()
{
}
ObjPrivate::~ObjPrivate()
{
}
Obj::Obj()
: d(new ObjPrivate)
{
}
Obj::~Obj()
{
delete d;
}
#ifndef OBJ_HPP
#define OBJ_HPP
#include <QObject>
// Object source comes without any _moc/.moc includes
class ObjPrivate;
class Obj : public QObject
{
Q_OBJECT
public:
Obj();
~Obj();
private:
ObjPrivate* const d;
};
#endif
#ifndef OBJ_P_HPP
#define OBJ_P_HPP
#include <QObject>
class ObjPrivate : public QObject
{
Q_OBJECT
public:
ObjPrivate();
~ObjPrivate();
};
#endif
#include "Obj.hpp"
int main(int argv, char** args)
{
Obj obj;
return 0;
}
cmake_minimum_required(VERSION 3.7)
project(mocDepends)
cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0071 NEW)
project(mocDepends CXX)
if (QT_TEST_VERSION STREQUAL 4)
find_package(Qt4 REQUIRED)
......@@ -28,7 +29,6 @@ add_executable(mocDepends1 test1.cpp
)
target_link_libraries(mocDepends1 ${QT_CORE_TARGET})
set_target_properties(mocDepends1 PROPERTIES AUTOMOC TRUE)
set_property(TARGET mocDepends1 PROPERTY __UNDOCUMENTED_AUTOGEN_GENERATED_FILES 1)
# -- Test 2 using generated library
# This tests the dependency of AUTOMOC of mocDepends2 to the
......@@ -44,4 +44,3 @@ add_library(SimpleLib STATIC simpleLib.hpp simpleLib.cpp)
add_executable(mocDepends2 test2.cpp )
target_link_libraries(mocDepends2 SimpleLib ${QT_CORE_TARGET})
set_target_properties(mocDepends2 PROPERTIES AUTOMOC TRUE)
set_property(TARGET mocDepends2 PROPERTY __UNDOCUMENTED_AUTOGEN_GENERATED_FILES 1)
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.9)
project(mocPlugin CXX)
set(CMAKE_AUTOMOC_DEPEND_FILTERS
......
cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0071 NEW)
project(mocRerun CXX)
if (QT_TEST_VERSION STREQUAL 4)
......@@ -27,7 +28,6 @@ add_executable(mocRerun
${CMAKE_CURRENT_BINARY_DIR}/main.cpp
res1.qrc
)
set_property(TARGET mocRerun PROPERTY __UNDOCUMENTED_AUTOGEN_GENERATED_FILES 1)
target_include_directories(mocRerun PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(mocRerun ${QT_CORE_TARGET})
# Write target name to text file
......
cmake_minimum_required(VERSION 3.7)
project(rccDepends)
cmake_minimum_required(VERSION 3.9)
project(rccDepends CXX)
set(CMAKE_AUTORCC ON)
......
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