summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/add_custom_command/RemoveEmptyCommands-check.cmake
blob: b2970444e99c3f67e5d067759a933fae9ce416b9 (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
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/exe.vcxproj")
if(NOT EXISTS "${vcProjectFile}")
  set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
  return()
endif()

set(inGroup FALSE)
set(inCommand FALSE)

set(expected_Debug
  "cmd_1 cmd_1_arg"
  "cmd_1_dbg cmd_1_dbg_arg"
  "cmd_2_dbg cmd_2_dbg_arg"
  "cmd_3_dbg cmd_3_dbg_arg")

set(expected_Release
  "cmd_1 cmd_1_arg"
  "cmd_3_rel cmd_3_rel_arg")

# extract build events
file(STRINGS "${vcProjectFile}" lines)
foreach(line IN LISTS lines)
  if(line MATCHES "^ *<ItemDefinitionGroup Condition=.*Configuration.*Platform.*>$")
    set(inGroup TRUE)
    string(REGEX MATCH "=='(.*)\\|(.*)'" out ${line})
    set(config ${CMAKE_MATCH_1})
  elseif(line MATCHES "^ *</ItemDefinitionGroup>$")
    set(inGroup FALSE)
  elseif(inGroup)
    if(line MATCHES "^ *<Command>.*$")
      set(inCommand TRUE)
      string(REGEX MATCH "<Command>(.*)" cmd ${line})
      set(currentCommand ${CMAKE_MATCH_1})
    elseif(line MATCHES "^(.*)</Command>$")
      string(REGEX MATCH "(.*)</Command>" cmd ${line})
      list(APPEND currentCommand ${CMAKE_MATCH_1})
      set(command_${config} ${currentCommand})
      set(inCommand FALSE)
    elseif(inCommand)
      list(APPEND currentCommand ${line})
    endif()
  endif()
endforeach()

foreach(config "Debug" "Release")
  set(currentName command_${config})
  set(expectedName expected_${config})
  set(strippedCommand "")
  if(DEFINED ${currentName})
    foreach(v ${${currentName}})
      if(${v} MATCHES "cmd_")
        list(APPEND strippedCommand ${v})
      endif()
    endforeach()
    if(NOT "${strippedCommand}" STREQUAL
      "${${expectedName}}")
      message(" - ${strippedCommand}")
      message(" + ${${expectedName}}")
      set(RunCMake_TEST_FAILED "build event command does not match")
      return()
    endif()
  endif()
endforeach()