Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Tests / RunCMake / VsDotnetSdk / VsDotnetSdkDefines-check.cmake
1 #
2 # Check C# VS project for required elements.
3 #
4 set(csProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.csproj")
5 if(NOT EXISTS "${csProjectFile}")
6   set(RunCMake_TEST_FAILED "Project file ${csProjectFile} does not exist.")
7   return()
8 endif()
9
10
11 set(inDebug FALSE)
12 set(inRelease FALSE)
13 set(debugOK FALSE)
14 set(releaseOK FALSE)
15
16
17 file(STRINGS "${csProjectFile}" lines)
18 foreach(line IN LISTS lines)
19   #message(STATUS ${line})
20   if(line MATCHES "^ *<PropertyGroup .*Debug.*")
21     set(inDebug TRUE)
22   elseif(line MATCHES "^ *<PropertyGroup .*Release.*")
23     set(inRelease TRUE)
24   elseif(line MATCHES "^ *</PropertyGroup> *$")
25     set(inRelease FALSE)
26     set(inDebug  FALSE)
27   elseif(inDebug AND
28      (line MATCHES "^ *<DefineConstants>.*MY_FOO_DEFINE.*</DefineConstants> *$") AND
29      (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_DEBUG.*</DefineConstants> *$") AND
30      (NOT (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_RELEASE.*</DefineConstants> *$")) AND
31      (NOT (line MATCHES "^ *<DefineConstants>.*MY_BAR_ASSIGNMENT=bar.*</DefineConstants> *$"))
32     )
33     set(debugOK TRUE)
34   elseif(inRelease AND
35      (line MATCHES "^ *<DefineConstants>.*MY_FOO_DEFINE.*</DefineConstants> *$") AND
36      (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_RELEASE.*</DefineConstants> *$") AND
37      (NOT (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_DEBUG.*</DefineConstants> *$")) AND
38      (NOT (line MATCHES "^ *<DefineConstants>.*MY_BAR_ASSIGNMENT=bar.*</DefineConstants> *$"))
39     )
40     set(releaseOK TRUE)
41   endif()
42 endforeach()
43
44 function(print_csprojfile)
45   file(STRINGS "${csProjectFile}" lines)
46   foreach(line IN LISTS lines)
47     message(STATUS ${line})
48   endforeach()
49 endfunction()
50
51
52 if(NOT debugOK)
53   message(STATUS "Failed to set Debug configuration defines correctly.")
54   set(RunCMake_TEST_FAILED "Failed to set Debug configuration defines correctly.")
55   print_csprojfile()
56   return()
57 endif()
58
59 if(NOT releaseOK)
60   message(STATUS "Failed to set Release configuration defines correctly.")
61   set(RunCMake_TEST_FAILED "Failed to set Release configuration defines correctly.")
62   print_csprojfile()
63   return()
64 endif()