Debian Codegraph @

Tests/RunCMake/GenerateExportHeader/GEH-failures.cmake

raw
1 set(failure_test_executables
2 ${CMAKE_CURRENT_BINARY_DIR}/failure_test_targets)
3 file(WRITE ${failure_test_executables} "")
4
5 # Check if we should do anything. If the compiler doesn't support hidden
6 # visibility, the failure tests won't fail, so just write an empty targets
7 # list and punt.
8 if(NOT WIN32 AND NOT CYGWIN AND NOT COMPILER_HAS_HIDDEN_VISIBILITY)
9 return()
10 endif()
11
12 # Read the input source file
13 file(READ ${CMAKE_CURRENT_SOURCE_DIR}/exportheader_test.cpp content_post)
14 set(content_pre "")
15
16 # Generate source files for failure test executables
17 set(counter 0)
18 while(1)
19 # Find first occurrence of link error marker in remaining content
20 string(REGEX MATCH "//([^;\n]+;) LINK ERROR( [(][^)]+[)])?\n(.*)"
21 match "${content_post}")
22 if(match STREQUAL "")
23 # No more matches
24 break()
25 endif()
26
27 # Shift content buffers and extract failing statement
28 string(LENGTH "${content_post}" content_post_length)
29 string(LENGTH "${match}" matched_length)
30 math(EXPR shift_length "${content_post_length} - ${matched_length}")
31
32 string(SUBSTRING "${content_post}" 0 ${shift_length} shift)
33 set(content_pre "${content_pre}${shift}")
34 set(content_post "${CMAKE_MATCH_3}")
35 set(content_active "//${CMAKE_MATCH_1} LINK ERROR${CMAKE_MATCH_2}")
36 set(statement "${CMAKE_MATCH_1}")
37
38 # Check if potential error is conditional, and evaluate condition if so
39 string(REGEX REPLACE " [(]([^)]+)[)]" "\\1" condition "${CMAKE_MATCH_2}")
40 if(NOT condition STREQUAL "")
41 string(REGEX REPLACE " +" ";" condition "${condition}")
42 if(${condition})
43 else()
44 message(STATUS "Not testing '${statement}'; "
45 "condition (${condition}) is FALSE")
46 set(content_pre "${content_pre}// link error removed\n")
47 continue()
48 endif()
49 endif()
50
51 if(NOT skip)
52 message(STATUS "Creating failure test for '${statement}'")
53 math(EXPR counter "${counter} + 1")
54
55 # Write new source file
56 set(out ${CMAKE_CURRENT_BINARY_DIR}/exportheader_failtest-${counter}.cpp)
57 file(WRITE ${out} "${content_pre}${statement}\n${content_post}")
58
59 # Add executable for failure test
60 add_executable(GEH-fail-${counter} EXCLUDE_FROM_ALL ${out})
61 target_link_libraries(GEH-fail-${counter} ${link_libraries})
62 file(APPEND ${failure_test_executables} "GEH-fail-${counter}\n")
63 endif()
64
65 # Add placeholder where failing statement was removed
66 set(content_pre "${content_pre}${content_active}\n")
67 endwhile()