1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

Merge topic 'automoc-depend-project-file' into release-3.18

776059ef0f Merge branch 'backport-3.17-automoc-depend-project-file'
6b20bbd2dd AutoMoc: Restore support for re-running after project file changes

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5166
This commit is contained in:
Brad King
2020-09-01 13:08:21 +00:00
committed by Kitware Robot
9 changed files with 150 additions and 1 deletions

View File

@@ -1518,6 +1518,7 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
info.SetConfig("PARSE_CACHE_FILE", this->AutogenTarget.ParseCacheFile);
info.Set("DEP_FILE", this->AutogenTarget.DepFile);
info.Set("DEP_FILE_RULE_NAME", this->AutogenTarget.DepFileRuleName);
info.SetArray("CMAKE_LIST_FILES", this->Makefile->GetListFiles());
info.SetArray("HEADER_EXTENSIONS",
this->Makefile->GetCMakeInstance()->GetHeaderExtensions());
info.SetArrayArray(

View File

@@ -184,6 +184,7 @@ public:
std::string DepFile;
std::string DepFileRuleName;
std::vector<std::string> HeaderExtensions;
std::vector<std::string> ListFiles;
};
/** Shared common variables. */
@@ -2176,7 +2177,7 @@ void cmQtAutoMocUicT::JobDepFilesMergeT::Process()
return dependenciesFromDepFile(f.c_str());
};
std::vector<std::string> dependencies;
std::vector<std::string> dependencies = BaseConst().ListFiles;
ParseCacheT& parseCache = BaseEval().ParseCache;
auto processMappingEntry = [&](const MappingMapT::value_type& m) {
auto cacheEntry = parseCache.GetOrInsert(m.first);
@@ -2257,6 +2258,7 @@ bool cmQtAutoMocUicT::InitFromInfo(InfoT const& info)
!info.GetString("DEP_FILE_RULE_NAME", BaseConst_.DepFileRuleName,
false) ||
!info.GetStringConfig("SETTINGS_FILE", SettingsFile_, true) ||
!info.GetArray("CMAKE_LIST_FILES", BaseConst_.ListFiles, true) ||
!info.GetArray("HEADER_EXTENSIONS", BaseConst_.HeaderExtensions, true) ||
!info.GetString("QT_MOC_EXECUTABLE", MocConst_.Executable, false) ||
!info.GetString("QT_UIC_EXECUTABLE", UicConst_.Executable, false)) {

View File

@@ -0,0 +1,96 @@
# This test checks whether adding a source file to the project triggers an AUTOMOC re-run.
cmake_minimum_required(VERSION 3.10)
project(RerunMocOnAddFile)
include("../AutogenCoreTest.cmake")
# Create an executable to generate a clean target
set(main_source "${CMAKE_CURRENT_BINARY_DIR}/generated_main.cpp")
file(WRITE "${main_source}" "int main() {}")
add_executable(exe "${main_source}")
# Utility variables
set(timeformat "%Y.%j.%H.%M%S")
set(testProjectTemplateDir "${CMAKE_CURRENT_SOURCE_DIR}/MocOnAddFile")
set(testProjectSrc "${CMAKE_CURRENT_BINARY_DIR}/MocOnAddFile")
set(testProjectBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocOnAddFile-build")
# Utility macros
macro(sleep)
message(STATUS "Sleeping for a few seconds.")
execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
endmacro()
macro(acquire_timestamp When)
file(TIMESTAMP "${mocBasicBin}" time${When} "${timeformat}")
endmacro()
macro(rebuild buildName)
message(STATUS "Starting build ${buildName}.")
execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${testProjectBinDir}" RESULT_VARIABLE result)
if (result)
message(FATAL_ERROR "Build ${buildName} failed.")
else()
message(STATUS "Build ${buildName} finished.")
endif()
endmacro()
macro(require_change)
if (timeAfter VERSION_GREATER timeBefore)
message(STATUS "As expected the file ${mocBasicBin} changed.")
else()
message(SEND_ERROR "Unexpectedly the file ${mocBasicBin} did not change!\nTimestamp pre: ${timeBefore}\nTimestamp aft: ${timeAfter}\n")
endif()
endmacro()
macro(require_change_not)
if (timeAfter VERSION_GREATER timeBefore)
message(SEND_ERROR "Unexpectedly the file ${mocBasicBin} changed!\nTimestamp pre: ${timeBefore}\nTimestamp aft: ${timeAfter}\n")
else()
message(STATUS "As expected the file ${mocBasicBin} did not change.")
endif()
endmacro()
# Create the test project from the template
unset(additional_project_sources)
unset(main_cpp_includes)
configure_file("${testProjectTemplateDir}/CMakeLists.txt.in" "${testProjectSrc}/CMakeLists.txt")
configure_file("${testProjectTemplateDir}/main.cpp.in" "${testProjectSrc}/main.cpp")
# Initial build
try_compile(MOC_RERUN
"${testProjectBinDir}"
"${testProjectSrc}"
MocOnAddFile
CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
"-DCMAKE_AUTOGEN_VERBOSE=${CMAKE_AUTOGEN_VERBOSE}"
"-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
OUTPUT_VARIABLE output
)
if (NOT MOC_RERUN)
message(FATAL_ERROR "Initial build of mocOnAddFile failed. Output: ${output}")
endif()
# Sleep to ensure new timestamps
sleep()
# Add a QObject class (defined in header) to the project and build
set(additional_project_sources myobject.cpp)
set(main_cpp_includes "#include \"myobject.h\"")
configure_file("${testProjectTemplateDir}/CMakeLists.txt.in" "${testProjectSrc}/CMakeLists.txt"
@ONLY)
configure_file("${testProjectTemplateDir}/main.cpp.in" "${testProjectSrc}/main.cpp" @ONLY)
configure_file("${testProjectTemplateDir}/myobject.h" "${testProjectSrc}/myobject.h" COPYONLY)
configure_file("${testProjectTemplateDir}/myobject.cpp" "${testProjectSrc}/myobject.cpp" COPYONLY)
rebuild(2)
# Sleep to ensure new timestamps
sleep()
# Add a QObject class (defined in source) to the project and build
set(additional_project_sources myobject.cpp anotherobject.cpp)
configure_file("${testProjectTemplateDir}/CMakeLists.txt.in" "${testProjectSrc}/CMakeLists.txt"
@ONLY)
configure_file("${testProjectTemplateDir}/anotherobject.cpp" "${testProjectSrc}/anotherobject.cpp"
COPYONLY)
rebuild(3)

View File

@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.10)
project(MocOnAddFile)
include("@CMAKE_CURRENT_LIST_DIR@/../AutogenCoreTest.cmake")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
add_executable(mocOnAddFile main.cpp @additional_project_sources@)
target_link_libraries(mocOnAddFile ${QT_QTCORE_TARGET})

View File

@@ -0,0 +1,15 @@
#include <qobject.h>
class AnotherObject : public QObject
{
Q_OBJECT
public:
AnotherObject() {}
};
AnotherObject* createAnotherObject()
{
return new AnotherObject();
}
#include "anotherobject.moc"

View File

@@ -0,0 +1,6 @@
@main_cpp_includes@
int main(int argc, char *argv[])
{
return 0;
}

View File

@@ -0,0 +1,6 @@
#include "myobject.h"
MyObject::MyObject(QObject* parent)
: QObject(parent)
{
}

View File

@@ -0,0 +1,13 @@
#ifndef MYOBJECT_H
#define MYOBJECT_H
#include <qobject.h>
class MyObject : public QObject
{
Q_OBJECT
public:
MyObject(QObject* parent = 0);
};
#endif

View File

@@ -20,6 +20,7 @@ ADD_AUTOGEN_TEST(RccOffMocLibrary)
ADD_AUTOGEN_TEST(RccOnly rccOnly)
ADD_AUTOGEN_TEST(RccSkipSource)
ADD_AUTOGEN_TEST(RerunMocBasic)
ADD_AUTOGEN_TEST(RerunMocOnAddFile)
ADD_AUTOGEN_TEST(RerunRccConfigChange)
ADD_AUTOGEN_TEST(RerunRccDepends)
ADD_AUTOGEN_TEST(SameName sameName)