mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 16:32:14 -06:00
Autogen: Add test for AUTOGEN_ORIGIN_DEPENDS=OFF
This commit is contained in:
71
Tests/QtAutogen/AutogenOriginDependsOff/CMakeLists.txt
Normal file
71
Tests/QtAutogen/AutogenOriginDependsOff/CMakeLists.txt
Normal file
@@ -0,0 +1,71 @@
|
||||
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 )
|
||||
9
Tests/QtAutogen/AutogenOriginDependsOff/a_mc.hpp.in
Normal file
9
Tests/QtAutogen/AutogenOriginDependsOff/a_mc.hpp.in
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef A_MC_HPP
|
||||
#define A_MC_HPP
|
||||
|
||||
namespace a_mc {
|
||||
|
||||
char const* mocs_compilation = "@MOCS_COMPILATION@";
|
||||
}
|
||||
|
||||
#endif
|
||||
28
Tests/QtAutogen/AutogenOriginDependsOff/a_qt.cpp
Normal file
28
Tests/QtAutogen/AutogenOriginDependsOff/a_qt.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
#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"
|
||||
25
Tests/QtAutogen/AutogenOriginDependsOff/a_qt.hpp
Normal file
25
Tests/QtAutogen/AutogenOriginDependsOff/a_qt.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#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
|
||||
9
Tests/QtAutogen/AutogenOriginDependsOff/b_mc.cpp.in
Normal file
9
Tests/QtAutogen/AutogenOriginDependsOff/b_mc.cpp.in
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <b_mc.hpp>
|
||||
|
||||
namespace b_mc {
|
||||
|
||||
char const* mocs_compilation()
|
||||
{
|
||||
return "@MOCS_COMPILATION@";
|
||||
}
|
||||
}
|
||||
9
Tests/QtAutogen/AutogenOriginDependsOff/b_mc.hpp
Normal file
9
Tests/QtAutogen/AutogenOriginDependsOff/b_mc.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef B_MC_HPP
|
||||
#define B_MC_HPP
|
||||
|
||||
namespace b_mc {
|
||||
|
||||
extern char const* mocs_compilation();
|
||||
}
|
||||
|
||||
#endif
|
||||
28
Tests/QtAutogen/AutogenOriginDependsOff/b_qt.cpp
Normal file
28
Tests/QtAutogen/AutogenOriginDependsOff/b_qt.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
#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"
|
||||
25
Tests/QtAutogen/AutogenOriginDependsOff/b_qt.hpp
Normal file
25
Tests/QtAutogen/AutogenOriginDependsOff/b_qt.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#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
|
||||
8
Tests/QtAutogen/AutogenOriginDependsOff/config.hpp.in
Normal file
8
Tests/QtAutogen/AutogenOriginDependsOff/config.hpp.in
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef CONFIG_HPP
|
||||
#define CONFIG_HPP
|
||||
|
||||
// Application configuration
|
||||
|
||||
enum dummy { NO_OP };
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
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 )
|
||||
15
Tests/QtAutogen/AutogenOriginDependsOff/main.cpp
Normal file
15
Tests/QtAutogen/AutogenOriginDependsOff/main.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#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)
|
||||
|
||||
Reference in New Issue
Block a user