aboutsummaryrefslogtreecommitdiff
path: root/tests/ECMGenerateHeadersTest/run_test.cmake.config
blob: a9027dbc2516a6bdf8f6bbcef9ce2fd3507364b6 (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
set(CMAKE_MODULE_PATH "@MODULES_DIR@")
set(CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
set(CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@")

include(ECMGenerateHeaders)
include(CMakeParseArguments)

function (check_files)
    set(options)
    set(oneValueArgs GENERATED ORIGINALS)
    set(multiValueArgs)
    cmake_parse_arguments(CF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
    list(LENGTH CF_GENERATED count)
    foreach(i RANGE ${count})
        list(GET CF_GENERATED 0 generated_file)
        list(GET CF_ORIGINALS 0 original_file)
        if (NOT EXISTS "${generated_file}")
            message(FATAL_ERROR "${generated_file} was not generated")
        endif()
        file(READ "${generated_file}" file_contents)
        string(STRIP "${file_contents}" file_contents)
        set (exp_contents "#include \"${original_file}\"")
        if (NOT "${file_contents}" STREQUAL "${exp_contents}")
            message(FATAL_ERROR "${generated_file} contains '${file_contents}' instead of '${exp_contents}'")
        endif()
    endforeach()
endfunction()

###########################################################

message(STATUS "Test 1: no optional arguments")
set(camelcase_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest1"
             "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2")
set(origfiles headtest1.h headtest2.h)
file(REMOVE ${expfiles})
ecm_generate_headers(
    camelcase_headers
    HEADER_NAMES HeadTest1 HeadTest2
)
if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
    message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${origfiles})


###########################################################

message(STATUS "Test 2: RELATIVE")
set(camelcase_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2"
             "${CMAKE_CURRENT_BINARY_DIR}/HeadTest3")
set(origfiles headtest2.h headtest3.h)
file(REMOVE ${expfiles})
ecm_generate_headers(
    camelcase_headers
    HEADER_NAMES HeadTest2 HeadTest3
    RELATIVE headsubdir
)
if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
    message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${origfiles})


###########################################################

message(STATUS "Test 3: OUTPUT_DIR")
set(camelcase_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/testdir/HeadTest1"
             "${CMAKE_CURRENT_BINARY_DIR}/testdir/HeadTest2")
set(origfiles headtest1.h headtest2.h)
file(REMOVE ${expfiles})
ecm_generate_headers(
    camelcase_headers
    HEADER_NAMES HeadTest1 HeadTest2
    OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/testdir"
)
if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
    message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${origfiles})


###########################################################

message(STATUS "Test 4: PREFIX")
set(camelcase_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/Module/HeadTest1"
             "${CMAKE_CURRENT_BINARY_DIR}/Module/HeadTest2")
set(intermediatefiles module/headtest1.h module/headtest2.h)
set(origfiles "${CMAKE_CURRENT_SOURCE_DIR}/headtest1.h"
              "${CMAKE_CURRENT_SOURCE_DIR}/headtest2.h")
file(REMOVE ${expfiles} ${intermediatefiles})
ecm_generate_headers(
    camelcase_headers
    HEADER_NAMES HeadTest1 HeadTest2
    PREFIX Module
)
if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
    message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${intermediatefiles})
check_files(GENERATED ${expfiles}
            ORIGINALS ${intermediatefiles})


###########################################################

message(STATUS "Test 5: REQUIRED_HEADERS")
set(camelcase_headers)
set(req_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest1"
             "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2")
set(origfiles headtest1.h headtest2.h)
set(origpaths "${CMAKE_CURRENT_SOURCE_DIR}/headtest1.h"
              "${CMAKE_CURRENT_SOURCE_DIR}/headtest2.h")
file(REMOVE ${expfiles})
ecm_generate_headers(
    camelcase_headers
    HEADER_NAMES HeadTest1 HeadTest2
    REQUIRED_HEADERS req_headers
)
if (NOT "${origpaths}" STREQUAL "${req_headers}")
    message(FATAL_ERROR "REQUIRED_HEADERS var was set to \"${req_headers}\" instead of \"${origpaths}\"")
endif()
if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
    message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${origfiles})


###########################################################

