summaryrefslogtreecommitdiff
path: root/Tests/QtAutogen/MocDepends/CMakeLists.txt
blob: 6ea72be61a43a834e4fc65fe9e5f60368ba83fbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
cmake_minimum_required(VERSION 3.10)
project(MocDepends)
include("../AutogenTest.cmake")

include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(CSD ${CMAKE_CURRENT_SOURCE_DIR})
set(CBD ${CMAKE_CURRENT_BINARY_DIR})

# -- Test dependency on header generated by a custom command
#
# 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 mocDepGenFile_autogen target of
# mocDepGenFile to the source file GenFile.hpp, which is *GENERATED*
# by a custom command.
# If mocDepGenFile_autogen gets built *before* or in *parallel* to the
# custom command, the build will fail. That's because GenFile.hpp,
# which is required by mocDepGenFile_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 mocDepGenFile_autogen target.
add_custom_command(
  OUTPUT ${CBD}/GenFile.hpp
  COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_invalid.hpp.in ${CBD}/GenFile.hpp
  COMMAND ${CMAKE_COMMAND} -E sleep 3
  COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_valid.hpp.in ${CBD}/GenFile.hpp)

add_executable(mocDepGenFile testGenFile.cpp ${CBD}/GenFile.hpp)
target_link_libraries(mocDepGenFile ${QT_QTCORE_TARGET})
set_target_properties(mocDepGenFile PROPERTIES AUTOMOC TRUE)


# -- Test dependency on header generating custom 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 mocDepTarget_autogen target of
# mocDepTarget to the utility target mocDepTargetUtil.
# If mocDepTarget_autogen gets built *before* or in *parallel* to
# mocDepTargetUtil, the build will fail. That's
# because GenTarget.hpp, which is required by mocDepTarget_autogen,
# is only valid after the mocDepTargetUtil build has been completed.
#
# The sleep seconds artificially increase the build time of mocDepTargetUtil
# to simulate a slow utility target build that takes longer to run than
# the build of the mocDepTarget_autogen target.
add_custom_target(mocDepTargetUtil
  BYPRODUCTS ${CBD}/GenTarget.hpp
  COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_invalid.hpp.in ${CBD}/GenTarget.hpp
  COMMAND ${CMAKE_COMMAND} -E sleep 3
  COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_valid.hpp.in ${CBD}/GenTarget.hpp)

add_executable(mocDepTarget testGenTarget.cpp)
target_link_libraries(mocDepTarget ${QT_QTCORE_TARGET})
set_target_properties(mocDepTarget PROPERTIES AUTOMOC TRUE)
add_dependencies(mocDepTarget mocDepTargetUtil)


# -- 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 mocDepGenLib_autogen target of mocDepGenLib
# to the user generated library SimpleLib, which mocDepGenLib links to.
# If mocDepGenLib_autogen gets built *before* or in *parallel* to SimpleLib,
# the build will fail. That's because simpleLib.hpp, which is required by
# mocDepGenLib_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 mocDepGenLib_autogen target.
add_custom_command(
  OUTPUT ${CBD}/simpleLib.hpp ${CBD}/simpleLib.cpp
  COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_invalid.hpp.in ${CBD}/simpleLib.hpp
  COMMAND ${CMAKE_COMMAND} -E sleep 3
  COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/simpleLib.hpp.in ${CBD}/simpleLib.hpp
  COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/simpleLib.cpp.in ${CBD}/simpleLib.cpp)
add_library(SimpleLib STATIC ${CBD}/simpleLib.hpp ${CBD}/simpleLib.cpp)
target_link_libraries(SimpleLib ${QT_QTCORE_TARGET})

add_executable(mocDepGenLib testGenLib.cpp)
target_link_libraries(mocDepGenLib SimpleLib ${QT_QTCORE_TARGET})
set_target_properties(mocDepGenLib PROPERTIES AUTOMOC TRUE)


# -- Test AUTOGEN_TARGET_DEPENDS with GENERATED file dependency
#
# This tests the dependency of the mocDepATDFile_autogen target of
# mocDepATDTarget to the utility target mocDepATDFileUtil.
# If mocDepATDFile_autogen gets built *before* or in *parallel* to
# mocDepATDFileUtil, the build will fail. That's
# because ATDFile.hpp, which is required by mocDepATDFile_autogen,
# is only valid after the mocDepATDFileUtil build has been completed.
#
# The sleep seconds artificially increase the build time of
# mocDepATDFileUtil to simulate a slow utility target build that takes
# longer to run than the build of the mocDepATDFile_autogen target.
add_custom_command(
  OUTPUT ${CBD}/ATDFile.hpp
  COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_invalid.hpp.in ${CBD}/ATDFile.hpp
  COMMAND ${CMAKE_COMMAND} -E sleep 3
  COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_valid.hpp.in ${CBD}/ATDFile.hpp)

add_executable(mocDepATDFile testATDFile.cpp)
target_link_libraries(mocDepATDFile ${QT_QTCORE_TARGET})
set_target_properties(mocDepATDFile PROPERTIES AUTOMOC TRUE)
set_target_properties(mocDepATDFile PROPERTIES AUTOGEN_TARGET_DEPENDS ${CBD}/ATDFile.hpp)


# -- Test AUTOGEN_TARGET_DEPENDS with target dependency
#
# This tests the dependency of the mocDepATDTarget_autogen target of
# mocDepATDTarget to the utility target mocDepATDTargetUtil.
# If mocDepATDTarget_autogen gets built *before* or in *parallel* to
# mocDepATDTargetUtil, the build will fail. That's
# because ATDTarget.hpp, which is required by mocDepATDTarget_autogen,
# is only valid after the mocDepATDTargetUtil build has been completed.
#
# The sleep seconds artificially increase the build time of
# mocDepATDTargetUtil to simulate a slow utility target build that takes
# longer to run than the build of the mocDepATDTarget_autogen target.
add_custom_target(mocDepATDTargetUtil
  BYPRODUCTS ${CBD}/ATDTarget.hpp
  COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_invalid.hpp.in ${CBD}/ATDTarget.hpp
  COMMAND ${CMAKE_COMMAND} -E sleep 3
  COMMAND ${CMAKE_COMMAND} -E copy ${CSD}/object_valid.hpp.in ${CBD}/ATDTarget.hpp)

add_executable(mocDepATDTarget testATDTarget.cpp)
target_link_libraries(mocDepATDTarget ${QT_QTCORE_TARGET})
set_target_properties(mocDepATDTarget PROPERTIES AUTOMOC TRUE)
set_target_properties(mocDepATDTarget PROPERTIES AUTOGEN_TARGET_DEPENDS mocDepATDTargetUtil)