summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/VsDotnetSdk/VsDotnetSdkDefines-check.cmake
blob: eaeba2439410ac023c37a7c48f8d19d202a8304f (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
#
# Check C# VS project for required elements.
#
set(csProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.csproj")
if(NOT EXISTS "${csProjectFile}")
  set(RunCMake_TEST_FAILED "Project file ${csProjectFile} does not exist.")
  return()
endif()


set(inDebug FALSE)
set(inRelease FALSE)
set(debugOK FALSE)
set(releaseOK FALSE)


file(STRINGS "${csProjectFile}" lines)
foreach(line IN LISTS lines)
  #message(STATUS ${line})
  if(line MATCHES "^ *<PropertyGroup .*Debug.*")
    set(inDebug TRUE)
  elseif(line MATCHES "^ *<PropertyGroup .*Release.*")
    set(inRelease TRUE)
  elseif(line MATCHES "^ *</PropertyGroup> *$")
    set(inRelease FALSE)
    set(inDebug  FALSE)
  elseif(inDebug AND
     (line MATCHES "^ *<DefineConstants>.*MY_FOO_DEFINE.*</DefineConstants> *$") AND
     (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_DEBUG.*</DefineConstants> *$") AND
     (NOT (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_RELEASE.*</DefineConstants> *$")) AND
     (NOT (line MATCHES "^ *<DefineConstants>.*MY_BAR_ASSIGNMENT=bar.*</DefineConstants> *$"))
    )
    set(debugOK TRUE)
  elseif(inRelease AND
     (line MATCHES "^ *<DefineConstants>.*MY_FOO_DEFINE.*</DefineConstants> *$") AND
     (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_RELEASE.*</DefineConstants> *$") AND
     (NOT (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_DEBUG.*</DefineConstants> *$")) AND
     (NOT (line MATCHES "^ *<DefineConstants>.*MY_BAR_ASSIGNMENT=bar.*</DefineConstants> *$"))
    )
    set(releaseOK TRUE)
  endif()
endforeach()

function(print_csprojfile)
  file(STRINGS "${csProjectFile}" lines)
  foreach(line IN LISTS lines)
    message(STATUS ${line})
  endforeach()
endfunction()


if(NOT debugOK)
  message(STATUS "Failed to set Debug configuration defines correctly.")
  set(RunCMake_TEST_FAILED "Failed to set Debug configuration defines correctly.")
  print_csprojfile()
  return()
endif()

if(NOT releaseOK)
  message(STATUS "Failed to set Release configuration defines correctly.")
  set(RunCMake_TEST_FAILED "Failed to set Release configuration defines correctly.")
  print_csprojfile()
  return()
endif()