|
| 1 | +# Copyright 2026 LiveKit |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# Resolves target aliases, marks their exported include directories as system includes, |
| 16 | +# and disables compiler warnings on compilable third-party targets. |
| 17 | +function(_livekit_resolve_target target out_var) |
| 18 | + if(NOT TARGET ${target}) |
| 19 | + set(${out_var} "" PARENT_SCOPE) |
| 20 | + return() |
| 21 | + endif() |
| 22 | + |
| 23 | + get_target_property(_aliased_target ${target} ALIASED_TARGET) |
| 24 | + if(_aliased_target) |
| 25 | + set(${out_var} "${_aliased_target}" PARENT_SCOPE) |
| 26 | + else() |
| 27 | + set(${out_var} "${target}" PARENT_SCOPE) |
| 28 | + endif() |
| 29 | +endfunction() |
| 30 | + |
| 31 | +function(livekit_disable_warnings target) |
| 32 | + _livekit_resolve_target(${target} _resolved_target) |
| 33 | + if(NOT _resolved_target) |
| 34 | + return() |
| 35 | + endif() |
| 36 | + |
| 37 | + get_target_property(_target_type ${_resolved_target} TYPE) |
| 38 | + get_target_property(_is_imported ${_resolved_target} IMPORTED) |
| 39 | + if(_is_imported OR _target_type STREQUAL "INTERFACE_LIBRARY") |
| 40 | + return() |
| 41 | + endif() |
| 42 | + if(NOT _target_type MATCHES "^(STATIC_LIBRARY|SHARED_LIBRARY|MODULE_LIBRARY|OBJECT_LIBRARY|EXECUTABLE)$") |
| 43 | + return() |
| 44 | + endif() |
| 45 | + |
| 46 | + target_compile_options(${_resolved_target} PRIVATE |
| 47 | + $<$<COMPILE_LANG_AND_ID:C,MSVC>:/W0> |
| 48 | + $<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/W0> |
| 49 | + $<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang,GNU>:-w> |
| 50 | + $<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang,GNU>:-w> |
| 51 | + ) |
| 52 | +endfunction() |
| 53 | + |
| 54 | +function(livekit_mark_system_includes target) |
| 55 | + _livekit_resolve_target(${target} _resolved_target) |
| 56 | + if(NOT _resolved_target) |
| 57 | + return() |
| 58 | + endif() |
| 59 | + |
| 60 | + get_target_property(_interface_includes ${_resolved_target} INTERFACE_INCLUDE_DIRECTORIES) |
| 61 | + if(_interface_includes) |
| 62 | + set_property(TARGET ${_resolved_target} APPEND PROPERTY |
| 63 | + INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${_interface_includes} |
| 64 | + ) |
| 65 | + endif() |
| 66 | +endfunction() |
| 67 | + |
| 68 | +function(livekit_collect_targets_in_directory out_var directory) |
| 69 | + get_property(_targets DIRECTORY "${directory}" PROPERTY BUILDSYSTEM_TARGETS) |
| 70 | + get_property(_subdirectories DIRECTORY "${directory}" PROPERTY SUBDIRECTORIES) |
| 71 | + |
| 72 | + set(_all_targets ${_targets}) |
| 73 | + foreach(_subdirectory IN LISTS _subdirectories) |
| 74 | + livekit_collect_targets_in_directory(_subdirectory_targets "${_subdirectory}") |
| 75 | + list(APPEND _all_targets ${_subdirectory_targets}) |
| 76 | + endforeach() |
| 77 | + |
| 78 | + set(${out_var} ${_all_targets} PARENT_SCOPE) |
| 79 | +endfunction() |
| 80 | + |
| 81 | +function(livekit_treat_as_external target) |
| 82 | + if(NOT TARGET ${target}) |
| 83 | + return() |
| 84 | + endif() |
| 85 | + |
| 86 | + livekit_mark_system_includes(${target}) |
| 87 | + livekit_disable_warnings(${target}) |
| 88 | +endfunction() |
0 commit comments