cmake: use cmake_push_check_state() around feature checks

Enclose
`CMAKE_EXTRA_INCLUDE_FILES`,
`CMAKE_REQUIRED_DEFINITIONS`,
`CMAKE_REQUIRED_FLAGS`,
`CMAKE_REQUIRED_INCLUDES`,
`CMAKE_REQUIRED_LIBRARIES`,
`CMAKE_REQUIRED_LINK_OPTIONS`,
settings within `cmake_push_check_state()`/`cmake_pop_check_state()`
calls. It prevents spilling them into other feature checks. It also
replaces manual resets found in some places (which can have
the undesired side-effect of destroying values meant for global use.)

Cherry-picked from #15157
Closes #15251
This commit is contained in:
Viktor Szakats 2024-10-05 01:12:44 +02:00
parent ae5e538e57
commit 91519bfb74
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
4 changed files with 21 additions and 19 deletions

View file

@ -249,7 +249,9 @@ if(BUILD_SHARED_LIBS)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/libcurl.vers.in"
"${CMAKE_CURRENT_BINARY_DIR}/libcurl.vers" @ONLY)
include(CMakePushCheckState)
include(CheckCSourceCompiles)
cmake_push_check_state()
set(CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/libcurl.vers")
check_c_source_compiles("int main(void) { return 0; }" HAVE_VERSIONED_SYMBOLS)
if(HAVE_VERSIONED_SYMBOLS)
@ -258,7 +260,7 @@ if(BUILD_SHARED_LIBS)
else()
message(WARNING "Versioned symbols requested, but not supported by the toolchain.")
endif()
unset(CMAKE_REQUIRED_LINK_OPTIONS)
cmake_pop_check_state()
endif()
endif()