Check*: Restore support for arbitrary result variable names

In commit db76876db5 (Modules: Use new SOURCES_FROM_* try_compile (1/2),
2022-09-26, v3.25.0-rc1~74^2~1) and commit 41f7b1169a (Modules: Use new
SOURCES_FROM_* try_compile (2/2), 2022-09-26, v3.25.0-rc1~74^2) the
switch to `SOURCE_FROM_*` required a stronger precondition (the second
argument to check_include_files must not have path components) than
before (any variable name could be used).

Fix that by transforming the variable name to a C identifier before
feeding it to try_compile as a filename.  The filename is unspecified by
the documentation, and the file itself is only temporary, so that should
work fine.

I have gone through all the occurrences of `SOURCE_FROM_*`, and
identified these two that require changes.  The rest should work fine as
the filenames do not depend on input variable names.

Fixes: #24204
This commit is contained in:
Zhong Ruoyu
2022-11-29 00:08:24 +08:00
committed by Brad King
parent 90907c8ff9
commit f6b99c5087
2 changed files with 6 additions and 4 deletions

View File

@@ -70,10 +70,11 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
message(FATAL_ERROR "Unknown arguments:\n ${ARGN}\n")
endif()
string(MAKE_C_IDENTIFIER ${VARIABLE} _variable_escaped)
if(_lang STREQUAL "C")
set(src ${VARIABLE}.c)
set(src ${_variable_escaped}.c)
elseif(_lang STREQUAL "CXX")
set(src ${VARIABLE}.cpp)
set(src ${_variable_escaped}.cpp)
else()
message(FATAL_ERROR "Unknown language:\n ${_lang}\nSupported languages: C, CXX.\n")
endif()

View File

@@ -103,10 +103,11 @@ function(__check_type_size_impl type var map builtin language)
endif()
# Perform language check
string(MAKE_C_IDENTIFIER ${var} _var_escaped)
if(language STREQUAL "C")
set(src ${var}.c)
set(src ${_var_escaped}.c)
elseif(language STREQUAL "CXX")
set(src ${var}.cpp)
set(src ${_var_escaped}.cpp)
else()
message(FATAL_ERROR "Unknown language:\n ${language}\nSupported languages: C, CXX.\n")
endif()