Browse Source

Merge topic 'msvc-showIncludes'

8f82e755f3 Ninja: Fix detection of MSVC showIncludes prefix in Italian
d6e7e4d4a1 Tests: Extend RunCMake.Ninja ShowIncludes cases to cover more languages
9596305c0b Tests: Generalize RunCMake.Ninja ShowIncludes test infrastructure
c6dd4fa21d Tests: Extend RunCMake.Ninja ShowIncludes case with sample path
a9d97492fd Ninja: Record showIncludes detection in configure log

Acked-by: Kitware Robot <[email protected]>
Merge-request: !8129
Brad King 2 years ago
parent
commit
1c4825066b
35 changed files with 153 additions and 19 deletions
  1. 7 1
      Modules/CMakeDetermineCompilerId.cmake
  2. 3 0
      Tests/RunCMake/CMakeLists.txt
  3. 11 2
      Tests/RunCMake/Ninja/RunCMakeTest.cmake
  4. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-437-English-check.cmake
  5. 1 0
      Tests/RunCMake/Ninja/ShowIncludes-437-English-stdout.txt
  6. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-437-English.cmake
  7. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-437-French-check.cmake
  8. 1 0
      Tests/RunCMake/Ninja/ShowIncludes-437-French-stdout.txt
  9. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-437-French.cmake
  10. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-437-German-check.cmake
  11. 1 0
      Tests/RunCMake/Ninja/ShowIncludes-437-German-stdout.txt
  12. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-437-German.cmake
  13. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-437-Italian-check.cmake
  14. 1 0
      Tests/RunCMake/Ninja/ShowIncludes-437-Italian-stdout.txt
  15. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-437-Italian.cmake
  16. 1 1
      Tests/RunCMake/Ninja/ShowIncludes-54936-Chinese-check.cmake
  17. 1 0
      Tests/RunCMake/Ninja/ShowIncludes-54936-Chinese-stdout.txt
  18. 1 0
      Tests/RunCMake/Ninja/ShowIncludes-54936-Chinese.cmake
  19. 0 1
      Tests/RunCMake/Ninja/ShowIncludes-54936-stdout.txt
  20. 1 1
      Tests/RunCMake/Ninja/ShowIncludes-65001-Chinese-check.cmake
  21. 1 0
      Tests/RunCMake/Ninja/ShowIncludes-65001-Chinese-stdout.txt
  22. 1 0
      Tests/RunCMake/Ninja/ShowIncludes-65001-Chinese.cmake
  23. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-65001-French-check.cmake
  24. 1 0
      Tests/RunCMake/Ninja/ShowIncludes-65001-French-stdout.txt
  25. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-65001-French.cmake
  26. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-65001-Japanese-check.cmake
  27. 1 0
      Tests/RunCMake/Ninja/ShowIncludes-65001-Japanese-stdout.txt
  28. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-65001-Japanese.cmake
  29. 0 1
      Tests/RunCMake/Ninja/ShowIncludes-65001-stdout.txt
  30. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-932-Japanese-check.cmake
  31. 1 0
      Tests/RunCMake/Ninja/ShowIncludes-932-Japanese-stdout.txt
  32. 3 0
      Tests/RunCMake/Ninja/ShowIncludes-932-Japanese.cmake
  33. 4 0
      Tests/RunCMake/Ninja/ShowIncludes-cmake.cmake
  34. 1 1
      Tests/RunCMake/Ninja/ShowIncludes.cmake
  35. 72 11
      Tests/RunCMake/showIncludes.c

+ 7 - 1
Modules/CMakeDetermineCompilerId.cmake

@@ -219,6 +219,9 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
       AND MSVC_${lang}_ARCHITECTURE_ID)
     foreach(userflags "${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}" "")
       CMAKE_DETERMINE_MSVC_SHOWINCLUDES_PREFIX(${lang} "${userflags}")
+      if(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX)
+        break()
+      endif()
     endforeach()
   else()
     set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "")
@@ -1140,9 +1143,12 @@ function(CMAKE_DETERMINE_MSVC_SHOWINCLUDES_PREFIX lang userflags)
     RESULT_VARIABLE res
     ENCODING AUTO # cl prints in console output code page
     )
