blob: 76dbdf50e64ca9f8ab69d760c9f21b75a9a674fa (
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
cmake_minimum_required(VERSION 3.16)
project(RerunMocBasic)
include("../AutogenCoreTest.cmake")
# Dummy executable to generate a clean target
add_executable(dummy dummy.cpp)
# Utility variables
set(timeformat "%Y.%j.%H.%M%S")
set(mocBasicSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/MocBasic")
set(mocBasicBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocBasic")
# Utility macros
macro(sleep)
message(STATUS "Sleeping for a few seconds.")
execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
endmacro()
macro(acquire_timestamp When)
file(TIMESTAMP "${mocBasicBin}" time${When} "${timeformat}")
endmacro()
macro(rebuild buildName)
message(STATUS "Starting build ${buildName}.")
execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocBasicBinDir}" RESULT_VARIABLE result)
if (result)
message(FATAL_ERROR "Build ${buildName} failed.")
else()
message(STATUS "Build ${buildName} finished.")
endif()
endmacro()
macro(require_change)
if (timeAfter VERSION_GREATER timeBefore)
message(STATUS "As expected the file ${mocBasicBin} changed.")
else()
message(SEND_ERROR "Unexpectedly the file ${mocBasicBin} did not change!\nTimestamp pre: ${timeBefore}\nTimestamp aft: ${timeAfter}\n")
endif()
endmacro()
macro(require_change_not)
if (timeAfter VERSION_GREATER timeBefore)
message(SEND_ERROR "Unexpectedly the file ${mocBasicBin} changed!\nTimestamp pre: ${timeBefore}\nTimestamp aft: ${timeAfter}\n")
else()
message(STATUS "As expected the file ${mocBasicBin} did not change.")
endif()
endmacro()
# Configure the test project
configure_file("${mocBasicSrcDir}/test1a.h.in" "${mocBasicBinDir}/test1.h" COPYONLY)
configure_file("${mocBasicSrcDir}/myobject3a.h.in" "${mocBasicBinDir}/myobject3.h" @ONLY)
if(CMAKE_GENERATOR_INSTANCE)
set(_D_CMAKE_GENERATOR_INSTANCE "-DCMAKE_GENERATOR_INSTANCE=${CMAKE_GENERATOR_INSTANCE}")
else()
set(_D_CMAKE_GENERATOR_INSTANCE "")
endif()
execute_process(
COMMAND "${CMAKE_COMMAND}" -B "${mocBasicBinDir}" -S "${mocBasicSrcDir}"
-G "${CMAKE_GENERATOR}"
-A "${CMAKE_GENERATOR_PLATFORM}"
-T "${CMAKE_GENERATOR_TOOLSET}"
${_D_CMAKE_GENERATOR_INSTANCE}
"-DQT_TEST_VERSION=${QT_TEST_VERSION}"
"-DCMAKE_AUTOGEN_VERBOSE=${CMAKE_AUTOGEN_VERBOSE}"
"-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}"
"-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
RESULT_VARIABLE exit_code
OUTPUT_VARIABLE output
)
if(NOT exit_code EQUAL 0)
message(FATAL_ERROR "Initial configuration of mocBasic failed. Output: ${output}")
endif()
# Initial build
execute_process(
COMMAND "${CMAKE_COMMAND}" --build "${mocBasicBinDir}"
RESULT_VARIABLE exit_code
OUTPUT_VARIABLE output
)
if(NOT exit_code EQUAL 0)
message(FATAL_ERROR "Initial build of mocBasic failed. Output: ${output}")
endif()
# Get name of the output binary
file(STRINGS "${mocBasicBinDir}/mocBasic.txt" mocBasicList ENCODING UTF-8)
list(GET mocBasicList 0 mocBasicBin)
# To avoid a race condition where the binary has the same timestamp
# as a source file and therefore gets rebuild
# - sleep to ensure a timestamp change
# - touch binary to ensure it has a new timestamp
acquire_timestamp(Before)
sleep()
message(STATUS "Touching binary file to ensure a new timestamps")
file(TOUCH_NOCREATE "${mocBasicBin}")
acquire_timestamp(After)
require_change()
# - Ensure that the timestamp will change
# - Change header file content
# - Rebuild
acquire_timestamp(Before)
sleep()
message(STATUS "Changing the header content for a MOC re-run")
configure_file("${mocBasicSrcDir}/test1b.h.in" "${mocBasicBinDir}/test1.h" COPYONLY)
sleep()
rebuild(2)
acquire_timestamp(After)
require_change()
# - Ensure that the timestamp would change
# - Change nothing
# - Rebuild
acquire_timestamp(Before)
sleep()
message(STATUS "Changing nothing for no MOC re-run")
rebuild(3)
acquire_timestamp(After)
require_change_not()
# - Ensure that the timestamp will change
# - Remove Q_OBJECT from header
# - Rebuild
acquire_timestamp(Before)
sleep()
message(STATUS "Remove Q_OBJECT from header file for a MOC re-run")
configure_file("${mocBasicSrcDir}/test1c.h.in" "${mocBasicBinDir}/test1.h" COPYONLY)
sleep()
rebuild(4)
acquire_timestamp(After)
require_change()
# - Ensure that the timestamp will change
# - Add Q_OBJECT to header again
# - Rebuild
acquire_timestamp(Before)
sleep()
message(STATUS "Add Q_OBJECT to test1.h for a MOC re-run")
configure_file("${mocBasicSrcDir}/test1a.h.in" "${mocBasicBinDir}/test1.h" COPYONLY)
sleep()
rebuild(5)
acquire_timestamp(After)
require_change()
# - Ensure that the timestamp will change
# - Add Q_OBJECT to MyObject3
# - Rebuild
acquire_timestamp(Before)
sleep()
message(STATUS "Add Q_OBJECT to myobject3.h file for a MOC re-run")
set(CLASS_CONTENT "Q_OBJECT")
configure_file("${mocBasicSrcDir}/myobject3a.h.in" "${mocBasicBinDir}/myobject3.h" @ONLY)
sleep()
rebuild(6)
acquire_timestamp(After)
require_change()
|