message(STATUS "Test 6: RELATIVE and REQUIRED_HEADERS")
set(camelcase_headers)
set(req_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2"
             "${CMAKE_CURRENT_BINARY_DIR}/HeadTest3")
set(origfiles headtest2.h headtest3.h)
set(origpaths "${CMAKE_CURRENT_SOURCE_DIR}/headsubdir/headtest2.h"
              "${CMAKE_CURRENT_SOURCE_DIR}/headsubdir/headtest3.h")
file(REMOVE ${expfiles})
ecm_generate_headers(
    camelcase_headers
    HEADER_NAMES HeadTest2 HeadTest3
    RELATIVE headsubdir
    REQUIRED_HEADERS req_headers
)
if (NOT "${origpaths}" STREQUAL "${req_headers}")
    message(FATAL_ERROR "REQUIRED_HEADERS var was set to \"${req_headers}\" instead of \"${origpaths}\"")
endif()
if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
    message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${origfiles})


###########################################################

message(STATUS "Test 7: OUTPUT_DIR and REQUIRED_HEADERS")
set(camelcase_headers)
set(req_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/testdir/HeadTest1"
             "${CMAKE_CURRENT_BINARY_DIR}/testdir/HeadTest2")
set(origfiles headtest1.h headtest2.h)
set(origpaths "${CMAKE_CURRENT_SOURCE_DIR}/headtest1.h"
              "${CMAKE_CURRENT_SOURCE_DIR}/headtest2.h")
file(REMOVE ${expfiles})
ecm_generate_headers(
    camelcase_headers
    HEADER_NAMES HeadTest1 HeadTest2
    OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/testdir"
    REQUIRED_HEADERS req_headers
)
if (NOT "${origpaths}" STREQUAL "${req_headers}")
    message(FATAL_ERROR "REQUIRED_HEADERS var was set to \"${req_headers}\" instead of \"${origpaths}\"")
endif()
if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
    message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${origfiles})


###########################################################

message(STATUS "Test 8: PREFIX and REQUIRED_HEADERS")
set(camelcase_headers)
set(req_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/Module/HeadTest1"
             "${CMAKE_CURRENT_BINARY_DIR}/Module/HeadTest2")
set(intermediatefiles module/headtest1.h module/headtest2.h)
set(origfiles "${CMAKE_CURRENT_SOURCE_DIR}/headtest1.h"
              "${CMAKE_CURRENT_SOURCE_DIR}/headtest2.h")
set(origpaths ${origfiles})
file(REMOVE ${expfiles} ${intermediatefiles})
ecm_generate_headers(
    camelcase_headers
    HEADER_NAMES HeadTest1 HeadTest2
    PREFIX Module
    REQUIRED_HEADERS req_headers
)
if (NOT "${origpaths}" STREQUAL "${req_headers}")
    message(FATAL_ERROR "REQUIRED_HEADERS var was set to \"${req_headers}\" instead of \"${origpaths}\"")
endif()
if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
    message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${intermediatefiles})
check_files(GENERATED ${expfiles}
            ORIGINALS ${intermediatefiles})


###########################################################

message(STATUS "Test 9: REQUIRED_HEADERS (duplicate var)")
set(all_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest1"
             "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2")
set(origfiles headtest1.h headtest2.h)
set(origpaths "${CMAKE_CURRENT_SOURCE_DIR}/headtest1.h"
              "${CMAKE_CURRENT_SOURCE_DIR}/headtest2.h")
