mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-09 17:18:18 +00:00
Modules: Tolerate CMAKE_EXECUTE_PROCESS_COMMAND_ERROR_IS_FATAL
Capture the `execute_process` command's `RESULT_VARIABLE`. Issue: #27782
This commit is contained in:
@@ -30,9 +30,10 @@ if(RUSTC_FILENAME STREQUAL "rustup")
|
||||
COMMAND ${RUSTUP_PATH} which rustc
|
||||
OUTPUT_VARIABLE REAL_RUSTC
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
RESULT_VARIABLE _rust_result
|
||||
)
|
||||
|
||||
if("${REAL_RUSTC}" STREQUAL "")
|
||||
if(NOT _rust_result EQUAL 0 OR "${REAL_RUSTC}" STREQUAL "")
|
||||
message(FATAL_ERROR "Failed to find path to real rustc")
|
||||
endif()
|
||||
|
||||
|
||||
@@ -15,19 +15,24 @@ if(CMAKE_HOST_UNIX)
|
||||
execute_process(COMMAND ${CMAKE_UNAME} -v
|
||||
OUTPUT_VARIABLE _CMAKE_HOST_SYSTEM_MAJOR_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET)
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE _uname_result)
|
||||
execute_process(COMMAND ${CMAKE_UNAME} -r
|
||||
OUTPUT_VARIABLE _CMAKE_HOST_SYSTEM_MINOR_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET)
|
||||
set(CMAKE_HOST_SYSTEM_VERSION "${_CMAKE_HOST_SYSTEM_MAJOR_VERSION}.${_CMAKE_HOST_SYSTEM_MINOR_VERSION}")
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE _uname_result2)
|
||||
if(_uname_result EQUAL 0 AND _uname_result2 EQUAL 0)
|
||||
set(CMAKE_HOST_SYSTEM_VERSION "${_CMAKE_HOST_SYSTEM_MAJOR_VERSION}.${_CMAKE_HOST_SYSTEM_MINOR_VERSION}")
|
||||
endif()
|
||||
unset(_CMAKE_HOST_SYSTEM_MAJOR_VERSION)
|
||||
unset(_CMAKE_HOST_SYSTEM_MINOR_VERSION)
|
||||
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
|
||||
execute_process(COMMAND getprop ro.build.version.sdk
|
||||
OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET)
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE _uname_result)
|
||||
|
||||
if(NOT DEFINED CMAKE_SYSTEM_VERSION)
|
||||
set(_ANDROID_API_LEVEL_H $ENV{PREFIX}/include/android/api-level.h)
|
||||
@@ -49,7 +54,8 @@ if(CMAKE_HOST_UNIX)
|
||||
execute_process(COMMAND ${CMAKE_UNAME} -r
|
||||
OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET)
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE _uname_result)
|
||||
endif()
|
||||
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|CYGWIN.*|MSYS.*|^GNU$|Android")
|
||||
execute_process(COMMAND ${CMAKE_UNAME} -m
|
||||
|
||||
@@ -25,9 +25,14 @@ endif()
|
||||
function(__armclang_set_processor_list lang out_var)
|
||||
execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" --target=${CMAKE_${lang}_COMPILER_TARGET} -mcpu=list
|
||||
OUTPUT_VARIABLE processor_list
|
||||
ERROR_VARIABLE processor_list)
|
||||
string(REGEX MATCHALL "-mcpu=([^ \n]*)" processor_list "${processor_list}")
|
||||
string(REGEX REPLACE "-mcpu=" "" processor_list "${processor_list}")
|
||||
ERROR_VARIABLE processor_list
|
||||
RESULT_VARIABLE _res
|
||||
)
|
||||
set(processor_list)
|
||||
if(_res EQUAL 0)
|
||||
string(REGEX MATCHALL "-mcpu=([^ \n]*)" processor_list "${processor_list}")
|
||||
string(REGEX REPLACE "-mcpu=" "" processor_list "${processor_list}")
|
||||
endif()
|
||||
set(${out_var} "${processor_list}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
@@ -45,9 +50,14 @@ endfunction()
|
||||
function(__armclang_set_arch_list lang out_var)
|
||||
execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" --target=${CMAKE_${lang}_COMPILER_TARGET} -march=list
|
||||
OUTPUT_VARIABLE arch_list
|
||||
ERROR_VARIABLE arch_list)
|
||||
string(REGEX MATCHALL "-march=([^ \n]*)" arch_list "${arch_list}")
|
||||
string(REGEX REPLACE "-march=" "" arch_list "${arch_list}")
|
||||
ERROR_VARIABLE arch_list
|
||||
RESULT_VARIABLE _res
|
||||
)
|
||||
set(arch_list)
|
||||
if(_res EQUAL 0)
|
||||
string(REGEX MATCHALL "-march=([^ \n]*)" arch_list "${arch_list}")
|
||||
string(REGEX REPLACE "-march=" "" arch_list "${arch_list}")
|
||||
endif()
|
||||
set(${out_var} "${arch_list}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
@@ -61,9 +71,14 @@ function(__armlink_set_cpu_list lang out_var)
|
||||
|
||||
execute_process(COMMAND "${CMAKE_LINKER}" ${__linker_wrapper_flags} --cpu=list
|
||||
OUTPUT_VARIABLE cpu_list
|
||||
ERROR_VARIABLE cpu_list)
|
||||
string(REGEX MATCHALL "--cpu=([^ \n]*)" cpu_list "${cpu_list}")
|
||||
string(REGEX REPLACE "--cpu=" "" cpu_list "${cpu_list}")
|
||||
ERROR_VARIABLE cpu_list
|
||||
RESULT_VARIABLE _res
|
||||
)
|
||||
set(cpu_list)
|
||||
if(_res EQUAL 0)
|
||||
string(REGEX MATCHALL "--cpu=([^ \n]*)" cpu_list "${cpu_list}")
|
||||
string(REGEX REPLACE "--cpu=" "" cpu_list "${cpu_list}")
|
||||
endif()
|
||||
set(${out_var} "${cpu_list}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
|
||||
@@ -6,10 +6,11 @@ if(NOT CMAKE_Fortran_COMPILER_WORKS AND NOT CMAKE_Fortran_COMPILER_FORCED)
|
||||
COMMAND ${CMAKE_Fortran_COMPILER} dummy.o -dryrun
|
||||
OUTPUT_VARIABLE _dryrun
|
||||
ERROR_VARIABLE _dryrun
|
||||
RESULT_VARIABLE _dryrun_result
|
||||
)
|
||||
# Match an object file.
|
||||
string(REGEX MATCH "/[^ ]*/[^ /][^ /]*\\.o" _nag_obj "${_dryrun}")
|
||||
if(_nag_obj)
|
||||
if(_nag_obj AND _dryrun_result EQUAL 0)
|
||||
# Parse object directory and convert to a regex.
|
||||
string(REGEX REPLACE "/[^/]*$" "" _nag_dir "${_nag_obj}")
|
||||
string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" _nag_regex "${_nag_dir}")
|
||||
|
||||
@@ -31,7 +31,10 @@ function(cmake_determine_linker_id lang linker)
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_STRIP_TRAILING_WHITESPACE
|
||||
COMMAND_ERROR_IS_FATAL NONE
|
||||
RESULT_VARIABLE _res
|
||||
)
|
||||
# We capture "_res" but don't check it because it's expected that
|
||||
# linkers will exit with non-zero on flags they do not have.
|
||||
|
||||
string(JOIN "\" \"" flags_string ${flags})
|
||||
string(REGEX REPLACE "\n\n.*" "" linker_desc_head "${linker_desc}")
|
||||
|
||||
@@ -24,11 +24,13 @@ function(__linker_gnu lang)
|
||||
# Ninja 1.10 or upper is required
|
||||
execute_process(COMMAND "${CMAKE_MAKE_PROGRAM}" --version
|
||||
OUTPUT_VARIABLE _ninja_version
|
||||
ERROR_VARIABLE _ninja_version)
|
||||
ERROR_VARIABLE _ninja_version
|
||||
RESULT_VARIABLE _res
|
||||
)
|
||||
if (_ninja_version MATCHES "[0-9]+(\\.[0-9]+)*")
|
||||
set (_ninja_version "${CMAKE_MATCH_0}")
|
||||
endif()
|
||||
if (_ninja_version VERSION_LESS "1.10")
|
||||
if (NOT _res EQUAL 0 OR _ninja_version VERSION_LESS "1.10")
|
||||
set(CMAKE_${lang}_LINKER_DEPFILE_SUPPORTED FALSE)
|
||||
endif()
|
||||
endif()
|
||||
@@ -38,8 +40,9 @@ function(__linker_gnu lang)
|
||||
if (CMAKE_${lang}_COMPILER_LINKER AND CMAKE_${lang}_COMPILER_LINKER_ID MATCHES "GNU|LLD|MOLD")
|
||||
execute_process(COMMAND "${CMAKE_${lang}_COMPILER_LINKER}" --help
|
||||
OUTPUT_VARIABLE _linker_capabilities
|
||||
ERROR_VARIABLE _linker_capabilities)
|
||||
if(_linker_capabilities MATCHES "--dependency-file")
|
||||
ERROR_VARIABLE _linker_capabilities
|
||||
RESULT_VARIABLE _res)
|
||||
if(_res EQUAL 0 AND _linker_capabilities MATCHES "--dependency-file")
|
||||
set(CMAKE_${lang}_LINKER_DEPFILE_SUPPORTED TRUE)
|
||||
else()
|
||||
set(CMAKE_${lang}_LINKER_DEPFILE_SUPPORTED FALSE)
|
||||
|
||||
@@ -30,8 +30,9 @@ execute_process(
|
||||
OUTPUT_VARIABLE _gcc_version
|
||||
ERROR_VARIABLE _gcc_error
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE _gcc_result
|
||||
)
|
||||
if(_gcc_version MATCHES "^([0-9]+\\.[0-9]+)")
|
||||
if(_gcc_result EQUAL 0 AND _gcc_version MATCHES "^([0-9]+\\.[0-9]+)")
|
||||
set(_ANDROID_TOOL_C_TOOLCHAIN_VERSION "${CMAKE_MATCH_1}")
|
||||
else()
|
||||
message(FATAL_ERROR
|
||||
|
||||
@@ -31,8 +31,9 @@ macro(cmake_gnu_set_sysroot_flag lang)
|
||||
COMMAND ${CMAKE_${lang}_COMPILER} "-v" "--help"
|
||||
OUTPUT_VARIABLE _gcc_help
|
||||
ERROR_VARIABLE _gcc_help
|
||||
RESULT_VARIABLE _gcc_result
|
||||
)
|
||||
if("${_gcc_help}" MATCHES "isysroot")
|
||||
if(_gcc_result EQUAL 0 AND "${_gcc_help}" MATCHES "isysroot")
|
||||
message(CHECK_PASS "yes")
|
||||
set(CMAKE_${lang}_SYSROOT_FLAG "-isysroot")
|
||||
else()
|
||||
@@ -51,8 +52,9 @@ macro(cmake_gnu_set_osx_deployment_target_flag lang)
|
||||
COMMAND ${CMAKE_${lang}_COMPILER} "-v" "--help"
|
||||
OUTPUT_VARIABLE _gcc_help
|
||||
ERROR_VARIABLE _gcc_help
|
||||
RESULT_VARIABLE _gcc_result
|
||||
)
|
||||
if("${_gcc_help}" MATCHES "macosx-version-min")
|
||||
if(_gcc_result EQUAL 0 AND "${_gcc_help}" MATCHES "macosx-version-min")
|
||||
message(CHECK_PASS "yes")
|
||||
set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mmacosx-version-min=")
|
||||
else()
|
||||
|
||||
@@ -292,10 +292,11 @@ endif()
|
||||
if(NOT CMAKE_CROSSCOMPILING)
|
||||
execute_process(COMMAND sw_vers -productVersion
|
||||
OUTPUT_VARIABLE _CMAKE_HOST_OSX_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE _result)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET)
|
||||
if(_result EQUAL 0 AND CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET)
|
||||
set(_CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT "$ENV{MACOSX_DEPLOYMENT_TARGET}")
|
||||
|
||||
# Xcode chooses a default macOS deployment target based on the macOS SDK
|
||||
|
||||
@@ -7,7 +7,7 @@ if(NOT _CMAKE_SYSTEM_LINKER_TYPE)
|
||||
RESULT_VARIABLE result
|
||||
OUTPUT_VARIABLE output
|
||||
ERROR_VARIABLE output)
|
||||
if(result OR NOT output MATCHES "LLD")
|
||||
if(NOT result EQUAL 0 OR NOT output MATCHES "LLD")
|
||||
# assume GNU as default linker
|
||||
set(_CMAKE_SYSTEM_LINKER_TYPE GNU CACHE INTERNAL "System linker type")
|
||||
else()
|
||||
|
||||
@@ -23,8 +23,8 @@ function(__cmake_set_whole_archive_feature __linker)
|
||||
OUTPUT_VARIABLE __linker_log
|
||||
ERROR_VARIABLE __linker_log
|
||||
COMMAND_ERROR_IS_FATAL NONE
|
||||
)
|
||||
if(__linker_log MATCHES "--push-state" OR __linker_log MATCHES "--pop-state")
|
||||
RESULT_VARIABLE __linker_result)
|
||||
if(__linker_result EQUAL 0 AND (__linker_log MATCHES "--push-state" OR __linker_log MATCHES "--pop-state"))
|
||||
set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED FALSE)
|
||||
else()
|
||||
set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED TRUE)
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
# Sun C++ 5.9 does not support -Wl, but Sun C++ 5.11 does not work without it.
|
||||
# Query the compiler flags to detect whether to use -Wl.
|
||||
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -flags OUTPUT_VARIABLE _cxx_flags ERROR_VARIABLE _cxx_error)
|
||||
if("${_cxx_flags}" MATCHES "\n-W[^\n]*component")
|
||||
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -flags
|
||||
OUTPUT_VARIABLE _cxx_flags
|
||||
ERROR_VARIABLE _cxx_error
|
||||
RESULT_VARIABLE _cxx_result)
|
||||
if(_cxx_result EQUAL 0 AND "${_cxx_flags}" MATCHES "\n-W[^\n]*component")
|
||||
set(CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG "-Wl,-rpath-link,")
|
||||
else()
|
||||
set(CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG "-rpath-link ")
|
||||
|
||||
@@ -7,12 +7,15 @@ include(Platform/NetBSD)
|
||||
if(NOT CMAKE_PLATFORM_RUNTIME_PATH)
|
||||
execute_process(COMMAND /sbin/ldconfig -r
|
||||
OUTPUT_VARIABLE LDCONFIG_HINTS
|
||||
ERROR_QUIET)
|
||||
string(REGEX REPLACE ".*search\\ directories:\\ ([^\n]*).*" "\\1"
|
||||
LDCONFIG_HINTS "${LDCONFIG_HINTS}")
|
||||
string(REPLACE ":" ";"
|
||||
CMAKE_PLATFORM_RUNTIME_PATH
|
||||
"${LDCONFIG_HINTS}")
|
||||
ERROR_QUIET
|
||||
RESULT_VARIABLE _res)
|
||||
if(_res EQUAL 0)
|
||||
string(REGEX REPLACE ".*search\\ directories:\\ ([^\n]*).*" "\\1"
|
||||
LDCONFIG_HINTS "${LDCONFIG_HINTS}")
|
||||
string(REPLACE ":" ";"
|
||||
CMAKE_PLATFORM_RUNTIME_PATH
|
||||
"${LDCONFIG_HINTS}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# OpenBSD requires -z origin to enable $ORIGIN expansion in RPATH.
|
||||
|
||||
@@ -58,8 +58,8 @@ set(CMAKE_GNULD_IMAGE_VERSION
|
||||
|
||||
# Check if GNU ld is too old to support @FILE syntax.
|
||||
set(__WINDOWS_GNU_LD_RESPONSE 1)
|
||||
execute_process(COMMAND ld -v OUTPUT_VARIABLE _help ERROR_VARIABLE _help)
|
||||
if("${_help}" MATCHES "GNU ld .* 2\\.1[1-6]")
|
||||
execute_process(COMMAND ld -v OUTPUT_VARIABLE _help ERROR_VARIABLE _help RESULT_VARIABLE _res)
|
||||
if(_res EQUAL 0 AND "${_help}" MATCHES "GNU ld .* 2\\.1[1-6]")
|
||||
set(__WINDOWS_GNU_LD_RESPONSE 0)
|
||||
endif()
|
||||
|
||||
@@ -107,8 +107,8 @@ macro(__windows_compiler_gnu lang)
|
||||
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
|
||||
|
||||
# We prefer "@" for response files but it is not supported by gcc 3.
|
||||
execute_process(COMMAND ${CMAKE_${lang}_COMPILER} --version OUTPUT_VARIABLE _ver ERROR_VARIABLE _ver)
|
||||
if("${_ver}" MATCHES "\\(GCC\\) 3\\.")
|
||||
execute_process(COMMAND ${CMAKE_${lang}_COMPILER} --version OUTPUT_VARIABLE _ver ERROR_VARIABLE _ver RESULT_VARIABLE _res)
|
||||
if(_res EQUAL 0 AND "${_ver}" MATCHES "\\(GCC\\) 3\\.")
|
||||
if("${lang}" STREQUAL "Fortran")
|
||||
# The GNU Fortran compiler reports an error:
|
||||
# no input files; unwilling to write output files
|
||||
|
||||
@@ -16,7 +16,7 @@ if (CMAKE_GENERATOR MATCHES "^Ninja")
|
||||
RESULT_VARIABLE _CMAKE_NINJA_RESULT
|
||||
OUTPUT_VARIABLE _CMAKE_NINJA_VERSION
|
||||
ERROR_VARIABLE _CMAKE_NINJA_VERSION)
|
||||
if (NOT _CMAKE_NINJA_RESULT AND _CMAKE_NINJA_VERSION MATCHES "[0-9]+(\\.[0-9]+)*")
|
||||
if (_CMAKE_NINJA_RESULT EQUAL 0 AND _CMAKE_NINJA_VERSION MATCHES "[0-9]+(\\.[0-9]+)*")
|
||||
set (_CMAKE_NINJA_VERSION "${CMAKE_MATCH_0}")
|
||||
endif()
|
||||
unset(_CMAKE_NINJA_RESULT)
|
||||
|
||||
Reference in New Issue
Block a user