Commit 54bc20dd authored by Craig Scott's avatar Craig Scott Committed by Kitware Robot

Merge topic 'autogen-depends'

a3a62fcc Autogen: Add AUTOMOC test for target dependencies forwarding
7fa9c550 Autogen: Forward target dependencies to *_autogen target
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1087
parents 901456d7 a3a62fcc
Pipeline #66629 passed with stage
in 0 seconds
......@@ -745,7 +745,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
const std::string qtMajorVersion = GetQtMajorVersion(target);
const std::string rccCommand = RccGetExecutable(target, qtMajorVersion);
const std::vector<std::string> suffixes = GetConfigurationSuffixes(makefile);
std::vector<std::string> autogenDepends;
std::set<std::string> autogenDependsSet;
std::vector<std::string> autogenProvides;
// Remove build directories on cleanup
......@@ -837,7 +837,20 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
// Initialize autogen target dependencies
if (const char* deps = target->GetProperty("AUTOGEN_TARGET_DEPENDS")) {
cmSystemTools::ExpandListArgument(deps, autogenDepends);
std::vector<std::string> extraDepends;
cmSystemTools::ExpandListArgument(deps, extraDepends);
autogenDependsSet.insert(extraDepends.begin(), extraDepends.end());
}
// Add other target dependencies autogen dependencies
{
const std::set<std::string>& utils = target->Target->GetUtilities();
for (std::set<std::string>::const_iterator it = utils.begin();
it != utils.end(); ++it) {
const std::string& targetName = *it;
if (makefile->FindTargetToUse(targetName) != CM_NULLPTR) {
autogenDependsSet.insert(targetName);
}
}
}
// Add link library targets to the autogen dependencies
{
......@@ -847,7 +860,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
it != libVec.end(); ++it) {
const std::string& libName = it->first;
if (makefile->FindTargetToUse(libName) != CM_NULLPTR) {
autogenDepends.push_back(libName);
autogenDependsSet.insert(libName);
}
}
}
......@@ -871,7 +884,7 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
if (PropertyEnabled(sf, "GENERATED")) {
if ((mocEnabled && !PropertyEnabled(sf, "SKIP_AUTOMOC")) ||
(uicEnabled && !PropertyEnabled(sf, "SKIP_AUTOUIC"))) {
autogenDepends.push_back(
autogenDependsSet.insert(
cmsys::SystemTools::GetRealPath(sf->GetFullPath()));
#if defined(_WIN32) && !defined(__CYGWIN__)
// Cannot use PRE_BUILD with generated files
......@@ -916,17 +929,22 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
if (PropertyEnabled(sf, "GENERATED")) {
// Add generated qrc file to the dependencies
autogenDepends.push_back(absFile);
autogenDependsSet.insert(absFile);
} else {
// Run cmake again when .qrc file changes
makefile->AddCMakeDependFile(absFile);
// Add the qrc input files to the dependencies
std::string error;
if (!cmQtAutoGeneratorCommon::RccListInputs(
qtMajorVersion, rccCommand, absFile, autogenDepends,
&error)) {
cmSystemTools::Error(error.c_str());
{
std::string error;
std::vector<std::string> extraDepends;
if (cmQtAutoGeneratorCommon::RccListInputs(
qtMajorVersion, rccCommand, absFile, extraDepends,
&error)) {
autogenDependsSet.insert(extraDepends.begin(),
extraDepends.end());
} else {
cmSystemTools::Error(error.c_str());
}
}
}
#if defined(_WIN32) && !defined(__CYGWIN__)
......@@ -940,10 +958,13 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
}
}
// Convert std::set to std::vector
const std::vector<std::string> autogenDepends(autogenDependsSet.begin(),
autogenDependsSet.end());
#if defined(_WIN32) && !defined(__CYGWIN__)
if (usePRE_BUILD) {
// If the autogen target depends on an other target don't use PRE_BUILD
for (std::vector<std::string>::iterator it = autogenDepends.begin();
for (std::vector<std::string>::const_iterator it = autogenDepends.begin();
it != autogenDepends.end(); ++it) {
if (makefile->FindTargetToUse(*it) != CM_NULLPTR) {
usePRE_BUILD = false;
......
......@@ -16,31 +16,80 @@ endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# -- Test 1 using generated header
# This tests the dependency of AUTOMOC of mocDepends1 to the generated object.hpp
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/object.hpp
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/invalid.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/object.hpp
COMMAND ${CMAKE_COMMAND} -E sleep 3
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/object.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/object.hpp
)
add_executable(mocDepends1 test1.cpp
${CMAKE_CURRENT_BINARY_DIR}/object.hpp
)
# -- Test 1: Depend on generated header
# The ORIGIN_autogen target must depend on the same *GENERATED* source files as
# the ORIGIN target. This is a requirement to ensure that all files for the
# ORIGIN target are generated before the ORIGIN_autogen target is built.
#
# This tests the dependency of the mocDepends1_autogen target of mocDepends1
# to the source file test1_object.hpp, which is *GENERATED* by a custom command.
# If mocDepends1_autogen gets built *before* or in *parallel* to the
# custom command, the build will fail. That's because test1_object.hpp,
# which is required by mocDepends1_autogen, is only valid after the
# custom command has been completed.
#
# The sleep seconds artificially increase the build time of the custom command
# to simulate a slow file generation process that takes longer to run than
# the build of the mocDepends1_autogen target.
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test1_object.hpp
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/invalid.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/test1_object.hpp
COMMAND ${CMAKE_COMMAND} -E sleep 3
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/object.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/test1_object.hpp)
add_executable(mocDepends1 test1.cpp ${CMAKE_CURRENT_BINARY_DIR}/test1_object.hpp)
target_link_libraries(mocDepends1 ${QT_CORE_TARGET})
set_target_properties(mocDepends1 PROPERTIES AUTOMOC TRUE)
# -- Test 2 using generated library
# This tests the dependency of AUTOMOC of mocDepends2 to the
# generated simpleLib.hpp which belongs to a linked library of mocDepends2
add_custom_command(OUTPUT simpleLib.hpp simpleLib.cpp
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/invalid.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp
COMMAND ${CMAKE_COMMAND} -E sleep 3
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/simpleLib.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/simpleLib.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.cpp
)
add_library(SimpleLib STATIC simpleLib.hpp simpleLib.cpp)
add_executable(mocDepends2 test2.cpp )
target_link_libraries(mocDepends2 SimpleLib ${QT_CORE_TARGET})
# -- Test 2: Depend on header generating target
# The ORIGIN_autogen target must depend on the same user defined targets
# as the ORIGIN target. This is a requirement to ensure that all files for the
# ORIGIN target are generated before the ORIGIN_autogen target is built.
#
# This tests the dependency of the mocDepends2_autogen target of mocDepends2
# to the utility target mocDepends2Object. If mocDepends2_autogen gets built
# *before* or in *parallel* to mocDepends2Object, the build will fail. That's
# because test2_object.hpp, which is required by mocDepends2_autogen,
# is only valid after the mocDepends2Object build has been completed.
#
# The sleep seconds artificially increase the build time of mocDepends2Object
# to simulate a slow utility target build that takes longer to run than
# the build of the mocDepends2_autogen target.
add_custom_target(mocDepends2Object
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/test2_object.hpp
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/invalid.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/test2_object.hpp
COMMAND ${CMAKE_COMMAND} -E sleep 3
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/object.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/test2_object.hpp)
add_executable(mocDepends2 test2.cpp)
target_link_libraries(mocDepends2 ${QT_CORE_TARGET})
set_target_properties(mocDepends2 PROPERTIES AUTOMOC TRUE)
add_dependencies(mocDepends2 mocDepends2Object)
# -- Test 3: Depend on generated linked library
# The ORIGIN_autogen target must depend on the same linked libraries
# as the ORIGIN target. This is a requirement to ensure that all files for the
# ORIGIN target are generated before the ORIGIN_autogen target is built.
#
# This tests the dependency of the mocDepends3_autogen target of mocDepends3
# to the user generated library SimpleLib, which mocDepends3 links to.
# If mocDepends3_autogen gets built *before* or in *parallel* to SimpleLib,
# the build will fail. That's because simpleLib.hpp, which is required by
# mocDepends3_autogen, is only valid after the SimpleLib build has been
# completed.
#
# The sleep seconds artificially increase the build time of SimpleLib
# to simulate a slow utility library build that takes longer to run than
# the build of the mocDepends3_autogen target.
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.cpp
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/invalid.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp
COMMAND ${CMAKE_COMMAND} -E sleep 3
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/simpleLib.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/simpleLib.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.cpp)
add_library(SimpleLib STATIC ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.hpp ${CMAKE_CURRENT_BINARY_DIR}/simpleLib.cpp)
target_link_libraries(SimpleLib ${QT_CORE_TARGET})
add_executable(mocDepends3 test3.cpp)
target_link_libraries(mocDepends3 SimpleLib ${QT_CORE_TARGET})
set_target_properties(mocDepends3 PROPERTIES AUTOMOC TRUE)
#ifndef SIMPLE_LIB_H
#define SIMPLE_LIB_H
class SimpleLib
#include <QObject>
class SimpleLib : public QObject
{
Q_OBJECT
public:
SimpleLib();
~SimpleLib();
......
#include "object.hpp"
#include "test1_object.hpp"
int main()
{
Object obj;
return 0;
}
#include "test2.hpp"
#include "moc_test2_object.cpp"
#include "test2_object.hpp"
int main()
{
SimpleLib obj;
LObject lobject;
Object obj;
return 0;
}
#include "test3.hpp"
int main()
{
SimpleLib libObject;
LObject lobject;
return 0;
}
// AUTOMOC the SimpleLib header simpleLib.hpp
#include "moc_simpleLib.cpp"
#ifndef TEST2_HPP
#define TEST2_HPP
#ifndef TEST3_HPP
#define TEST3_HPP
#include "simpleLib.hpp"
#include <QObject>
......
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