-  if(res EQUAL 0 AND "${out}" MATCHES "(^|\n)([^:\n]*:[^:\n]*:[ \t]*)")
+  string(REPLACE "\n" "\n  " msg "  ${out}")
+  if(res EQUAL 0 AND "${out}" MATCHES "(^|\n)([^:\n][^:\n]+:[^:\n]*[^: \n][^: \n]:?[ \t]+)[A-Za-z]:\\\\")
     set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "${CMAKE_MATCH_2}" PARENT_SCOPE)
+    string(APPEND msg "\nFound prefix \"${CMAKE_MATCH_2}\"")
   else()
     set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "" PARENT_SCOPE)
   endif()
+  message(CONFIGURE_LOG "Detecting ${lang} compiler /showIncludes prefix:\n${msg}\n")
 endfunction()

+ 3 - 0
Tests/RunCMake/CMakeLists.txt

@@ -200,6 +200,9 @@ if(CMAKE_GENERATOR MATCHES "Ninja")
   if(WIN32)
     add_executable(showIncludes showIncludes.c)
     list(APPEND Ninja_ARGS -DshowIncludes=$<TARGET_FILE:showIncludes>)
+    if(CMake_TEST_NO_CODEPAGE_9xx)
+      list(APPEND Ninja_ARGS -DCMake_TEST_NO_CODEPAGE_9xx=1)
+    endif()
   endif()
   add_RunCMake_test(Ninja)
   set(NinjaMultiConfig_ARGS

+ 11 - 2
Tests/RunCMake/Ninja/RunCMakeTest.cmake

@@ -46,8 +46,17 @@ if(WIN32)
   if(RunCMake_MAKE_PROGRAM)
     set(maybe_MAKE_PROGRAM "-DRunCMake_MAKE_PROGRAM=${RunCMake_MAKE_PROGRAM}")
   endif()
-  run_cmake_script(ShowIncludes-54936 -DshowIncludes=${showIncludes} ${maybe_MAKE_PROGRAM})
-  run_cmake_script(ShowIncludes-65001 -DshowIncludes=${showIncludes} ${maybe_MAKE_PROGRAM})
+  run_cmake_script(ShowIncludes-437-English -DshowIncludes=${showIncludes} ${maybe_MAKE_PROGRAM})
+  run_cmake_script(ShowIncludes-437-French -DshowIncludes=${showIncludes} ${maybe_MAKE_PROGRAM})
+  run_cmake_script(ShowIncludes-437-German -DshowIncludes=${showIncludes} ${maybe_MAKE_PROGRAM})
+  run_cmake_script(ShowIncludes-437-Italian -DshowIncludes=${showIncludes} ${maybe_MAKE_PROGRAM})
+  run_cmake_script(ShowIncludes-54936-Chinese -DshowIncludes=${showIncludes} ${maybe_MAKE_PROGRAM})
+  run_cmake_script(ShowIncludes-65001-Chinese -DshowIncludes=${showIncludes} ${maybe_MAKE_PROGRAM})
+  run_cmake_script(ShowIncludes-65001-French -DshowIncludes=${showIncludes} ${maybe_MAKE_PROGRAM})
+  run_cmake_script(ShowIncludes-65001-Japanese -DshowIncludes=${showIncludes} ${maybe_MAKE_PROGRAM})
+  if(NOT CMake_TEST_NO_CODEPAGE_9xx)
+    run_cmake_script(ShowIncludes-932-Japanese -DshowIncludes=${showIncludes} ${maybe_MAKE_PROGRAM})
+  endif()
   unset(maybe_MAKE_PROGRAM)
 endif()
 

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-English-check.cmake

@@ -0,0 +1,3 @@
+# 'cl /showIncludes' prefix with 'VSLANG=1033' and 'chcp 437'.
+set(expect "Note: including file: ")
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes-check.cmake)

+ 1 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-English-stdout.txt

@@ -0,0 +1 @@
+-- showIncludes='Note: including file: '

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-English.cmake

@@ -0,0 +1,3 @@
+set(CODEPAGE 437)
+set(VSLANG 1033)
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes.cmake)

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-French-check.cmake

@@ -0,0 +1,3 @@
+# 'cl /showIncludes' prefix with 'VSLANG=1036' and 'chcp 437'.
+string(ASCII 82 101 109 97 114 113 117 101 255 58 32 105 110 99 108 117 115 105 111 110 32 100 117 32 102 105 99 104 105 101 114 255 58 32 32 expect)
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes-check.cmake)

