Commit b71a9598 authored by Sebastian Holtermann's avatar Sebastian Holtermann
Browse files

Autogen: Add test for AUTOGEN_ORIGIN_DEPENDS=OFF

parent f74c4065
cmake_minimum_required(VERSION 3.11)
project(AutogenOriginDependsOff)
include("../AutogenTest.cmake")
set(CSD ${CMAKE_CURRENT_SOURCE_DIR})
set(CBD ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CSD})
include_directories(${CBD})
# A GENERATED file ensures there will be an _autogen target in VS
add_custom_command (
OUTPUT "${CBD}/config.hpp"
COMMAND ${CMAKE_COMMAND} -E copy "${CSD}/config.hpp.in" "${CBD}/config.hpp"
)
# Library "a_mc" provides a header that holds a string with the content of
# mocs_compilation.cpp from a_qt. It therefore must depend on a_qt_autogen.
add_custom_target ( a_mc
COMMAND ${CMAKE_COMMAND} -E sleep 2
COMMAND ${CMAKE_COMMAND}
"-DMCF=${CBD}/a_qt_autogen/mocs_compilation.cpp"
"-DCF_IN=${CSD}/a_mc.hpp.in"
"-DCF_OUT=${CBD}/a_mc.hpp"
-P ${CSD}/configure_content.cmake
)
add_dependencies ( a_mc a_qt_autogen )
# Library "a_qt"
# - depends on a GENERATED file
# - AUTOMOC enabled
# - depends on a target (a_mc) that depends on a_qt_qutogen
add_library ( a_qt a_qt.cpp "${CBD}/config.hpp" )
add_dependencies ( a_qt a_mc )
target_link_libraries ( a_qt ${QT_QTCORE_TARGET})
set_target_properties ( a_qt PROPERTIES AUTOMOC TRUE)
# Disable AUTOGEN_ORIGIN_DEPENDS to avoid loop dependencies
set_target_properties ( a_qt PROPERTIES AUTOGEN_ORIGIN_DEPENDS OFF)
# Library "b_mc" provides a header that holds a string function that returns
# the content of mocs_compilation.cpp from b_qt.
# It therefore must depend on b_qt_autogen.
add_custom_command (
OUTPUT ${CBD}/b_mc.cpp
DEPENDS b_qt_autogen
COMMAND ${CMAKE_COMMAND} -E sleep 2
COMMAND ${CMAKE_COMMAND}
"-DMCF=${CBD}/b_qt_autogen/mocs_compilation.cpp"
"-DCF_IN=${CSD}/b_mc.cpp.in"
"-DCF_OUT=${CBD}/b_mc.cpp"
-P ${CSD}/configure_content.cmake
)
add_library ( b_mc ${CSD}/b_mc.hpp ${CBD}/b_mc.cpp )
# Library "b_qt"
# - depends on a GENERATED file
# - AUTOMOC enabled
# - depends on a library (b_mc) that depends on b_qt_qutogen
add_library ( b_qt b_qt.cpp "${CBD}/config.hpp" )
target_link_libraries ( b_qt b_mc )
target_link_libraries ( b_qt ${QT_QTCORE_TARGET})
set_target_properties ( b_qt PROPERTIES AUTOMOC TRUE)
# Disable AUTOGEN_ORIGIN_DEPENDS to avoid loop dependencies
set_target_properties ( b_qt PROPERTIES AUTOGEN_ORIGIN_DEPENDS OFF)
# The main target depends on both libraries which depend on the _autogen
# target of the main target.
add_executable ( autogenOriginDependsOff main.cpp )
target_link_libraries ( autogenOriginDependsOff a_qt b_qt )
#ifndef A_MC_HPP
#define A_MC_HPP
namespace a_mc {
char const* mocs_compilation = "@MOCS_COMPILATION@";
}
#endif
#include "a_qt.hpp"
#include <a_mc.hpp>
namespace a_qt {
/// @brief A source local QObject based class
class Source_QObject : public QObject
{
Q_OBJECT
public:
Source_QObject() {}
~Source_QObject() {}
std::string str;
};
std::string mocs_compilation()
{
// Create and destroy QObject based classes
Header_QObject header_obj;
Source_QObject source_obj;
return std::string(a_mc::mocs_compilation);
}
}
#include "a_qt.moc"
#ifndef A_QT_HPP
#define A_QT_HPP
#include <QObject>
#include <config.hpp>
#include <string>
namespace a_qt {
/// @brief A header local QObject based class
class Header_QObject : public QObject
{
Q_OBJECT
public:
Header_QObject() {}
~Header_QObject() {}
std::string str;
};
/// @brief Function that returns the content of mocs_compilation.cpp
extern std::string mocs_compilation();
}
#endif
#include <b_mc.hpp>
namespace b_mc {
char const* mocs_compilation()
{
return "@MOCS_COMPILATION@";
}
}
#ifndef B_MC_HPP
#define B_MC_HPP
namespace b_mc {
extern char const* mocs_compilation();
}
#endif
#include "b_qt.hpp"
#include <b_mc.hpp>
namespace b_qt {
/// @brief A source local QObject based class
class Source_QObject : public QObject
{
Q_OBJECT
public:
Source_QObject() {}
~Source_QObject() {}
std::string str;
};
std::string mocs_compilation()
{
// Create and destroy QObject based classes
Header_QObject header_obj;
Source_QObject source_obj;
return std::string(b_mc::mocs_compilation());
}
}
#include "b_qt.moc"
#ifndef B_QT_HPP
#define B_QT_HPP
#include <QObject>
#include <config.hpp>
#include <string>
namespace b_qt {
/// @brief A header local QObject based class
class Header_QObject : public QObject
{
Q_OBJECT
public:
Header_QObject() {}
~Header_QObject() {}
std::string str;
};
/// @brief Function that returns the content of mocs_compilation.cpp
extern std::string mocs_compilation();
}
#endif
#ifndef CONFIG_HPP
#define CONFIG_HPP
// Application configuration
enum dummy { NO_OP };
#endif
cmake_minimum_required(VERSION 3.10)
# Read mocs_compilation.cpp file into variable
file(READ "${MCF}" MOCS_COMPILATION)
string(REPLACE "\\" "\\\\" MOCS_COMPILATION "${MOCS_COMPILATION}" )
string(REPLACE "\"" "\\\"" MOCS_COMPILATION "${MOCS_COMPILATION}" )
string(REPLACE "\n" "\"\n\"" MOCS_COMPILATION "${MOCS_COMPILATION}" )
# Configure file
configure_file ( "${CF_IN}" "${CF_OUT}" @ONLY )
#include <a_qt.hpp>
#include <b_qt.hpp>
#include <string>
int main()
{
if (a_qt::mocs_compilation().empty()) {
return -1;
}
if (b_qt::mocs_compilation().empty()) {
return -1;
}
return 0;
}
......@@ -15,6 +15,7 @@ ADD_AUTOGEN_TEST(RccSkipSource)
if(QT_TEST_VERSION GREATER 4)
ADD_AUTOGEN_TEST(MocMacroName mocMacroName)
endif()
ADD_AUTOGEN_TEST(AutogenOriginDependsOff autogenOriginDependsOff)
ADD_AUTOGEN_TEST(MocDepends)
if(QT_TEST_ALLOW_QT_MACROS)
ADD_AUTOGEN_TEST(MocIncludeStrict mocIncludeStrict)
......
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