Skip to content

Commit

Permalink
cmake: Delete check_cxx_source_links* macros
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Feb 20, 2025
1 parent 71bf829 commit 8d238c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
9 changes: 0 additions & 9 deletions cmake/module/CheckSourceCompilesAndLinks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
28 changes: 16 additions & 12 deletions cmake/module/TestAppendRequiredLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

0 comments on commit 8d238c1

Please sign in to comment.