+ 1 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-French-stdout.txt

@@ -0,0 +1 @@
+-- showIncludes='Remarque : inclusion du fichier :  '

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-French.cmake

@@ -0,0 +1,3 @@
+set(CODEPAGE 437)
+set(VSLANG 1036)
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes.cmake)

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-German-check.cmake

@@ -0,0 +1,3 @@
+# 'cl /showIncludes' prefix with 'VSLANG=1031' and 'chcp 437'.
+set(expect "Hinweis: Einlesen der Datei: ")
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes-check.cmake)

+ 1 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-German-stdout.txt

@@ -0,0 +1 @@
+-- showIncludes='Hinweis: Einlesen der Datei: '

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-German.cmake

@@ -0,0 +1,3 @@
+set(CODEPAGE 437)
+set(VSLANG 1031)
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes.cmake)

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-Italian-check.cmake

@@ -0,0 +1,3 @@
+# 'cl /showIncludes' prefix with 'VSLANG=1040' and 'chcp 437'.
+set(expect "Nota: file incluso  ")
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes-check.cmake)

+ 1 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-Italian-stdout.txt

@@ -0,0 +1 @@
+-- showIncludes='Nota: file incluso  '

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-437-Italian.cmake

@@ -0,0 +1,3 @@
+set(CODEPAGE 437)
+set(VSLANG 1040)
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes.cmake)

+ 1 - 1
Tests/RunCMake/Ninja/ShowIncludes-54936-check.cmake → Tests/RunCMake/Ninja/ShowIncludes-54936-Chinese-check.cmake

@@ -1,3 +1,3 @@
 # 'cl /showIncludes' prefix with 'VSLANG=2052' and 'chcp 54936'.
-string(ASCII 215 162 210 226 58 32 176 252 186 172 206 196 188 254 58 expect)
+string(ASCII 215 162 210 226 58 32 176 252 186 172 206 196 188 254 58 32 32 expect)
 include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes-check.cmake)

+ 1 - 0
Tests/RunCMake/Ninja/ShowIncludes-54936-Chinese-stdout.txt

@@ -0,0 +1 @@
+-- showIncludes='注意: 包含文件:  '

+ 1 - 0
Tests/RunCMake/Ninja/ShowIncludes-54936.cmake → Tests/RunCMake/Ninja/ShowIncludes-54936-Chinese.cmake

@@ -1,2 +1,3 @@
 set(CODEPAGE 54936)
+set(VSLANG 2052)
 include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes.cmake)

+ 0 - 1
Tests/RunCMake/Ninja/ShowIncludes-54936-stdout.txt

@@ -1 +0,0 @@
--- showIncludes='注意: 包含文件:'

+ 1 - 1
Tests/RunCMake/Ninja/ShowIncludes-65001-check.cmake → Tests/RunCMake/Ninja/ShowIncludes-65001-Chinese-check.cmake

@@ -1,3 +1,3 @@
 # 'cl /showIncludes' prefix with 'VSLANG=2052' and 'chcp 65001'.
-string(ASCII 230 179 168 230 132 143 58 32 229 140 133 229 144 171 230 150 135 228 187 182 58 expect)
+string(ASCII 230 179 168 230 132 143 58 32 229 140 133 229 144 171 230 150 135 228 187 182 58 32 32 expect)
 include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes-check.cmake)

+ 1 - 0
Tests/RunCMake/Ninja/ShowIncludes-65001-Chinese-stdout.txt

@@ -0,0 +1 @@
+-- showIncludes='注意: 包含文件:  '

+ 1 - 0
Tests/RunCMake/Ninja/ShowIncludes-65001.cmake → Tests/RunCMake/Ninja/ShowIncludes-65001-Chinese.cmake

@@ -1,2 +1,3 @@
 set(CODEPAGE 65001)
+set(VSLANG 2052)
 include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes.cmake)

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-65001-French-check.cmake

@@ -0,0 +1,3 @@
+# 'cl /showIncludes' prefix with 'VSLANG=1036' and 'chcp 65001'.
+string(ASCII 82 101 109 97 114 113 117 101 194 160 58 32 105 110 99 108 117 115 105 111 110 32 100 117 32 102 105 99 104 105 101 114 194 160 58 32 32 expect)
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes-check.cmake)

