File: VsToolOverride-check.cmake

package info (click to toggle)
cmake 4.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 152,456 kB
  • sloc: ansic: 403,896; cpp: 303,920; sh: 4,105; python: 3,583; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 111; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (64 lines) | stat: -rw-r--r-- 2,463 bytes parent folder | download | duplicates (5)
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
# Figure out which build tool the test files in a project are using
macro(get_build_tools_from_project_file projectFile)
  set(_s "[ \t\r\n]")   # Whitespace character class

  set(ItemGroupBeginRegex "<${_s}*ItemGroup${_s}*>")
  set(ItemGroupEndRegex "</${_s}*ItemGroup${_s}*>")
  set(GroupItemRegex ".*<${_s}*([A-Za-z0-9_]+)${_s}+Include${_s}*=${_s}*\"([^\"]*)\".*")

  if(NOT EXISTS "${projectFile}")
    set(RunCMake_TEST_FAILED "Project file ${projectFile} does not exist.")
    return()
  endif()

  file(STRINGS "${projectFile}" lines)

  foreach(line IN LISTS lines)
    if(line MATCHES "${ItemGroupBeginRegex}")
      set(InItemGroup TRUE)
    elseif(line MATCHES "${ItemGroupEndRegex}")
      set(InItemGroup FALSE)
    elseif(line MATCHES "${GroupItemRegex}")
      if(InItemGroup)
        string(REGEX REPLACE "${GroupItemRegex}" "\\1" itemTool "${line}")
        string(REGEX REPLACE "${GroupItemRegex}" "\\2" itemPath "${line}")

        if(itemPath MATCHES ".*foo\\.cpp")
          set(fooCppTool "${itemTool}")
        elseif(itemPath MATCHES ".*foo\\.txt")
          set(fooTxtTool "${itemTool}")
        elseif(itemPath MATCHES ".*bar\\.cpp")
          set(barCppTool "${itemTool}")
        elseif(itemPath MATCHES ".*bar\\.txt")
          set(barTxtTool "${itemTool}")
        endif()
      endif()
    endif()
  endforeach()
endmacro()

# Verify a build tool is as expected
macro(verify_build_tool fileName expectedBuildTool actualBuildTool)
  if("${actualBuildTool}" STREQUAL "${expectedBuildTool}")
    message(STATUS "File '${fileName}' in project file '${projectFile}' has expected build tool '${expectedBuildTool}'")
  else()
    set(RunCMake_TEST_FAILED "File '${fileName}' in project file '${projectFile}' has unexpected build tool '${actualBuildTool}'! Expected: '${expectedBuildTool}'" PARENT_SCOPE)
    return()
  endif()
endmacro()

# Test using VS_TOOL_OVERRIDE
block()
  set(projectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
  get_build_tools_from_project_file("${projectFile}")
  verify_build_tool("foo.cpp" "CustomFooCppTool" "${fooCppTool}")
  verify_build_tool("foo.txt" "CustomFooTxtTool" "${fooTxtTool}")
endblock()

# Test default behavior without using VS_TOOL_OVERRIDE
block()
  set(projectFile "${RunCMake_TEST_BINARY_DIR}/bar.vcxproj")
  get_build_tools_from_project_file("${projectFile}")
  verify_build_tool("bar.cpp" "ClCompile" "${barCppTool}")
  verify_build_tool("bar.txt" "None" "${barTxtTool}")
endblock()