v31.1-roots.1 · Commit 16: [PATCH 16/17] fix(build): classify Homebrew libevent headers as system
cmake/module/FindLibevent.cmake
Before: cmake/module/FindLibevent.cmake · After: cmake/module/FindLibevent.cmake
File metadata
index c006b43d6040865db81e849a1ebb29bfad8091fa..c6f5d35a4f20ac7506d9ed907379b7b010b6e7f0 100644
Download original patch · Release notes
Diff rows 1–63 of 63. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
cmake/module/FindLibevent.cmake
CHANGED
|
@@ -14,6 +14,47 @@ This is a wrapper around find_package()/pkg_check_modules() commands that:
|
|
| 14 |
|
| 15 |
#]=======================================================================]
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Check whether evhttp_connection_get_peer expects const char**.
|
| 18 |
# See https://github.com/libevent/libevent/commit/a18301a2bb160ff7c3ffaf5b7653c39ffe27b385
|
| 19 |
function(check_evhttp_connection_get_peer target)
|
|
@@ -59,6 +100,9 @@ if(Libevent_FOUND)
|
|
| 59 |
REQUIRED_VARS Libevent_DIR
|
| 60 |
VERSION_VAR Libevent_VERSION
|
| 61 |
)
|
|
|
|
|
|
|
|
|
|
| 62 |
check_evhttp_connection_get_peer(libevent::extra)
|
| 63 |
else()
|
| 64 |
find_package(PkgConfig REQUIRED)
|
|
@@ -71,6 +115,7 @@ else()
|
|
| 71 |
if(TARGET PkgConfig::libevent_${component} AND NOT TARGET libevent::${component})
|
| 72 |
add_library(libevent::${component} ALIAS PkgConfig::libevent_${component})
|
| 73 |
endif()
|
|
|
|
| 74 |
endforeach()
|
| 75 |
find_package_handle_standard_args(Libevent
|
| 76 |
REQUIRED_VARS libevent_core_LIBRARY_DIRS
|
|
|
|
| 14 |
|
| 15 |
#]=======================================================================]
|
| 16 |
|
| 17 |
+
function(add_homebrew_libevent_header_alias target)
|
| 18 |
+
if(NOT CMAKE_HOST_APPLE)
|
| 19 |
+
return()
|
| 20 |
+
endif()
|
| 21 |
+
find_program(HOMEBREW_EXECUTABLE brew)
|
| 22 |
+
if(NOT HOMEBREW_EXECUTABLE)
|
| 23 |
+
return()
|
| 24 |
+
endif()
|
| 25 |
+
execute_process(
|
| 26 |
+
COMMAND ${HOMEBREW_EXECUTABLE} --prefix
|
| 27 |
+
OUTPUT_VARIABLE _homebrew_prefix
|
| 28 |
+
RESULT_VARIABLE _homebrew_status
|
| 29 |
+
ERROR_QUIET
|
| 30 |
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
| 31 |
+
)
|
| 32 |
+
if(NOT _homebrew_status EQUAL 0 OR NOT IS_DIRECTORY "${_homebrew_prefix}/include/event2")
|
| 33 |
+
return()
|
| 34 |
+
endif()
|
| 35 |
+
get_target_property(_libevent_target ${target} ALIASED_TARGET)
|
| 36 |
+
if(NOT _libevent_target)
|
| 37 |
+
set(_libevent_target ${target})
|
| 38 |
+
endif()
|
| 39 |
+
file(REAL_PATH "${_homebrew_prefix}/include/event2" _linked_libevent_headers)
|
| 40 |
+
get_target_property(_libevent_include_dirs ${_libevent_target} INTERFACE_INCLUDE_DIRECTORIES)
|
| 41 |
+
foreach(_libevent_include_dir IN LISTS _libevent_include_dirs)
|
| 42 |
+
if(IS_DIRECTORY "${_libevent_include_dir}/event2")
|
| 43 |
+
file(REAL_PATH "${_libevent_include_dir}/event2" _configured_libevent_headers)
|
| 44 |
+
if(_linked_libevent_headers STREQUAL _configured_libevent_headers)
|
| 45 |
+
# The compiler can select the linked spelling before the Cellar path.
|
| 46 |
+
# Retain its system flag even when CMake filters implicit include paths.
|
| 47 |
+
target_include_directories(${_libevent_target} SYSTEM INTERFACE "${_homebrew_prefix}/include")
|
| 48 |
+
target_compile_options(${_libevent_target} INTERFACE
|
| 49 |
+
"$<$<COMPILE_LANGUAGE:CXX>:SHELL:-isystem \"${_homebrew_prefix}/include\">"
|
| 50 |
+
)
|
| 51 |
+
message(STATUS "Using matching Homebrew Libevent header alias for ${target}: ${_homebrew_prefix}/include")
|
| 52 |
+
break()
|
| 53 |
+
endif()
|
| 54 |
+
endif()
|
| 55 |
+
endforeach()
|
| 56 |
+
endfunction()
|
| 57 |
+
|
| 58 |
# Check whether evhttp_connection_get_peer expects const char**.
|
| 59 |
# See https://github.com/libevent/libevent/commit/a18301a2bb160ff7c3ffaf5b7653c39ffe27b385
|
| 60 |
function(check_evhttp_connection_get_peer target)
|
|
|
|
| 100 |
REQUIRED_VARS Libevent_DIR
|
| 101 |
VERSION_VAR Libevent_VERSION
|
| 102 |
)
|
| 103 |
+
foreach(component IN LISTS _libevent_components)
|
| 104 |
+
add_homebrew_libevent_header_alias(libevent::${component})
|
| 105 |
+
endforeach()
|
| 106 |
check_evhttp_connection_get_peer(libevent::extra)
|
| 107 |
else()
|
| 108 |
find_package(PkgConfig REQUIRED)
|
|
|
|
| 115 |
if(TARGET PkgConfig::libevent_${component} AND NOT TARGET libevent::${component})
|
| 116 |
add_library(libevent::${component} ALIAS PkgConfig::libevent_${component})
|
| 117 |
endif()
|
| 118 |
+
add_homebrew_libevent_header_alias(libevent::${component})
|
| 119 |
endforeach()
|
| 120 |
find_package_handle_standard_args(Libevent
|
| 121 |
REQUIRED_VARS libevent_core_LIBRARY_DIRS
|