mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-19 19:43:23 +08:00
enable_language: Assume compiler works if ABI detection compiles
We run a `try_compile` with a tiny test source to check if the compiler works so that we can fail early if it does not. When the compiler does work, we immediately `try_compile` the ABI detection source. In the common case that both steps work, we gain no useful information from the first one and the work was wasted. Re-order the checks to try the ABI detection first. If it works then assume the compiler works and skip the dedicated check. If the ABI check fails then proceed with the normal test for a working compiler so the diagnostic can be shown as before. Fixes: #18703
This commit is contained in:
@@ -21,6 +21,15 @@ endif()
|
||||
# We now store this in CMakeCCompiler.cmake.
|
||||
unset(CMAKE_C_COMPILER_WORKS CACHE)
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeCCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(C ${CMAKE_ROOT}/Modules/CMakeCCompilerABI.c)
|
||||
if(CMAKE_C_ABI_COMPILED)
|
||||
# The compiler worked so skip dedicated test below.
|
||||
set(CMAKE_C_COMPILER_WORKS TRUE)
|
||||
message(STATUS "Check for working C compiler: ${CMAKE_C_COMPILER} - skipped")
|
||||
endif()
|
||||
|
||||
# This file is used by EnableLanguage in cmGlobalGenerator to
|
||||
# determine that that selected C compiler can actually compile
|
||||
# and link the most basic of programs. If not, a fatal error
|
||||
@@ -47,10 +56,7 @@ if(NOT CMAKE_C_COMPILER_WORKS)
|
||||
# Move result from cache to normal variable.
|
||||
set(CMAKE_C_COMPILER_WORKS ${CMAKE_C_COMPILER_WORKS})
|
||||
unset(CMAKE_C_COMPILER_WORKS CACHE)
|
||||
set(C_TEST_WAS_RUN 1)
|
||||
__TestCompiler_restoreTryCompileTargetType()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_C_COMPILER_WORKS)
|
||||
PrintTestCompilerResult(CHECK_FAIL "broken")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
@@ -61,17 +67,13 @@ if(NOT CMAKE_C_COMPILER_WORKS)
|
||||
"is not able to compile a simple test program.\nIt fails "
|
||||
"with the following output:\n ${_output}\n\n"
|
||||
"CMake will not be able to correctly generate this project.")
|
||||
else()
|
||||
if(C_TEST_WAS_RUN)
|
||||
endif()
|
||||
PrintTestCompilerResult(CHECK_PASS "works")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Determining if the C compiler works passed with "
|
||||
"the following output:\n${__CMAKE_C_COMPILER_OUTPUT}\n\n")
|
||||
endif()
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeCCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(C ${CMAKE_ROOT}/Modules/CMakeCCompilerABI.c)
|
||||
# Try to identify the compiler features
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
|
||||
CMAKE_DETERMINE_COMPILE_FEATURES(C)
|
||||
@@ -90,7 +92,6 @@ else()
|
||||
endforeach()
|
||||
unset(CMAKE_C_ABI_FILES)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
|
||||
unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
|
||||
|
@@ -14,6 +14,15 @@ include(CMakeTestCompilerCommon)
|
||||
# We now store this in CMakeCUDACompiler.cmake.
|
||||
unset(CMAKE_CUDA_COMPILER_WORKS CACHE)
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeCUDACompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(CUDA ${CMAKE_ROOT}/Modules/CMakeCUDACompilerABI.cu)
|
||||
if(CMAKE_CUDA_ABI_COMPILED)
|
||||
# The compiler worked so skip dedicated test below.
|
||||
set(CMAKE_CUDA_COMPILER_WORKS TRUE)
|
||||
message(STATUS "Check for working CUDA compiler: ${CMAKE_CUDA_COMPILER} - skipped")
|
||||
endif()
|
||||
|
||||
# This file is used by EnableLanguage in cmGlobalGenerator to
|
||||
# determine that the selected cuda compiler can actually compile
|
||||
# and link the most basic of programs. If not, a fatal error
|
||||
@@ -34,9 +43,6 @@ if(NOT CMAKE_CUDA_COMPILER_WORKS)
|
||||
# Move result from cache to normal variable.
|
||||
set(CMAKE_CUDA_COMPILER_WORKS ${CMAKE_CUDA_COMPILER_WORKS})
|
||||
unset(CMAKE_CUDA_COMPILER_WORKS CACHE)
|
||||
set(CUDA_TEST_WAS_RUN 1)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CUDA_COMPILER_WORKS)
|
||||
PrintTestCompilerResult(CHECK_FAIL "broken")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
@@ -47,17 +53,13 @@ if(NOT CMAKE_CUDA_COMPILER_WORKS)
|
||||
"is not able to compile a simple test program.\nIt fails "
|
||||
"with the following output:\n ${_output}\n\n"
|
||||
"CMake will not be able to correctly generate this project.")
|
||||
else()
|
||||
if(CUDA_TEST_WAS_RUN)
|
||||
endif()
|
||||
PrintTestCompilerResult(CHECK_PASS "works")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Determining if the CUDA compiler works passed with "
|
||||
"the following output:\n${__CMAKE_CUDA_COMPILER_OUTPUT}\n\n")
|
||||
endif()
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeCUDACompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(CUDA ${CMAKE_ROOT}/Modules/CMakeCUDACompilerABI.cu)
|
||||
# Try to identify the compiler features
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
|
||||
CMAKE_DETERMINE_COMPILE_FEATURES(CUDA)
|
||||
@@ -92,7 +94,5 @@ else()
|
||||
@ONLY
|
||||
)
|
||||
include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCUDACompiler.cmake)
|
||||
endif()
|
||||
|
||||
|
||||
unset(__CMAKE_CUDA_COMPILER_OUTPUT)
|
||||
|
@@ -21,6 +21,15 @@ endif()
|
||||
# We now store this in CMakeCXXCompiler.cmake.
|
||||
unset(CMAKE_CXX_COMPILER_WORKS CACHE)
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
|
||||
if(CMAKE_CXX_ABI_COMPILED)
|
||||
# The compiler worked so skip dedicated test below.
|
||||
set(CMAKE_CXX_COMPILER_WORKS TRUE)
|
||||
message(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER} - skipped")
|
||||
endif()
|
||||
|
||||
# This file is used by EnableLanguage in cmGlobalGenerator to
|
||||
# determine that the selected C++ compiler can actually compile
|
||||
# and link the most basic of programs. If not, a fatal error
|
||||
@@ -40,10 +49,7 @@ if(NOT CMAKE_CXX_COMPILER_WORKS)
|
||||
# Move result from cache to normal variable.
|
||||
set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS})
|
||||
unset(CMAKE_CXX_COMPILER_WORKS CACHE)
|
||||
set(CXX_TEST_WAS_RUN 1)
|
||||
__TestCompiler_restoreTryCompileTargetType()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_CXX_COMPILER_WORKS)
|
||||
PrintTestCompilerResult(CHECK_FAIL "broken")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
@@ -54,17 +60,13 @@ if(NOT CMAKE_CXX_COMPILER_WORKS)
|
||||
"is not able to compile a simple test program.\nIt fails "
|
||||
"with the following output:\n ${_output}\n\n"
|
||||
"CMake will not be able to correctly generate this project.")
|
||||
else()
|
||||
if(CXX_TEST_WAS_RUN)
|
||||
endif()
|
||||
PrintTestCompilerResult(CHECK_PASS "works")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Determining if the CXX compiler works passed with "
|
||||
"the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
|
||||
endif()
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
|
||||
# Try to identify the compiler features
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
|
||||
CMAKE_DETERMINE_COMPILE_FEATURES(CXX)
|
||||
@@ -83,7 +85,6 @@ else()
|
||||
endforeach()
|
||||
unset(CMAKE_CXX_ABI_FILES)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
|
||||
unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
|
||||
|
@@ -15,6 +15,15 @@ include(CMakeTestCompilerCommon)
|
||||
# We now store this in CMakeFortranCompiler.cmake.
|
||||
unset(CMAKE_Fortran_COMPILER_WORKS CACHE)
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeFortranCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(Fortran ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F)
|
||||
if(CMAKE_Fortran_ABI_COMPILED)
|
||||
# The compiler worked so skip dedicated test below.
|
||||
set(CMAKE_Fortran_COMPILER_WORKS TRUE)
|
||||
message(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER} - skipped")
|
||||
endif()
|
||||
|
||||
# This file is used by EnableLanguage in cmGlobalGenerator to
|
||||
# determine that the selected Fortran compiler can actually compile
|
||||
# and link the most basic of programs. If not, a fatal error
|
||||
@@ -33,9 +42,6 @@ if(NOT CMAKE_Fortran_COMPILER_WORKS)
|
||||
# Move result from cache to normal variable.
|
||||
set(CMAKE_Fortran_COMPILER_WORKS ${CMAKE_Fortran_COMPILER_WORKS})
|
||||
unset(CMAKE_Fortran_COMPILER_WORKS CACHE)
|
||||
set(FORTRAN_TEST_WAS_RUN 1)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_Fortran_COMPILER_WORKS)
|
||||
PrintTestCompilerResult(CHECK_FAIL "broken")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
@@ -46,18 +52,13 @@ if(NOT CMAKE_Fortran_COMPILER_WORKS)
|
||||
"is not able to compile a simple test program.\nIt fails "
|
||||
"with the following output:\n ${_output}\n\n"
|
||||
"CMake will not be able to correctly generate this project.")
|
||||
else()
|
||||
if(FORTRAN_TEST_WAS_RUN)
|
||||
endif()
|
||||
PrintTestCompilerResult(CHECK_PASS "works")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Determining if the Fortran compiler works passed with "
|
||||
"the following output:\n${OUTPUT}\n\n")
|
||||
endif()
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeFortranCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(Fortran ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F)
|
||||
|
||||
# Test for Fortran 90 support by using an f90-specific construct.
|
||||
if(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
|
||||
message(CHECK_START "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90")
|
||||
@@ -99,4 +100,3 @@ else()
|
||||
endforeach()
|
||||
unset(CMAKE_Fortran_ABI_FILES)
|
||||
endif()
|
||||
endif()
|
||||
|
@@ -21,6 +21,15 @@ endif()
|
||||
# We now store this in CMakeCCompiler.cmake.
|
||||
unset(CMAKE_OBJC_COMPILER_WORKS CACHE)
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeOBJCCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(OBJC ${CMAKE_ROOT}/Modules/CMakeOBJCCompilerABI.m)
|
||||
if(CMAKE_OBJC_ABI_COMPILED)
|
||||
# The compiler worked so skip dedicated test below.
|
||||
set(CMAKE_OBJC_COMPILER_WORKS TRUE)
|
||||
message(STATUS "Check for working OBJC compiler: ${CMAKE_OBJC_COMPILER} - skipped")
|
||||
endif()
|
||||
|
||||
# This file is used by EnableLanguage in cmGlobalGenerator to
|
||||
# determine that that selected Objective-C compiler can actually compile
|
||||
# and link the most basic of programs. If not, a fatal error
|
||||
@@ -44,10 +53,7 @@ if(NOT CMAKE_OBJC_COMPILER_WORKS)
|
||||
# Move result from cache to normal variable.
|
||||
set(CMAKE_OBJC_COMPILER_WORKS ${CMAKE_OBJC_COMPILER_WORKS})
|
||||
unset(CMAKE_OBJC_COMPILER_WORKS CACHE)
|
||||
set(OBJC_TEST_WAS_RUN 1)
|
||||
__TestCompiler_restoreTryCompileTargetType()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_OBJC_COMPILER_WORKS)
|
||||
PrintTestCompilerResult(CHECK_FAIL "broken")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
@@ -58,17 +64,13 @@ if(NOT CMAKE_OBJC_COMPILER_WORKS)
|
||||
"is not able to compile a simple test program.\nIt fails "
|
||||
"with the following output:\n ${_output}\n\n"
|
||||
"CMake will not be able to correctly generate this project.")
|
||||
else()
|
||||
if(OBJC_TEST_WAS_RUN)
|
||||
endif()
|
||||
PrintTestCompilerResult(CHECK_PASS "works")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Determining if the Objective-C compiler works passed with "
|
||||
"the following output:\n${__CMAKE_OBJC_COMPILER_OUTPUT}\n\n")
|
||||
endif()
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeOBJCCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(OBJC ${CMAKE_ROOT}/Modules/CMakeOBJCCompilerABI.m)
|
||||
# Try to identify the compiler features
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
|
||||
CMAKE_DETERMINE_COMPILE_FEATURES(OBJC)
|
||||
@@ -87,7 +89,6 @@ else()
|
||||
endforeach()
|
||||
unset(CMAKE_OBJC_ABI_FILES)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
|
||||
unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
|
||||
|
@@ -21,6 +21,15 @@ endif()
|
||||
# We now store this in CMakeOBJCXXCompiler.cmake.
|
||||
unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE)
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeOBJCXXCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(OBJCXX ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompilerABI.mm)
|
||||
if(CMAKE_OBJCXX_ABI_COMPILED)
|
||||
# The compiler worked so skip dedicated test below.
|
||||
set(CMAKE_OBJCXX_COMPILER_WORKS TRUE)
|
||||
message(STATUS "Check for working OBJCXX compiler: ${CMAKE_OBJCXX_COMPILER} - skipped")
|
||||
endif()
|
||||
|
||||
# This file is used by EnableLanguage in cmGlobalGenerator to
|
||||
# determine that the selected Objective-C++ compiler can actually compile
|
||||
# and link the most basic of programs. If not, a fatal error
|
||||
@@ -43,10 +52,7 @@ if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
|
||||
# Move result from cache to normal variable.
|
||||
set(CMAKE_OBJCXX_COMPILER_WORKS ${CMAKE_OBJCXX_COMPILER_WORKS})
|
||||
unset(CMAKE_OBJCXX_COMPILER_WORKS CACHE)
|
||||
set(OBJCXX_TEST_WAS_RUN 1)
|
||||
__TestCompiler_restoreTryCompileTargetType()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
|
||||
PrintTestCompilerResult(CHECK_FAIL "broken")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
@@ -57,17 +63,13 @@ if(NOT CMAKE_OBJCXX_COMPILER_WORKS)
|
||||
"is not able to compile a simple test program.\nIt fails "
|
||||
"with the following output:\n ${_output}\n\n"
|
||||
"CMake will not be able to correctly generate this project.")
|
||||
else()
|
||||
if(OBJCXX_TEST_WAS_RUN)
|
||||
endif()
|
||||
PrintTestCompilerResult(CHECK_PASS "works")
|
||||
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Determining if the Objective-C++ compiler works passed with "
|
||||
"the following output:\n${__CMAKE_OBJCXX_COMPILER_OUTPUT}\n\n")
|
||||
endif()
|
||||
|
||||
# Try to identify the ABI and configure it into CMakeOBJCXXCompiler.cmake
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(OBJCXX ${CMAKE_ROOT}/Modules/CMakeOBJCXXCompilerABI.mm)
|
||||
# Try to identify the compiler features
|
||||
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
|
||||
CMAKE_DETERMINE_COMPILE_FEATURES(OBJCXX)
|
||||
@@ -86,7 +88,6 @@ else()
|
||||
endforeach()
|
||||
unset(CMAKE_OBJCXX_ABI_FILES)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
|
||||
unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
|
||||
|
Reference in New Issue
Block a user