mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-08 14:50:10 -06:00
Autogen: Test: Add mocDepends test
This commit is contained in:
@@ -238,6 +238,10 @@ target_link_libraries(skipRccB ${QT_LIBRARIES})
|
||||
# Source files with the same basename in different subdirectories
|
||||
add_subdirectory(sameName)
|
||||
|
||||
# -- Test
|
||||
# Tests AUTOMOC with generated sources
|
||||
add_subdirectory(mocDepends)
|
||||
|
||||
# -- Test
|
||||
# Tests various include moc patterns
|
||||
add_subdirectory(mocIncludeStrict)
|
||||
|
||||
45
Tests/QtAutogen/mocDepends/CMakeLists.txt
Normal file
45
Tests/QtAutogen/mocDepends/CMakeLists.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project(mocDepends)
|
||||
|
||||
if (QT_TEST_VERSION STREQUAL 4)
|
||||
find_package(Qt4 REQUIRED)
|
||||
set(QT_CORE_TARGET Qt4::QtCore)
|
||||
else()
|
||||
if (NOT QT_TEST_VERSION STREQUAL 5)
|
||||
message(SEND_ERROR "Invalid Qt version specified.")
|
||||
endif()
|
||||
|
||||
find_package(Qt5Core REQUIRED)
|
||||
set(QT_CORE_TARGET Qt5::Core)
|
||||
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
|
||||
)
|
||||
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})
|
||||
set_target_properties(mocDepends2 PROPERTIES AUTOMOC TRUE)
|
||||
1
Tests/QtAutogen/mocDepends/invalid.hpp.in
Normal file
1
Tests/QtAutogen/mocDepends/invalid.hpp.in
Normal file
@@ -0,0 +1 @@
|
||||
#ifndef
|
||||
14
Tests/QtAutogen/mocDepends/object.hpp.in
Normal file
14
Tests/QtAutogen/mocDepends/object.hpp.in
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef OBJECT_HPP
|
||||
#define OBJECT_HPP
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Object : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_SLOT
|
||||
void aSlot(){};
|
||||
};
|
||||
|
||||
#endif
|
||||
9
Tests/QtAutogen/mocDepends/simpleLib.cpp.in
Normal file
9
Tests/QtAutogen/mocDepends/simpleLib.cpp.in
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "simpleLib.hpp"
|
||||
|
||||
SimpleLib::SimpleLib()
|
||||
{
|
||||
}
|
||||
|
||||
SimpleLib::~SimpleLib()
|
||||
{
|
||||
}
|
||||
11
Tests/QtAutogen/mocDepends/simpleLib.hpp.in
Normal file
11
Tests/QtAutogen/mocDepends/simpleLib.hpp.in
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef SIMPLE_LIB_H
|
||||
#define SIMPLE_LIB_H
|
||||
|
||||
class SimpleLib
|
||||
{
|
||||
public:
|
||||
SimpleLib();
|
||||
~SimpleLib();
|
||||
};
|
||||
|
||||
#endif
|
||||
9
Tests/QtAutogen/mocDepends/test1.cpp
Normal file
9
Tests/QtAutogen/mocDepends/test1.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
#include "object.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
Object obj;
|
||||
|
||||
return 0;
|
||||
}
|
||||
10
Tests/QtAutogen/mocDepends/test2.cpp
Normal file
10
Tests/QtAutogen/mocDepends/test2.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#include "test2.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
SimpleLib obj;
|
||||
LObject lobject;
|
||||
|
||||
return 0;
|
||||
}
|
||||
16
Tests/QtAutogen/mocDepends/test2.hpp
Normal file
16
Tests/QtAutogen/mocDepends/test2.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef TEST2_HPP
|
||||
#define TEST2_HPP
|
||||
|
||||
#include "simpleLib.hpp"
|
||||
#include <QObject>
|
||||
|
||||
// This object triggers the AUTOMOC on this file
|
||||
class LObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_SLOT
|
||||
void aSlot(){};
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user