-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
1327 lines (1022 loc) · 55.4 KB
/
CMakeLists.txt
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# /CMakeLists.txt
#
# Main entry point for PolysquareToolingUtil tests.
#
# See /LICENCE.md for Copyright information
include ("${CMAKE_CURRENT_LIST_DIR}/conanbuildinfo.cmake")
set (CMAKE_MODULE_PATH
${CONAN_CMAKE_MODULE_PATH} # NOLINT:correctness/quotes
${CMAKE_MODULE_PATH}) # NOLINT:correctness/quotes
cmake_minimum_required (VERSION 2.8)
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR};${CMAKE_MODULE_PATH}")
set (_CURRENT_LIST_FILE "${CMAKE_CURRENT_LIST_FILE}")
include ("cmake/cmake-module-common/Common" OPTIONAL)
include (PolysquareToolingUtil)
# Checks that our ON command line switch for a variable being true is added.
function (psq_test_add_switch_off)
function (psq_configure)
set (OPTION_IS_OFF OFF)
psq_add_switch (OPTIONS OPTION_IS_OFF ON --on OFF --off)
cmake_unit_assert_that (OPTIONS
list_contains_value STRING EQUAL "--off")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Checks that our ON command line switch for a variable being true is added.
function (psq_test_add_switch_on)
function (psq_configure)
set (OPTION_IS_ON ON)
psq_add_switch (OPTIONS OPTION_IS_ON ON --on OFF --off)
cmake_unit_assert_that (OPTIONS
list_contains_value STRING EQUAL "--on")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Checks that our list elements got added to the GLOBAL_PROPERTY
# global property.
function (psq_test_append_each_to_global_property)
function (psq_configure)
set (LIST_ELEMENTS ONE TWO)
psq_append_to_global_property (GLOBAL_PROPERTY LIST ${LIST_ELEMENTS})
cmake_unit_assert_that (GLOBAL item_has_property_containing_value
GLOBAL GLOBAL_PROPERTY STRING EQUAL ONE)
cmake_unit_assert_that (GLOBAL item_has_property_containing_value
GLOBAL GLOBAL_PROPERTY STRING EQUAL TWO)
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Checks that our list elements got added to the GLOBAL_PROPERTY
# global property.
function (psq_test_append_each_to_global_property_unique)
function (psq_configure)
set (LIST_ELEMENTS ONE ONE)
psq_append_to_global_property_unique (GLOBAL_PROPERTY
LIST ${LIST_ELEMENTS})
get_property (GLOBAL_PROPERTY_LIST GLOBAL PROPERTY GLOBAL_PROPERTY)
list (LENGTH GLOBAL_PROPERTY_LIST GLOBAL_PROPERTY_LIST_LENGTH)
cmake_unit_assert_that (GLOBAL_PROPERTY_LIST_LENGTH
compare_as INTEGER EQUAL 1)
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Checks that our list elements got added to the list with PREFIX before them.
function (psq_test_append_each_to_options_with_prefix)
function (psq_configure)
set (LIST_ELEMENTS ONE TWO)
psq_append_each_to_options_with_prefix (OPTIONS PREFIX
LIST ${LIST_ELEMENTS})
cmake_unit_assert_that (OPTIONS
list_contains_value STRING EQUAL PREFIXONE)
cmake_unit_assert_that (OPTIONS
list_contains_value STRING EQUAL PREFIXTWO)
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Adds some source files, including a source file which is not a valid
# compilation unit or header source at all. The configure step should succeed.
function (psq_test_extraneous_non_header_sources_not_scanned)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
set (SOURCE_DIR "${SOURCE_DIR}")
set (BINARY_DIR "${BINARY_DIR}")
set (CXX_SOURCE_FILE "Source.cpp")
set (CXX_SOURCE_FILE_PATH "${SOURCE_DIR}/${CXX_SOURCE_FILE}")
set (EXTRANEOUS_FILE "${BINARY_DIR}/Extraneous.nonstandard")
cmake_unit_create_source_file_before_build (NAME
"${CXX_SOURCE_FILE}"
FUNCTIONS main
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
file (WRITE "${EXTRANEOUS_FILE}" "")
set (TARGET executable)
add_executable (${TARGET}
"${CXX_SOURCE_FILE_PATH}"
"${EXTRANEOUS_FILE}")
psq_strip_extraneous_sources (FILTERED_SOURCES ${TARGET})
psq_sort_sources_to_languages (C_SOURCES CXX_SOURCES HEADERS
SOURCES ${FILTERED_SOURCES})
cmake_unit_assert_that (C_SOURCES not list_contains_value
STRING EQUAL "${EXTRANEOUS_FILE}")
cmake_unit_assert_that (CXX_SOURCES not list_contains_value
STRING EQUAL "${EXTRANEOUS_FILE}")
cmake_unit_assert_that (HEADERS not list_contains_value
STRING EQUAL "${EXTRANEOUS_FILE}")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure
INVOKE_CONFIGURE OPTIONS
LANGUAGES
C
CXX)
endfunction ()
# Tests that we can filter out generated sources added with
# add_custom_command.
function (psq_test_filter_out_generated_sources)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
set (SOURCE_FILE "${BINARY_DIR}/Source.cpp")
set (GENERATED_FILE "${BINARY_DIR}/Generated.cpp")
add_custom_command (OUTPUT "${GENERATED_FILE}"
COMMAND
"${CMAKE_COMMAND}"
-E
touch
"${GENERATED_FILE}")
psq_filter_out_generated_sources (FILTERED_SOURCES
SOURCES "${SOURCE_FILE}"
"${GENERATED_FILE}")
cmake_unit_assert_that (FILTERED_SOURCES
list_contains_value STRING EQUAL
"${SOURCE_FILE}")
cmake_unit_assert_that (FILTERED_SOURCES not list_contains_value
STRING EQUAL "${GENERATED_FILE}")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Checks that some multi-variable arguments passed in to a function with
# an argument prefix PREFIX get re-added to the forward options list
# as MUTLIVAR_ARGUMENT_NAME;Argument1;Argument2; etc.
function (psq_test_forward_multivar_args)
function (psq_configure)
set (PASSED_ARGUMENTS_ONE Argument1)
set (PASSED_ARGUMENTS_TWO Argument2)
set (PASSED_ARGUMENTS ${PASSED_ARGUMENTS_ONE} ${PASSED_ARGUMENTS_TWO})
function (psq_called_function)
cmake_parse_arguments (PREFIX "" "" "MULTIVAR_ARGUMENT_NAME"
${ARGN})
psq_forward_options (PREFIX
FORWARD_OPTIONS
MULTIVAR_ARGS MULTIVAR_ARGUMENT_NAME)
cmake_unit_assert_that (FORWARD_OPTIONS list_contains_value
STRING EQUAL MULTIVAR_ARGUMENT_NAME)
cmake_unit_assert_that (FORWARD_OPTIONS list_contains_value
STRING EQUAL ${PASSED_ARGUMENTS_ONE})
cmake_unit_assert_that (FORWARD_OPTIONS list_contains_value
STRING EQUAL ${PASSED_ARGUMENTS_TWO})
endfunction ()
psq_called_function (MULTIVAR_ARGUMENT_NAME ${PASSED_ARGUMENTS})
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Checks that option arguments passed to a function get put back into the
# forward options list with their original name, but only if they were
# set
function (psq_test_forward_option_args)
function (psq_configure)
function (psq_called_function)
set (OPTION_ARGS PASSED NOT_PASSED)
cmake_parse_arguments (PREFIX "${OPTION_ARGS}" "" "" ${ARGN})
psq_forward_options (PREFIX
FORWARD_OPTIONS OPTION_ARGS ${OPTION_ARGS})
cmake_unit_assert_that (FORWARD_OPTIONS
list_contains_value STRING EQUAL PASSED)
cmake_unit_assert_that (FORWARD_OPTIONS not list_contains_value
STRING EQUAL NOT_PASSED)
endfunction ()
psq_called_function (PASSED)
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Checks that some single-variable arguments passed in to a function with
# an argument prefix PREFIX get re-added to the forward options list
# as SINGLEVAR_ARGUMENT_NAME_PASSED;Argument1 etc and
# SINGLEVAR_ARGUMENT_NAME_NOT_PASSED is not present in the forward options.
function (psq_test_forward_singlevar_args)
function (psq_configure)
set (PASSED_ARGUMENT Argument)
function (psq_called_function)
set (SINGLEVAR_ARGS SINGLEVAR_ARGUMENT_NAME_PASSED
SINGLEVAR_ARGUMENT_NAME_NOT_PASSED)
cmake_parse_arguments (PREFIX "" "${SINGLEVAR_ARGS}" "" ${ARGN})
psq_forward_options (PREFIX
FORWARD_OPTIONS
SINGLEVAR_ARGS ${SINGLEVAR_ARGS})
cmake_unit_assert_that (FORWARD_OPTIONS list_contains_value
STRING EQUAL SINGLEVAR_ARGUMENT_NAME_PASSED)
cmake_unit_assert_that (FORWARD_OPTIONS list_contains_value
STRING EQUAL ${PASSED_ARGUMENT})
cmake_unit_assert_that (FORWARD_OPTIONS not list_contains_value
STRING EQUAL
SINGLEVAR_ARGUMENT_NAME_NOT_PASSED)
endfunction ()
psq_called_function (SINGLEVAR_ARGUMENT_NAME_PASSED ${PASSED_ARGUMENT})
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Gets the intersection between lists A_LIST and B_LIST. Checks that only
# items contained in both are in DESTINATION_LIST
function (psq_test_get_list_intersection)
function (psq_configure)
set (A_LIST A B C)
set (B_LIST B C D)
psq_get_list_intersection (DESTINATION_LIST
SOURCE ${A_LIST}
INTERSECTION ${B_LIST})
message (STATUS "Interseciton was ${DESTINATION_LIST}")
cmake_unit_assert_that (DESTINATION_LIST list_contains_value
STRING EQUAL B)
cmake_unit_assert_that (DESTINATION_LIST list_contains_value
STRING EQUAL C)
cmake_unit_assert_that (DESTINATION_LIST not list_contains_value
STRING EQUAL A)
cmake_unit_assert_that (DESTINATION_LIST not list_contains_value
STRING EQUAL D)
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Adds a binary and calls psq_get_target_command_attach_point
# on it. The result should be PRE_BUILD as opposed to PRE_LINK.
function (psq_test_get_target_attach_point_for_binary_pre_link)
function (psq_configure)
cmake_unit_create_simple_executable (executable
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
psq_get_target_command_attach_point (executable WHEN)
cmake_unit_assert_that (WHEN compare_as STRING EQUAL "PRE_LINK")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure
INVOKE_CONFIGURE OPTIONS
LANGUAGES
C
CXX)
endfunction ()
# Adds a library and calls psq_get_target_command_attach_point
# on it. The result should be PRE_BUILD as opposed to PRE_LINK.
function (psq_test_get_target_attach_point_for_library_pre_link)
function (psq_configure)
cmake_unit_create_simple_library (library SHARED
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
psq_get_target_command_attach_point (library WHEN)
cmake_unit_assert_that (WHEN compare_as STRING EQUAL "PRE_LINK")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure
INVOKE_CONFIGURE OPTIONS
LANGUAGES
C
CXX)
endfunction ()
# Adds a custom target and calls psq_get_target_command_attach_point
# on it. The result should be PRE_BUILD as opposed to PRE_LINK.
function (psq_test_get_target_attach_point_for_utility_pre_build)
function (psq_configure)
add_custom_target (my_custom_target ALL)
psq_get_target_command_attach_point (my_custom_target WHEN)
cmake_unit_assert_that (WHEN compare_as STRING EQUAL "PRE_BUILD")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Tests that we can filter out generated sources added with
# add_custom_command if CHECK_GENERATED was not passed to
# psq_handle_check_generated_option
function (psq_test_handle_check_generated_option_filter)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
set (SOURCE_FILE "${BINARY_DIR}/Source.cpp")
set (GENERATED_FILE "${BINARY_DIR}/Generated.cpp")
add_custom_command (OUTPUT "${GENERATED_FILE}"
COMMAND "${CMAKE_COMMAND}"
-E
touch
"${GENERATED_FILE}")
function (psq_add_tooling)
cmake_parse_arguments (PREFIX "CHECK_GENERATED" "" "" ${ARGN})
psq_handle_check_generated_option (PREFIX FILTERED_SOURCES
SOURCES "${SOURCE_FILE}"
"${GENERATED_FILE}")
cmake_unit_assert_that (FILTERED_SOURCES list_contains_value
STRING EQUAL "${SOURCE_FILE}")
cmake_unit_assert_that (FILTERED_SOURCES not list_contains_value
STRING EQUAL "${GENERATED_FILE}")
endfunction ()
psq_add_tooling ()
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Tests that we can filter out generated sources added with
# add_custom_command if CHECK_GENERATED was not passed to
# psq_handle_check_generated_option
function (psq_test_handle_check_generated_option_no_filter)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
set (SOURCE_FILE "${BINARY_DIR}/Source.cpp")
set (GENERATED_FILE "${BINARY_DIR}/Generated.cpp")
add_custom_command (OUTPUT "${GENERATED_FILE}"
COMMAND "${CMAKE_COMMAND}"
-E
touch
"${GENERATED_FILE}")
function (psq_add_tooling)
cmake_parse_arguments (PREFIX "CHECK_GENERATED" "" "" ${ARGN})
psq_handle_check_generated_option (PREFIX FILTERED_SOURCES
SOURCES "${SOURCE_FILE}"
"${GENERATED_FILE}")
cmake_unit_assert_that (FILTERED_SOURCES list_contains_value
STRING EQUAL "${SOURCE_FILE}")
cmake_unit_assert_that (FILTERED_SOURCES list_contains_value
STRING EQUAL "${GENERATED_FILE}")
endfunction ()
psq_add_tooling (CHECK_GENERATED)
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Helper macro to generate a header and source file as
# well as a corresponding compilation database. Extra
# arguments get passed to psq_make_compilation_db.
macro (psq_make_sources_and_compilation_db SOURCE_NAME LANGUAGE)
set (HEADER_FILE "Header.h")
set (HEADER_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FILE}")
cmake_unit_create_source_file_before_build (NAME "${HEADER_FILE}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
set (SOURCE_FILE_NAME "${SOURCE_NAME}")
set (SOURCE_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE_NAME}")
cmake_unit_create_source_file_before_build (NAME "${SOURCE_FILE_NAME}"
FUNCTIONS main
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
set (TARGET target)
add_custom_target (${TARGET} ALL
SOURCES "${SOURCE_FILE_PATH}" "${HEADER_FILE_PATH}")
psq_make_compilation_db (${TARGET} COMPILATION_DB_DIR
${LANGUAGE}_SOURCES
"${SOURCE_FILE_PATH}"
"${HEADER_FILE_PATH}"
INTERNAL_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}"
${ARGN})
endmacro ()
# Helper macro to call psq_run_tool_for_each_source
# on both a generated and a pre-existing source
function (psq_run_tool_on_generated_sources)
set (SOURCE_FILE_NAME "Source.cpp")
set (SOURCE_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE_NAME}")
cmake_unit_create_source_file_before_build (NAME "${SOURCE_FILE_NAME}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
set (GENERATED_FILE_NAME "Generated.cpp")
set (GENERATED_FILE_PATH
"${CMAKE_CURRENT_BINARY_DIR}/${GENERATED_FILE_NAME}")
cmake_unit_generate_source_file_during_build (TARGET
NAME "${GENERATED_FILE_NAME}")
add_custom_target (target ALL
SOURCES "${SOURCE_FILE_PATH}" "${GENERATED_FILE_PATH}")
psq_run_tool_for_each_source (target
"Tool"
COMMAND "${CMAKE_COMMAND}"
-E
touch
${ARGN})
endfunction ()
# Helper macro to add call psq_run_tool_on_source for a
# pre-existing source.
function (psq_run_tool_on_preexisting_source TOOL_NAME)
set (SOURCE_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Source.cpp")
set (STAMP_FILE_PATH "${CMAKE_CURRENT_BINARY_DIR}/Source.cpp")
cmake_unit_create_source_file_before_build (NAME "${SOURCE_FILE}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
add_custom_target (target ALL SOURCES "${SOURCE_FILE_PATH}")
psq_run_tool_on_source (target "${SOURCE_FILE_PATH}" "${TOOL_NAME}"
COMMAND "${CMAKE_COMMAND}"
-E
touch
"${STAMP_FILE_PATH}.ToolRun")
endfunction ()
# Adds a custom target with a source and calls psq_run_tool_on_source
# on it (the "tool" in this case being ${CMAKE_COMMAND} -E touch
# /${SOURCE_FILE}.ToolRun)
function (psq_test_run_tool_on_source)
function (psq_configure)
psq_run_tool_on_preexisting_source ("ool")
endfunction ()
function (psq_verify)
cmake_unit_get_log_for (INVOKE_BUILD OUTPUT BUILD_OUTPUT)
cmake_unit_escape_string (ESCAPED_CMAKE_COMMAND "${CMAKE_COMMAND}")
set (TOOL_COMMAND_REGEX
"^.*${ESCAPED_CMAKE_COMMAND} -E touch .*Source.cpp.ToolRun*$")
cmake_unit_assert_that ("${BUILD_OUTPUT}"
file_contents any_line matches_regex
"${TOOL_COMMAND_REGEX}")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure)
endfunction ()
# Adds a custom target with a source and calls psq_run_tool_on_source
# on it (the "tool" in this case being ${CMAKE_COMMAND} -E touch
# /${SOURCE_FILE}.ToolRun) and
# add a custom target "custom_dependency" not put on ALL to DEPENDS
function (psq_test_run_tool_on_source_after_depends)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
set (SOURCE_FILE_NAME "Source.cpp")
set (SOURCE_FILE_PATH "${SOURCE_DIR}/${SOURCE_FILE_NAME}")
set (STAMP_FILE_PATH "${BINARY_DIR}/${SOURCE_FILE_NAME}")
cmake_unit_create_source_file_before_build (NAME "${SOURCE_FILE_NAME}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
add_custom_target (custom_dependency
COMMAND cmake -E echo "ran custom_dependency")
add_custom_target (target ALL SOURCES "${SOURCE_FILE_PATH}")
psq_run_tool_on_source (target "${SOURCE_FILE_PATH}" "Tool"
COMMAND "${CMAKE_COMMAND}"
-E
touch
"${STAMP_FILE_PATH}.ToolRun"
DEPENDS custom_dependency)
endfunction ()
function (psq_verify)
cmake_unit_get_log_for (INVOKE_BUILD OUTPUT BUILD_OUTPUT)
message (STATUS "Reading ${BUILD_OUTPUT}")
cmake_unit_assert_that (${BUILD_OUTPUT}
file_contents any_line matches_regex
"^.*custom_dependency*$")
endfunction ()
cmake_unit_configure_test (CONFIGURE COMMAND psq_configure
VERIFY COMMAND psq_verify
INVOKE_CONFIGURE OPTIONS LANGUAGES C CXX)
endfunction ()
# Adds a custom target with a source and calls psq_run_tool_on_source
# on it (the "tool" in this case being ${CMAKE_COMMAND} -E touch
# /${SOURCE_FILE}.ToolRun)
function (psq_test_run_tool_on_source_generates_stampfile)
function (psq_configure)
psq_run_tool_on_preexisting_source ("Tool")
endfunction ()
function (psq_verify)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
cmake_unit_assert_that ("${BINARY_DIR}/Source.cpp.Tool.stamp"
exists_as_file)
endfunction ()
cmake_unit_configure_test (CONFIGURE COMMAND psq_configure
VERIFY COMMAND psq_verify
INVOKE_CONFIGURE OPTIONS LANGUAGES C CXX)
endfunction ()
# Adds a custom target with a source and calls psq_run_tool_on_source
# on it (the "tool" in this case being ${CMAKE_COMMAND} -E
# touch /${SOURCE_FILE}.ToolRun)
# and the tool name being "tool (tool)"
function (psq_test_run_tool_on_source_generates_stampfile_with_spaces)
function (psq_configure)
psq_run_tool_on_preexisting_source ("tool (tool)")
endfunction ()
function (psq_verify)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
cmake_unit_assert_that ("${BINARY_DIR}/Source.cpp.tool (tool).stamp"
exists_as_file)
endfunction ()
cmake_unit_configure_test (CONFIGURE COMMAND psq_configure
VERIFY COMMAND psq_verify)
endfunction ()
# Adds a custom target with a source and calls psq_run_tool_on_source
# on it (the "tool" in this case being ${CMAKE_COMMAND} -E touch
# ${SOURCE_FILE}.ToolRun)
function (psq_test_run_tool_on_source_has_comment)
function (psq_configure)
psq_run_tool_on_preexisting_source ("Tool")
endfunction ()
function (psq_verify)
cmake_unit_get_log_for (INVOKE_BUILD OUTPUT BUILD_OUTPUT)
cmake_unit_assert_that (${BUILD_OUTPUT}
file_contents any_line matches_regex
"^.*Analyzing.*Source.cpp.* with Tool.*$")
endfunction ()
cmake_unit_configure_test (PRECONFIGURE OPTIONS
SKIP_GENERATOR_REGEX
"^.*Ninja.*$"
CONFIGURE COMMAND psq_configure
VERIFY COMMAND psq_verify
INVOKE_CONFIGURE OPTIONS LANGUAGES C CXX)
endfunction ()
# Adds a custom target with two sources and calls psq_run_tool_for_each_source
# on it (the "tool" in this case being ${CMAKE_COMMAND} -E touch
# /${SOURCE}.ToolRun)
function (psq_test_run_tool_on_sources)
function (psq_configure)
set (SOURCE_FILE_NAME "Source.cpp")
set (OTHER_SOURCE_FILE_NAME "Other.cpp")
cmake_unit_create_source_file_before_build (NAME "${SOURCE_FILE_NAME}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
cmake_unit_create_source_file_before_build (NAME
"${OTHER_SOURCE_FILE_NAME}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
add_custom_target (target ALL
SOURCES "${SOURCE_FILE_NAME}"
"${OTHER_SOURCE_FILE_NAME}")
psq_run_tool_for_each_source (target "Tool"
COMMAND "${CMAKE_COMMAND}"
-E
touch
endfunction ()
function (psq_verify)
cmake_unit_get_log_for (INVOKE_BUILD OUTPUT BUILD_OUTPUT)
cmake_unit_escape_string (ESCAPED_CMAKE_COMMAND "${CMAKE_COMMAND}")
set (TOOL_SOURCE_COMMAND_REGEX
"^.*${ESCAPED_CMAKE_COMMAND} -E touch .*Source.cpp.ToolRun*$")
cmake_unit_assert_that (${BUILD_OUTPUT}
file_contents any_line matches_regex
"${TOOL_SOURCE_COMMAND_REGEX}")
cmake_unit_escape_string (ESCAPED_CMAKE_COMMAND "${CMAKE_COMMAND}")
set (TOOL_OTHER_COMMAND_REGEX
"^.*${ESCAPED_CMAKE_COMMAND} -E touch .*Other.cpp.ToolRun*$")
cmake_unit_assert_that ("${BUILD_OUTPUT}"
file_contents any_line matches_regex
"${TOOL_OTHER_COMMAND_REGEX}")
endfunction ()
cmake_unit_configure_test (CONFIGURE COMMAND psq_configure
VERIFY COMMAND psq_verify
INVOKE_CONFIGURE OPTIONS LANGUAGES C CXX)
endfunction ()
# Adds a custom target with a normal and generated source and calls
# psq_run_tool_for_each_source on it (the "tool" in this case being
# ${CMAKE_COMMAND} -E touch /${SOURCE}.ToolRun). Pass CHECK_GENERATED to
# psq_run_tool_for_each_source
function (psq_test_run_tool_check_generated)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
psq_run_tool_on_generated_sources (CHECK_GENERATED)
endfunction ()
function (psq_verify)
cmake_unit_get_log_for (INVOKE_BUILD OUTPUT BUILD_OUTPUT)
cmake_unit_escape_string (ESCAPED_CMAKE_COMMAND "${CMAKE_COMMAND}")
set (TOOL_COMMAND_REGEX
"^.*${ESCAPED_CMAKE_COMMAND} -E touch .*Source.cpp.ToolRun*$")
cmake_unit_assert_that (${BUILD_OUTPUT}
file_contents any_line matches_regex
"${TOOL_COMMAND_REGEX}")
cmake_unit_assert_that (${BUILD_OUTPUT}
file_contents any_line matches_regex
"^.*-E touch .*Generated.cpp.ToolRun*$")
file (REMOVE "${SOURCE_DIR}/Source.cpp.ToolRun")
endfunction ()
cmake_unit_configure_test (CONFIGURE COMMAND psq_configure
VERIFY COMMAND psq_verify
INVOKE_CONFIGURE OPTIONS LANGUAGES C CXX)
endfunction ()
# Adds a custom target with a normal and generated source and calls
# psq_run_tool_for_each_source on it (the "tool" in this case being
# ${CMAKE_COMMAND} -E touch /${SOURCE}.ToolRun)
function (psq_test_run_tool_filter_generated)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
psq_run_tool_on_generated_sources ()
endfunction ()
function (psq_verify)
cmake_unit_get_log_for (INVOKE_BUILD OUTPUT BUILD_OUTPUT)
cmake_unit_escape_string (ESCAPED_CMAKE_COMMAND "${CMAKE_COMMAND}")
set (TOOL_COMMAND_REGEX
"^.*${ESCAPED_CMAKE_COMMAND} .*touch .*Source.cpp.ToolRun*$")
cmake_unit_assert_that (${BUILD_OUTPUT}
file_contents any_line matches_regex
"${TOOL_COMMAND_REGEX}")
cmake_unit_assert_that ("${BUILD_OUTPUT}"
not file_contents any_line matches_regex
"^.*touch .*Generated.cpp.ToolRun*$")
file (REMOVE "${SOURCE_DIR}/Source.cpp.ToolRun")
endfunction ()
cmake_unit_configure_test (CONFIGURE COMMAND psq_configure
VERIFY COMMAND psq_verify
INVOKE_CONFIGURE OPTIONS LANGUAGES C CXX)
endfunction ()
# Checks that C headers are put in C_SOURCES when calling
# psq_sort_sources_to_languages
function (psq_test_sort_c_headers_to_c)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
set (HEADER_FILE "Header.h")
set (HEADER_FILE_PATH "${SOURCE_DIR}/${HEADER_FILE}")
cmake_unit_create_source_file_before_build (NAME "${HEADER_FILE}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
set (CXX_SOURCE_FILE "Source.cpp")
set (CXX_SOURCE_FILE_PATH "${SOURCE_DIR}/${CXX_SOURCE_FILE}")
cmake_unit_create_source_file_before_build (NAME "${CXX_SOURCE_FILE}"
INCLUDES
"${HEADER_FILE_PATH}"
INCLUDE_DIRECTORIES
"${SOURCE_DIR}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
set (C_SOURCE_FILE "Source.c")
set (C_SOURCE_FILE_PATH "${SOURCE_DIR}/${C_SOURCE_FILE}")
cmake_unit_create_source_file_before_build (NAME "${C_SOURCE_FILE}"
INCLUDES
"${HEADER_FILE_PATH}"
INCLUDE_DIRECTORIES
"${SOURCE_DIR}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
psq_sort_sources_to_languages (C_SOURCES CXX_SOURCES HEADERS
SOURCES "${C_SOURCE_FILE_PATH}"
"${CXX_SOURCE_FILE_PATH}"
"${HEADER_FILE_PATH}"
INCLUDES "${SOURCE_DIR}")
cmake_unit_assert_that (C_SOURCES list_contains_value
STRING EQUAL "${HEADER_FILE_PATH}")
cmake_unit_assert_that (CXX_SOURCES not list_contains_value
STRING EQUAL "${HEADER_FILE_PATH}")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure
INVOKE_CONFIGURE OPTIONS
LANGUAGES
C
CXX)
endfunction ()
# Checks that C headers are put in CXX_SOURCES when calling
# psq_sort_sources_to_languages with CPP_IDENTIFIERS that this header has.
function (psq_test_sort_c_headers_to_cxx_and_c_with_cpp_identifiers)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
set (HEADER_FILE "Header.h")
set (HEADER_FILE_PATH "${SOURCE_DIR}/${HEADER_FILE}")
cmake_unit_create_source_file_before_build (NAME "${HEADER_FILE}"
DEFINES IS_CPP_AND_C
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
set (CXX_SOURCE_FILE "Source.cpp")
set (CXX_SOURCE_FILE_PATH "${SOURCE_DIR}/${CXX_SOURCE_FILE}")
cmake_unit_create_source_file_before_build (NAME "${CXX_SOURCE_FILE}"
INCLUDES
"${HEADER_FILE_PATH}"
INCLUDE_DIRECTORIES
"${SOURCE_DIR}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
set (C_SOURCE_FILE "Source.c")
set (C_SOURCE_FILE_PATH "${SOURCE_DIR}/${C_SOURCE_FILE}")
cmake_unit_create_source_file_before_build (NAME "${C_SOURCE_FILE}"
INCLUDES
"${HEADER_FILE_PATH}"
INCLUDE_DIRECTORIES
"${SOURCE_DIR}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
psq_sort_sources_to_languages (C_SOURCES CXX_SOURCES HEADERS
SOURCES "${C_SOURCE_FILE_PATH}"
"${CXX_SOURCE_FILE_PATH}"
"${HEADER_FILE_PATH}"
INCLUDES "${SOURCE_DIR}"
CPP_IDENTIFIERS IS_CPP_AND_C)
cmake_unit_assert_that (CXX_SOURCES list_contains_value
STRING EQUAL "${HEADER_FILE_PATH}")
cmake_unit_assert_that (C_SOURCES list_contains_value
STRING EQUAL "${HEADER_FILE_PATH}")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure
INVOKE_CONFIGURE OPTIONS
LANGUAGES
C
CXX)
endfunction ()
# Checks that C headers are put in CXX_SOURCES when calling
# psq_sort_sources_to_languages with FORCE_LANGUAGE CXX
function (psq_test_sort_c_headers_to_cxx_force_language)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
set (HEADER_FILE "Header.h")
set (HEADER_FILE_PATH "${SOURCE_DIR}/${HEADER_FILE}")
cmake_unit_create_source_file_before_build (NAME "${HEADER_FILE}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
set (CXX_SOURCE_FILE "Source.cpp")
set (CXX_SOURCE_FILE_PATH
"${SOURCE_DIR}/${CXX_SOURCE_FILE}")
cmake_unit_create_source_file_before_build (NAME "${CXX_SOURCE_FILE}"
INCLUDES "${HEADER_FILE}"
INCLUDE_DIRECTORIES
"${SOURCE_DIR}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
set (C_SOURCE_FILE "Source.c")
set (C_SOURCE_FILE_PATH "${SOURCE_DIR}/${C_SOURCE_FILE}")
cmake_unit_create_source_file_before_build (NAME "${C_SOURCE_FILE}"
INCLUDES
"${HEADER_FILE_PATH}"
INCLUDE_DIRECTORIES
"${SOURCE_DIR}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
psq_sort_sources_to_languages (C_SOURCES CXX_SOURCES HEADERS
SOURCES "${C_SOURCE_FILE_PATH}"
"${CXX_SOURCE_FILE_PATH}"
"${HEADER_FILE_PATH}"
INCLUDES "${SOURCE_DIR}"
FORCE_LANGUAGE CXX)
cmake_unit_assert_that (CXX_SOURCES list_contains_value
STRING EQUAL "${HEADER_FILE_PATH}")
cmake_unit_assert_that (HEADERS list_contains_value
STRING EQUAL "${HEADER_FILE_PATH}")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure
INVOKE_CONFIGURE OPTIONS
LANGUAGES
C
CXX)
endfunction ()
# Checks that C sources are put in C_SOURCES when calling
# psq_sort_sources_to_languages
function (psq_test_sort_c_sources_to_c)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
set (SOURCE_FILE_NAME "Source.c")
set (SOURCE_FILE_PATH "${SOURCE_DIR}/${SOURCE_FILE_NAME}")
cmake_unit_create_source_file_before_build (NAME "${SOURCE_FILE_NAME}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
psq_sort_sources_to_languages (C_SOURCES CXX_SOURCES HEADERS
SOURCES "${SOURCE_FILE_PATH}")
cmake_unit_assert_that (C_SOURCES list_contains_value
STRING EQUAL "${SOURCE_FILE_PATH}")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure
INVOKE_CONFIGURE OPTIONS
LANGUAGES
C
CXX)
endfunction ()
# Checks that CXX headers are put in CXX_SOURCES when calling
# psq_sort_sources_to_languages
function (psq_test_sort_cxx_headers_to_cxx)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
set (HEADER_FILE "Header.h")
set (HEADER_FILE_PATH "${SOURCE_DIR}/${HEADER_FILE}")
cmake_unit_create_source_file_before_build (NAME "${HEADER_FILE}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
set (SOURCE_FILE_NAME "Source.cpp")
set (SOURCE_FILE_PATH "${SOURCE_DIR}/${SOURCE_FILE_NAME}")
cmake_unit_create_source_file_before_build (NAME "${SOURCE_FILE_NAME}"
INCLUDES
"${HEADER_FILE_PATH}"
INCLUDE_DIRECTORIES
"${SOURCE_DIR}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")
psq_sort_sources_to_languages (C_SOURCES CXX_SOURCES HEADERS
SOURCES "${SOURCE_FILE_PATH}"
"${HEADER_FILE_PATH}"
INCLUDES "${SOURCE_DIR}")
cmake_unit_assert_that (CXX_SOURCES list_contains_value
STRING EQUAL "${HEADER_FILE_PATH}")
endfunction ()
cmake_unit_configure_config_only_test (CONFIGURE COMMAND psq_configure
INVOKE_CONFIGURE OPTIONS
LANGUAGES
C
CXX)
endfunction ()
# Checks that CXX sources are put in CXX_SOURCES when calling
# psq_sort_sources_to_languages
function (psq_test_sort_cxx_sources_to_cxx)
cmake_unit_get_dirs (BINARY_DIR SOURCE_DIR)
function (psq_configure)
set (SOURCE_FILE_NAME "Source.cpp")
set (SOURCE_FILE_PATH "${SOURCE_DIR}/${SOURCE_FILE_NAME}")
cmake_unit_create_source_file_before_build (NAME "${SOURCE_FILE_NAME}"
GENERATING_FILE
"${_CURRENT_LIST_FILE}")