+ 1 - 0
Tests/RunCMake/Ninja/ShowIncludes-65001-French-stdout.txt

@@ -0,0 +1 @@
+-- showIncludes='Remarque : inclusion du fichier :  '

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-65001-French.cmake

@@ -0,0 +1,3 @@
+set(CODEPAGE 65001)
+set(VSLANG 1036)
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes.cmake)

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-65001-Japanese-check.cmake

@@ -0,0 +1,3 @@
+# 'cl /showIncludes' prefix with 'VSLANG=1041' and 'chcp 65001'.
+string(ASCII 227 131 161 227 131 162 58 32 227 130 164 227 131 179 227 130 175 227 131 171 227 131 188 227 131 137 32 227 131 149 227 130 161 227 130 164 227 131 171 58 32 32 expect)
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes-check.cmake)

+ 1 - 0
Tests/RunCMake/Ninja/ShowIncludes-65001-Japanese-stdout.txt

@@ -0,0 +1 @@
+-- showIncludes='メモ: インクルード ファイル:  '

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-65001-Japanese.cmake

@@ -0,0 +1,3 @@
+set(CODEPAGE 65001)
+set(VSLANG 1041)
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes.cmake)

+ 0 - 1
Tests/RunCMake/Ninja/ShowIncludes-65001-stdout.txt

@@ -1 +0,0 @@
--- showIncludes='注意: 包含文件:'

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-932-Japanese-check.cmake

@@ -0,0 +1,3 @@
+# 'cl /showIncludes' prefix with 'VSLANG=1041' and 'chcp 932'.
+string(ASCII 131 129 131 130 58 32 131 67 131 147 131 78 131 139 129 91 131 104 32 131 116 131 64 131 67 131 139 58 32 32 expect)
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes-check.cmake)

+ 1 - 0
Tests/RunCMake/Ninja/ShowIncludes-932-Japanese-stdout.txt

@@ -0,0 +1 @@
+-- showIncludes='メモ: インクルード ファイル:  '

+ 3 - 0
Tests/RunCMake/Ninja/ShowIncludes-932-Japanese.cmake

@@ -0,0 +1,3 @@
+set(CODEPAGE 932)
+set(VSLANG 1041)
+include(${CMAKE_CURRENT_LIST_DIR}/ShowIncludes.cmake)

+ 4 - 0
Tests/RunCMake/Ninja/ShowIncludes-cmake.cmake

@@ -1,6 +1,10 @@
 # Set the console code page.
 execute_process(COMMAND cmd /c chcp "${CODEPAGE}")
 
+if(VSLANG)
+  set(ENV{VSLANG} "${VSLANG}")
+endif()
+
 if(RunCMake_MAKE_PROGRAM)
   set(maybe_MAKE_PROGRAM "-DCMAKE_MAKE_PROGRAM=${RunCMake_MAKE_PROGRAM}")
 endif()

+ 1 - 1
Tests/RunCMake/Ninja/ShowIncludes.cmake

@@ -15,7 +15,7 @@ endif()
 
 # Run cmake in a new Window to isolate its console code page.
 execute_process(COMMAND cmd /c start /min /wait ""
-  ${CMAKE_COMMAND} -DCODEPAGE=${CODEPAGE} ${maybe_MAKE_PROGRAM} -P ${CMAKE_CURRENT_LIST_DIR}/ShowIncludes-cmake.cmake)
+  ${CMAKE_COMMAND} -DCODEPAGE=${CODEPAGE} -DVSLANG=${VSLANG} ${maybe_MAKE_PROGRAM} -P ${CMAKE_CURRENT_LIST_DIR}/ShowIncludes-cmake.cmake)
 
 # Print our internal UTF-8 representation of the showIncludes prefix.
 file(READ "${CMAKE_CURRENT_BINARY_DIR}/showIncludes.txt" showIncludes_txt)

+ 72 - 11
Tests/RunCMake/showIncludes.c

