diff options
Diffstat (limited to 'Tests/QtAutogen')
-rw-r--r-- | Tests/QtAutogen/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/QtAutogen/mocDepends/CMakeLists.txt | 97 | ||||
-rw-r--r-- | Tests/QtAutogen/mocDepends/simpleLib.hpp.in | 5 | ||||
-rw-r--r-- | Tests/QtAutogen/mocDepends/test1.cpp | 3 | ||||
-rw-r--r-- | Tests/QtAutogen/mocDepends/test2.cpp | 7 | ||||
-rw-r--r-- | Tests/QtAutogen/mocDepends/test3.cpp | 12 | ||||
-rw-r--r-- | Tests/QtAutogen/mocDepends/test3.hpp (renamed from Tests/QtAutogen/mocDepends/test2.hpp) | 4 | ||||
-rw-r--r-- | Tests/QtAutogen/mocInclude/shared.cmake | 6 | ||||
-rw-r--r-- | Tests/QtAutogen/objectLibrary/CMakeLists.txt | 14 | ||||
-rw-r--r-- | Tests/QtAutogen/objectLibrary/a/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/QtAutogen/objectLibrary/a/classa.cpp | 7 | ||||
-rw-r--r-- | Tests/QtAutogen/objectLibrary/a/classa.h | 23 | ||||
-rw-r--r-- | Tests/QtAutogen/objectLibrary/b/classb.cpp | 7 | ||||
-rw-r--r-- | Tests/QtAutogen/objectLibrary/b/classb.h | 23 | ||||
-rw-r--r-- | Tests/QtAutogen/objectLibrary/main.cpp | 13 |
15 files changed, 192 insertions, 35 deletions
diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt index 5064d26..198bf63 100644 --- a/Tests/QtAutogen/CMakeLists.txt +++ b/Tests/QtAutogen/CMakeLists.txt @@ -193,5 +193,9 @@ endif() add_subdirectory(uicInclude) # -- Test +# OBJECT libraries +add_subdirectory(objectLibrary) + +# -- Test # Complex test case add_subdirectory(complex) diff --git a/Tests/QtAutogen/mocDepends/CMakeLists.txt b/Tests/QtAutogen/mocDepends/CMakeLists.txt index cd5adf5..d71d740 100644 --- a/Tests/QtAutogen/mocDepends/CMakeLists.txt +++ b/Tests/QtAutogen/mocDepends/CMakeLists.txt @@ -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) diff --git a/Tests/QtAutogen/mocDepends/simpleLib.hpp.in b/Tests/QtAutogen/mocDepends/simpleLib.hpp.in index 758f1f6..b65b0cb 100644 --- a/Tests/QtAutogen/mocDepends/simpleLib.hpp.in +++ b/Tests/QtAutogen/mocDepends/simpleLib.hpp.in @@ -1,8 +1,11 @@ #ifndef SIMPLE_LIB_H #define SIMPLE_LIB_H -class SimpleLib +#include <QObject> + +class SimpleLib : public QObject { + Q_OBJECT public: SimpleLib(); ~SimpleLib(); diff --git a/Tests/QtAutogen/mocDepends/test1.cpp b/Tests/QtAutogen/mocDepends/test1.cpp index 92c259c..002dfd8 100644 --- a/Tests/QtAutogen/mocDepends/test1.cpp +++ b/Tests/QtAutogen/mocDepends/test1.cpp @@ -1,9 +1,8 @@ -#include "object.hpp" +#include "test1_object.hpp" int main() { Object obj; - return 0; } diff --git a/Tests/QtAutogen/mocDepends/test2.cpp b/Tests/QtAutogen/mocDepends/test2.cpp index 155b19b..3fd845e 100644 --- a/Tests/QtAutogen/mocDepends/test2.cpp +++ b/Tests/QtAutogen/mocDepends/test2.cpp @@ -1,10 +1,9 @@ -#include "test2.hpp" +#include "moc_test2_object.cpp" +#include "test2_object.hpp" int main() { - SimpleLib obj; - LObject lobject; - + Object obj; return 0; } diff --git a/Tests/QtAutogen/mocDepends/test3.cpp b/Tests/QtAutogen/mocDepends/test3.cpp new file mode 100644 index 0000000..a009598 --- /dev/null +++ b/Tests/QtAutogen/mocDepends/test3.cpp @@ -0,0 +1,12 @@ + +#include "test3.hpp" + +int main() +{ + SimpleLib libObject; + LObject lobject; + return 0; +} + +// AUTOMOC the SimpleLib header simpleLib.hpp +#include "moc_simpleLib.cpp" diff --git a/Tests/QtAutogen/mocDepends/test2.hpp b/Tests/QtAutogen/mocDepends/test3.hpp index 0125f07..408335b 100644 --- a/Tests/QtAutogen/mocDepends/test2.hpp +++ b/Tests/QtAutogen/mocDepends/test3.hpp @@ -1,5 +1,5 @@ -#ifndef TEST2_HPP -#define TEST2_HPP +#ifndef TEST3_HPP +#define TEST3_HPP #include "simpleLib.hpp" #include <QObject> diff --git a/Tests/QtAutogen/mocInclude/shared.cmake b/Tests/QtAutogen/mocInclude/shared.cmake index c426050..d05f27c 100644 --- a/Tests/QtAutogen/mocInclude/shared.cmake +++ b/Tests/QtAutogen/mocInclude/shared.cmake @@ -29,9 +29,11 @@ set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/SObjB.cpp PROPERTY SKIP_AUTOMOC qtx_generate_moc( ${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/SObjCExtra.hpp ${CMAKE_CURRENT_BINARY_DIR}/SObjCExtra_extMoc.cpp) -set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/SObjCExtra.hpp PROPERTY SKIP_AUTOMOC ON) +set_property( + SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../mocInclude/SObjCExtra.hpp + PROPERTY SKIP_AUTOMOC ON) # Custom target to depend on -set(SOBJC_MOC ${CMAKE_CURRENT_BINARY_DIR}/${MOC_INCLUDE_NAME}_autogen/include/moc_SObjCExtra.cpp) +set(SOBJC_MOC ${CMAKE_CURRENT_BINARY_DIR}/moc_SObjCExtra.cpp) add_custom_target("${MOC_INCLUDE_NAME}_SOBJC" DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/SObjCExtra_extMoc.cpp BYPRODUCTS ${SOBJC_MOC} diff --git a/Tests/QtAutogen/objectLibrary/CMakeLists.txt b/Tests/QtAutogen/objectLibrary/CMakeLists.txt new file mode 100644 index 0000000..9b29a40 --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/CMakeLists.txt @@ -0,0 +1,14 @@ +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) + +# Object library a defined in a subdirectory +add_subdirectory(a) + +# Object library b defined locally +include_directories(b) +add_library(b OBJECT b/classb.cpp) +target_compile_features(b PRIVATE ${QT_COMPILE_FEATURES}) + +# Executable with OBJECT library generator expressions +add_executable(someProgram main.cpp $<TARGET_OBJECTS:a> $<TARGET_OBJECTS:b>) +target_link_libraries(someProgram ${QT_LIBRARIES}) diff --git a/Tests/QtAutogen/objectLibrary/a/CMakeLists.txt b/Tests/QtAutogen/objectLibrary/a/CMakeLists.txt new file mode 100644 index 0000000..fe76ac3 --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/a/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(a OBJECT classa.cpp) +target_compile_features(a PRIVATE ${QT_COMPILE_FEATURES}) diff --git a/Tests/QtAutogen/objectLibrary/a/classa.cpp b/Tests/QtAutogen/objectLibrary/a/classa.cpp new file mode 100644 index 0000000..4f08fda --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/a/classa.cpp @@ -0,0 +1,7 @@ +#include "classa.h" +#include <QDebug> + +void ClassA::slotDoSomething() +{ + qDebug() << m_member; +} diff --git a/Tests/QtAutogen/objectLibrary/a/classa.h b/Tests/QtAutogen/objectLibrary/a/classa.h new file mode 100644 index 0000000..fa5fed9 --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/a/classa.h @@ -0,0 +1,23 @@ +#ifndef CLASSA_H +#define CLASSA_H + +#include <QObject> +#include <QString> + +class ClassA : public QObject +{ + Q_OBJECT +public: + ClassA() + : m_member("Hello A") + { + } + +public slots: + void slotDoSomething(); + +private: + QString m_member; +}; + +#endif diff --git a/Tests/QtAutogen/objectLibrary/b/classb.cpp b/Tests/QtAutogen/objectLibrary/b/classb.cpp new file mode 100644 index 0000000..26e0926 --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/b/classb.cpp @@ -0,0 +1,7 @@ +#include "classb.h" +#include <QDebug> + +void ClassB::slotDoSomething() +{ + qDebug() << m_member; +} diff --git a/Tests/QtAutogen/objectLibrary/b/classb.h b/Tests/QtAutogen/objectLibrary/b/classb.h new file mode 100644 index 0000000..783bb48 --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/b/classb.h @@ -0,0 +1,23 @@ +#ifndef CLASSB_H +#define CLASSB_H + +#include <QObject> +#include <QString> + +class ClassB : public QObject +{ + Q_OBJECT +public: + ClassB() + : m_member("Hello B") + { + } + +public slots: + void slotDoSomething(); + +private: + QString m_member; +}; + +#endif diff --git a/Tests/QtAutogen/objectLibrary/main.cpp b/Tests/QtAutogen/objectLibrary/main.cpp new file mode 100644 index 0000000..cacf0fd --- /dev/null +++ b/Tests/QtAutogen/objectLibrary/main.cpp @@ -0,0 +1,13 @@ +#include "a/classa.h" +#include "b/classb.h" + +int main(int argc, char** argv) +{ + ClassA a; + a.slotDoSomething(); + + ClassB b; + b.slotDoSomething(); + + return 0; +} |