From 8d238c1dfde28bbd38bfba84136900724c0d7d95 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Thu, 20 Feb 2025 12:39:12 +0000 Subject: [PATCH] cmake: Delete `check_cxx_source_links*` macros --- .../module/CheckSourceCompilesAndLinks.cmake | 9 ------ .../module/TestAppendRequiredLibraries.cmake | 28 +++++++++++-------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/cmake/module/CheckSourceCompilesAndLinks.cmake b/cmake/module/CheckSourceCompilesAndLinks.cmake index 7967f38eded38..02bd7265bf788 100644 --- a/cmake/module/CheckSourceCompilesAndLinks.cmake +++ b/cmake/module/CheckSourceCompilesAndLinks.cmake @@ -3,8 +3,6 @@ # file COPYING or https://opensource.org/license/mit/. include_guard(GLOBAL) -include(CheckCXXSourceCompiles) -include(CMakePushCheckState) #[=[ Check once if C++ source code can be compiled. @@ -34,10 +32,3 @@ function(check_cxx_source_compiles_with_flags source result_var) check_cxx_source_compiles("${source}" ${result_var}) set(${result_var} ${${result_var}} PARENT_SCOPE) endfunction() - -macro(check_cxx_source_links_with_libs libs source) - cmake_push_check_state(RESET) - set(CMAKE_REQUIRED_LIBRARIES "${libs}") - check_cxx_source_compiles("${source}" ${ARGN}) - cmake_pop_check_state() -endmacro() diff --git a/cmake/module/TestAppendRequiredLibraries.cmake b/cmake/module/TestAppendRequiredLibraries.cmake index c1030a641fe38..cb403f1e16d77 100644 --- a/cmake/module/TestAppendRequiredLibraries.cmake +++ b/cmake/module/TestAppendRequiredLibraries.cmake @@ -25,10 +25,13 @@ function(test_append_socket_library target) } ") - include(CheckSourceCompilesAndLinks) + include(CheckCXXSourceCompiles) check_cxx_source_compiles("${check_socket_source}" IFADDR_LINKS_WITHOUT_LIBSOCKET) if(NOT IFADDR_LINKS_WITHOUT_LIBSOCKET) - check_cxx_source_links_with_libs(socket "${check_socket_source}" IFADDR_NEEDS_LINK_TO_LIBSOCKET) + include(CheckSourceCompilesAndLinks) + check_cxx_source_compiles_with_flags("${check_socket_source}" IFADDR_NEEDS_LINK_TO_LIBSOCKET + LINK_LIBRARIES socket + ) if(IFADDR_NEEDS_LINK_TO_LIBSOCKET) target_link_libraries(${target} INTERFACE socket) else() @@ -77,16 +80,17 @@ function(test_append_atomic_library target) } ") - include(CheckSourceCompilesAndLinks) + include(CheckCXXSourceCompiles) check_cxx_source_compiles("${check_atomic_source}" STD_ATOMIC_LINKS_WITHOUT_LIBATOMIC) - if(STD_ATOMIC_LINKS_WITHOUT_LIBATOMIC) - return() - endif() - - check_cxx_source_links_with_libs(atomic "${check_atomic_source}" STD_ATOMIC_NEEDS_LINK_TO_LIBATOMIC) - if(STD_ATOMIC_NEEDS_LINK_TO_LIBATOMIC) - target_link_libraries(${target} INTERFACE atomic) - else() - message(FATAL_ERROR "Cannot figure out how to use std::atomic.") + if(NOT STD_ATOMIC_LINKS_WITHOUT_LIBATOMIC) + include(CheckSourceCompilesAndLinks) + check_cxx_source_compiles_with_flags("${check_atomic_source}" STD_ATOMIC_NEEDS_LINK_TO_LIBATOMIC + LINK_LIBRARIES atomic + ) + if(STD_ATOMIC_NEEDS_LINK_TO_LIBATOMIC) + target_link_libraries(${target} INTERFACE atomic) + else() + message(FATAL_ERROR "Cannot figure out how to use std::atomic.") + endif() endif() endfunction()