file(REMOVE ${expfiles})
ecm_generate_headers(
    all_headers
    HEADER_NAMES HeadTest1 HeadTest2
    REQUIRED_HEADERS all_headers
)
list(SORT all_headers)
set(exp_headers ${expfiles} ${origpaths})
list(SORT exp_headers)
if (NOT "${exp_headers}" STREQUAL "${all_headers}")
    message(FATAL_ERROR "combined headers var was set to \"${all_headers}\" instead of \"${exp_headers}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${origfiles})


###########################################################

message(STATUS "Test 10: ORIGINAL CAMELCASE")
set(forward_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/CamelCaseHeadTest1"
             "${CMAKE_CURRENT_BINARY_DIR}/CamelCaseHeadTest2")
set(origfiles CamelCaseHeadTest1.h CamelCaseHeadTest2.h)
file(REMOVE ${expfiles})
ecm_generate_headers(
    forward_headers
    ORIGINAL CAMELCASE
    HEADER_NAMES CamelCaseHeadTest1 CamelCaseHeadTest2
)
if (NOT "${expfiles}" STREQUAL "${forward_headers}")
    message(FATAL_ERROR "forward_headers was set to \"${forward_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${origfiles})


###########################################################

message(STATUS "Test 11: PREFIX and ORIGINAL CAMELCASE")
set(forward_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/Module/CamelCaseHeadTest1"
             "${CMAKE_CURRENT_BINARY_DIR}/Module/CamelCaseHeadTest2")
set(intermediatefiles Module/CamelCaseHeadTest1.h Module/CamelCaseHeadTest2.h)
set(origfiles "${CMAKE_CURRENT_SOURCE_DIR}/headtest1.h"
              "${CMAKE_CURRENT_SOURCE_DIR}/headtest2.h")
file(REMOVE ${expfiles} ${intermediatefiles})
ecm_generate_headers(
    forward_headers
    ORIGINAL CAMELCASE
    HEADER_NAMES CamelCaseHeadTest1 CamelCaseHeadTest2
    PREFIX Module
)
if (NOT "${expfiles}" STREQUAL "${forward_headers}")
    message(FATAL_ERROR "forward_headers was set to \"${forward_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${intermediatefiles})
check_files(GENERATED ${expfiles}
            ORIGINALS ${intermediatefiles})

###########################################################

message(STATUS "Test 12: COMMON_HEADER")

set(camelcase_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest1"
             "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2"
             "${CMAKE_CURRENT_BINARY_DIR}/HeadTest4"
             "${CMAKE_CURRENT_BINARY_DIR}/CommonHeader")
set(origfiles headtest1.h headtest2.h)
file(REMOVE ${expfiles})
ecm_generate_headers(
    camelcase_headers
    ORIGINAL LOWERCASE
    HEADER_NAMES HeadTest1 HeadTest2 HeadTest4
    COMMON_HEADER CommonHeader
)
if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
    message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${origfiles})

file(READ CommonHeader file_contents)
string(STRIP "${file_contents}" file_contents)
file(READ "${CMAKE_CURRENT_BINARY_DIR}/CommonHeader" exp_contents)
string(STRIP "${exp_contents}" exp_contents)
if (NOT "${file_contents}" STREQUAL "${exp_contents}")
    message(FATAL_ERROR "${generated_file} contains '${file_contents}' instead of '${exp_contents}'")
endif()


###########################################################

message(STATUS "Test 13: multiple classes and COMMON_HEADER")

set(camelcase_headers)
set(expfiles "${CMAKE_CURRENT_BINARY_DIR}/HeadTest1"
             "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2"
             "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2Add1"
             "${CMAKE_CURRENT_BINARY_DIR}/HeadTest2Add2"
             "${CMAKE_CURRENT_BINARY_DIR}/HeadTest4"
             "${CMAKE_CURRENT_BINARY_DIR}/CommonHeader")
set(origfiles headtest1.h headtest2.h headtest4.h)
file(REMOVE ${expfiles})
ecm_generate_headers(
    camelcase_headers
    ORIGINAL LOWERCASE
    HEADER_NAMES HeadTest1 HeadTest2,HeadTest2Add1,HeadTest2Add2 HeadTest4
    COMMON_HEADER CommonHeader
)
if (NOT "${expfiles}" STREQUAL "${camelcase_headers}")
    message(FATAL_ERROR "camelcase_headers was set to \"${camelcase_headers}\" instead of \"${expfiles}\"")
endif()
check_files(GENERATED ${expfiles}
            ORIGINALS ${origfiles})

file(READ CommonHeader file_contents)
string(STRIP "${file_contents}" file_contents)
file(READ "${CMAKE_CURRENT_BINARY_DIR}/CommonHeader" exp_contents)
string(STRIP "${exp_contents}" exp_contents)
if (NOT "${file_contents}" STREQUAL "${exp_contents}")
    message(FATAL_ERROR "${generated_file} contains '${file_contents}' instead of '${exp_contents}'")
endif()


# vim:ft=cmake