소스 검색

cxxmodules: Do not scan sources while testing the compiler

The C++ sources we use to test the compiler do not use modules.
Avoid requiring a compiler that can scan just to enable the language,
even when CMP0155 is NEW.  The project may explicitly turn off
`CMAKE_CXX_SCAN_FOR_MODULES` before adding any targets.

Fixes: #25956
Brad King 1 년 전
부모
커밋
6df925b595
2개의 변경된 파일16개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      Modules/CMakeDetermineCompilerABI.cmake
  2. 13 0
      Modules/CMakeTestCXXCompiler.cmake

+ 3 - 0
Modules/CMakeDetermineCompilerABI.cmake

@@ -34,6 +34,9 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src)
       endif()
       endif()
       set(CMAKE_${lang}_RUNTIME_LIBRARY "Static")
       set(CMAKE_${lang}_RUNTIME_LIBRARY "Static")
     endif()
     endif()
+    if(lang STREQUAL "CXX")
+      set(CMAKE_${lang}_SCAN_FOR_MODULES OFF)
+    endif()
     if(NOT "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xMSVC")
     if(NOT "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xMSVC")
       # Avoid adding our own platform standard libraries for compilers
       # Avoid adding our own platform standard libraries for compilers
       # from which we might detect implicit link libraries.
       # from which we might detect implicit link libraries.

+ 13 - 0
Modules/CMakeTestCXXCompiler.cmake

@@ -37,6 +37,13 @@ endif()
 # any makefiles or projects.
 # any makefiles or projects.
 if(NOT CMAKE_CXX_COMPILER_WORKS)
 if(NOT CMAKE_CXX_COMPILER_WORKS)
   PrintTestCompilerStatus("CXX")
   PrintTestCompilerStatus("CXX")
+  # FIXME: Use a block() to isolate the variables we set/unset here.
+  if(DEFINED CMAKE_CXX_SCAN_FOR_MODULES)
+    set(__CMAKE_SAVED_CXX_SCAN_FOR_MODULES "${CMAKE_CXX_SCAN_FOR_MODULES}")
+  else()
+    unset(__CMAKE_SAVED_CXX_SCAN_FOR_MODULES)
+  endif()
+  set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
   __TestCompiler_setTryCompileTargetType()
   __TestCompiler_setTryCompileTargetType()
   string(CONCAT __TestCompiler_testCXXCompilerSource
   string(CONCAT __TestCompiler_testCXXCompilerSource
     "#ifndef __cplusplus\n"
     "#ifndef __cplusplus\n"
@@ -49,6 +56,12 @@ if(NOT CMAKE_CXX_COMPILER_WORKS)
   try_compile(CMAKE_CXX_COMPILER_WORKS
   try_compile(CMAKE_CXX_COMPILER_WORKS
     SOURCE_FROM_VAR testCXXCompiler.cxx __TestCompiler_testCXXCompilerSource
     SOURCE_FROM_VAR testCXXCompiler.cxx __TestCompiler_testCXXCompilerSource
     OUTPUT_VARIABLE __CMAKE_CXX_COMPILER_OUTPUT)
     OUTPUT_VARIABLE __CMAKE_CXX_COMPILER_OUTPUT)
+  if(DEFINED __CMAKE_SAVED_CXX_SCAN_FOR_MODULES)
+    set(CMAKE_CXX_SCAN_FOR_MODULES "${__CMAKE_SAVED_CXX_SCAN_FOR_MODULES}")
+    unset(__CMAKE_SAVED_CXX_SCAN_FOR_MODULES)
+  else()
+    unset(CMAKE_CXX_SCAN_FOR_MODULES)
+  endif()
   unset(__TestCompiler_testCXXCompilerSource)
   unset(__TestCompiler_testCXXCompilerSource)
   # Move result from cache to normal variable.
   # Move result from cache to normal variable.
   set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS})
   set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS})