mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
Commit 7644d557df (Check*: Refactor variable handling, 2026-07-20,
v4.4.1~12^2~1) introduced a subtle regression in the handling of
`CMAKE_REQUIRED_LINK_OPTIONS` and `CMAKE_REQUIRED_LIBRARIES` which
resulted in an error if these were set to a 'false-like' value. This
could happen, for example, if the user passes `<name>_LIBS`, which
happens to have the value `<name>-NOTFOUND`. Previously, such values
would be ignored.
Fix it by separately checking for user- or module-provided link options
or link libraries. (We were already doing this for the other variables
used to propagate requirements into checks.)
Fixes: #28026
57 lines
1.8 KiB
CMake
57 lines
1.8 KiB
CMake
enable_language(C)
|
|
enable_language(CXX)
|
|
|
|
# Warning options after the first entry are ignored for compatibility.
|
|
set(CMAKE_REQUIRED_FLAGS
|
|
"-DCHECK_REQUIRED_FLAGS -Drequired_flag_function=memcpy -Drequired_flag_library=memcpy -Drequired_flag_type=int"
|
|
"-Wseen-by-cmake")
|
|
set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_LIST_DIR}")
|
|
|
|
include(CheckFunctionExists)
|
|
include(CheckIncludeFile)
|
|
include(CheckIncludeFileCXX)
|
|
include(CheckIncludeFiles)
|
|
include(CheckLibraryExists)
|
|
include(CheckPrototypeDefinition)
|
|
include(CheckTypeSize)
|
|
|
|
function(run_tests)
|
|
if(${ARGC} GREATER 1)
|
|
set(${ARGN})
|
|
endif()
|
|
|
|
check_function_exists(required_flag_function CHECK_FUNCTION_EXISTS_RESULT)
|
|
check_include_file(CheckRequiredFlags.h CHECK_INCLUDE_FILE_RESULT)
|
|
check_include_file_cxx(CheckRequiredFlags.h CHECK_INCLUDE_FILE_CXX_RESULT)
|
|
check_include_files("stddef.h;CheckRequiredFlags.h" CHECK_INCLUDE_FILES_RESULT)
|
|
check_library_exists("" required_flag_library "" CHECK_LIBRARY_EXISTS_RESULT)
|
|
check_prototype_definition(
|
|
required_flag_prototype
|
|
"int required_flag_prototype(int value)"
|
|
"value"
|
|
"CheckRequiredFlags.h"
|
|
CHECK_PROTOTYPE_DEFINITION_RESULT
|
|
)
|
|
check_type_size(required_flag_type CHECK_TYPE_SIZE_RESULT)
|
|
|
|
foreach(result IN ITEMS
|
|
CHECK_FUNCTION_EXISTS_RESULT
|
|
CHECK_INCLUDE_FILE_RESULT
|
|
CHECK_INCLUDE_FILE_CXX_RESULT
|
|
CHECK_INCLUDE_FILES_RESULT
|
|
CHECK_LIBRARY_EXISTS_RESULT
|
|
CHECK_PROTOTYPE_DEFINITION_RESULT
|
|
CHECK_TYPE_SIZE_RESULT
|
|
)
|
|
if(NOT ${result})
|
|
message(SEND_ERROR "${result} did not honor CMAKE_REQUIRED_FLAGS")
|
|
endif()
|
|
unset(CACHE{${result}})
|
|
endforeach()
|
|
unset(CACHE{HAVE_CHECK_TYPE_SIZE_RESULT})
|
|
endfunction()
|
|
|
|
run_tests()
|
|
run_tests(CMAKE_REQUIRED_LINK_OPTIONS REQUIRED-NOTFOUND)
|
|
run_tests(CMAKE_REQUIRED_LIBRARIES REQUIRED-NOTFOUND)
|