@@ -1,33 +1,94 @@
+#ifndef _CRT_SECURE_NO_WARNINGS
+#  define _CRT_SECURE_NO_WARNINGS
+#endif
+
 #if defined(_MSC_VER) && _MSC_VER >= 1928
 #  pragma warning(disable : 5105) /* macro expansion warning in windows.h */
 #endif
 #include <windows.h>
 
 #include <stdio.h>
+#include <stdlib.h>
 
 int main()
 {
   /* 'cl /showIncludes' encodes output in the console output code page.  */
   unsigned int cp = GetConsoleOutputCP();
+
+  /* 'cl /showIncludes' prints output in the VS language.  */
+  const char* vslang = getenv("VSLANG");
+  if (!vslang) {
+    fprintf(stderr, "VSLANG is not set.\n");
+    return 1;
+  }
+
   printf("Console output code page: %u\n", cp);
   printf("Console input code page: %u\n", GetConsoleCP());
   printf("ANSI code page: %u\n", GetACP());
   printf("OEM code page: %u\n", GetOEMCP());
+  printf("VSLANG: %s\n", vslang);
+
+  if (strcmp(vslang, "1031") == 0) {
+    if (cp == 437 || cp == 65001) {
+      printf("Hinweis: Einlesen der Datei: C:\\foo.h\n");
+      return 0;
+    }
+  }
 
-  if (cp == 54936 || cp == 936) {
-    /* VSLANG=2052 */
-    printf("\xd7\xa2\xd2\xe2: "
-           "\xb0\xfc\xba\xac\xce\xc4\xbc\xfe:\n");
-    return 0;
+  if (strcmp(vslang, "1033") == 0) {
+    if (cp == 437 || cp == 65001) {
+      printf("Note: including file: C:\\foo.h\n");
+      return 0;
+    }
   }
 
-  if (cp == 65001) {
-    /* VSLANG=2052  */
-    printf("\xe6\xb3\xa8\xe6\x84\x8f: "
-           "\xe5\x8c\x85\xe5\x90\xab\xe6\x96\x87\xe4\xbb\xb6:\n");
-    return 0;
+  if (strcmp(vslang, "1036") == 0) {
+    if (cp == 437 || cp == 863) {
+      printf("Remarque\xff: inclusion du fichier\xff:  C:\\foo.h\n");
+      return 0;
+    }
+    if (cp == 65001) {
+      printf("Remarque\xc2\xa0: inclusion du fichier\xc2\xa0:  C:\\foo.h\n");
+      return 0;
+    }
+  }
+
+  if (strcmp(vslang, "1040") == 0) {
+    if (cp == 437 || cp == 65001) {
+      printf("Nota: file incluso  C:\\foo.h\n");
+      return 0;
+    }
+  }
+
+  if (strcmp(vslang, "1041") == 0) {
+    if (cp == 932) {
+      printf("\x83\x81\x83\x82: "
+             "\x83\x43\x83\x93\x83\x4e\x83\x8b\x81\x5b\x83\x68 "
+             "\x83\x74\x83\x40\x83\x43\x83\x8b:  C:\\foo.h\n");
+      return 0;
+    }
+    if (cp == 65001) {
+      printf("\xe3\x83\xa1\xe3\x83\xa2: \xe3\x82\xa4\xe3\x83\xb3"
+             "\xe3\x82\xaf\xe3\x83\xab\xe3\x83\xbc\xe3\x83\x89 "
+             "\xe3\x83\x95\xe3\x82\xa1\xe3\x82\xa4\xe3\x83\xab:  C:\\foo.h\n");
+      return 0;
+    }
+  }
+
+  if (strcmp(vslang, "2052") == 0) {
+    if (cp == 54936 || cp == 936) {
+      printf("\xd7\xa2\xd2\xe2: "
+             "\xb0\xfc\xba\xac\xce\xc4\xbc\xfe:  C:\\foo.h\n");
+      return 0;
+    }
+
+    if (cp == 65001) {
+      printf("\xe6\xb3\xa8\xe6\x84\x8f: "
+             "\xe5\x8c\x85\xe5\x90\xab\xe6\x96\x87\xe4\xbb\xb6:  C:\\foo.h\n");
+      return 0;
+    }
   }
 
-  fprintf(stderr, "No example showIncludes for console's output code page.\n");
+  fprintf(stderr, "No example showIncludes for this code page and VSLANG.\n");
   return 1;
 }